src/Loader.php
public function loadController($controller, $namespace = null)
    {
        try {
            $subController = null;
            if (strstr($controller, ',') !== false) {
                $url = explode(',', $controller);
                $urlCount = count($url) - 1;
                $subController = '';

                for ($i = 0; $i < $urlCount; $i++) {
                    if (!defined('CODING_STYLE') or (defined('CODING_STYLE') and CODING_STYLE === true)) {
                        $subController .= ucfirst($url[$i]) . DIRECTORY_SEPARATOR;
                    } else {
                        $subController .= $url[$i] . DIRECTORY_SEPARATOR;
                    }
                }

                $controller = $url[$urlCount];
            }

            if (!defined('CODING_STYLE') or (defined('CODING_STYLE') and CODING_STYLE === true)) {
                $controller = ucfirst($controller);
            }

            $controller = str_replace(DIRECTORY_SEPARATOR, $this->namespaceSeparator, $controller);

            if (!empty($namespace) && $namespace == '\\') {
                $load = $controller;
            } elseif (!empty($namespace)) {
                $class = '\\' . $namespace . '\\Controller\\' . $subController . $controller;
                $load = str_replace('/', $this->namespaceSeparator, $class);
            } else {
                $load = $this->namespaceSeparator . 'Controller' . $this->namespaceSeparator . $subController . $controller . 'Controller';
                $load = str_replace(DIRECTORY_SEPARATOR, $this->namespaceSeparator, $load);
            }

            if (isset($this->debug)) {
                $this->debug->addHeader(['X-DF-Debug-Controller' => $load]);
            }

            $controller = new $load($this->baseClass);
        } catch (\Exception $e) {
            if (ini_get('display_errors') === 'on') {
                $msg = null;
                $msg .= '<pre>';
                $msg .= 'Message: <b>' . $e->getMessage() . '</b><br><br>';

                $msg .= 'Accept: ' . $_SERVER['HTTP_ACCEPT'] . '<br>';
                if (isset($_SERVER['HTTP_REFERER'])) {
                    $msg .= 'Referer: ' . $_SERVER['HTTP_REFERER'] . '<br><br>';
                }

                $msg .= 'Request Method: ' . $_SERVER['REQUEST_METHOD'] . '<br><br>';
                $msg .= 'Current file Path: <b>' . $this->router->currentPath() . '</b><br>';
                $msg .= 'File Exception: ' . $e->getFile() . ':' . $e->getLine() . '<br><br>';
                $msg .= 'Trace: <br>' . $e->getTraceAsString() . '<br>';
                $msg .= '</pre>';

                return Response::create($msg)->display();
            }

            $routes = Config::load('router')->get('routes');
            if (!empty($routes['error/:code'])) {
                return Response::redirect('error/:code?code=400', 400)->display();
            }

            return Response::create()->status(500)->display();
        }

        return $controller;
    }
public function loadController($controller, $namespace = null)
    {
        try {
            $subController = null;
            if (strstr($controller, ',') !== false) {
                $url = explode(',', $controller);
                $urlCount = count($url) - 1;
                $subController = '';

                for ($i = 0; $i < $urlCount; $i++) {
                    if (!defined('CODING_STYLE') or (defined('CODING_STYLE') and CODING_STYLE === true)) {
                        $subController .= ucfirst($url[$i]) . DIRECTORY_SEPARATOR;
                    } else {
                        $subController .= $url[$i] . DIRECTORY_SEPARATOR;
                    }
                }

                $controller = $url[$urlCount];
            }

            if (!defined('CODING_STYLE') or (defined('CODING_STYLE') and CODING_STYLE === true)) {
                $controller = ucfirst($controller);
            }

            $controller = str_replace(DIRECTORY_SEPARATOR, $this->namespaceSeparator, $controller);

            if (!empty($namespace) && $namespace == '\\') {
                $load = $controller;
            } elseif (!empty($namespace)) {
                $class = '\\' . $namespace . '\\Controller\\' . $subController . $controller;
                $load = str_replace('/', $this->namespaceSeparator, $class);
            } else {
                $load = $this->namespaceSeparator . 'Controller' . $this->namespaceSeparator . $subController . $controller . 'Controller';
                $load = str_replace(DIRECTORY_SEPARATOR, $this->namespaceSeparator, $load);
            }

            if (isset($this->debug)) {
                $this->debug->addHeader(['X-DF-Debug-Controller' => $load]);
            }

            $controller = new $load($this->baseClass);
        } catch (\Exception $e) {
            if (ini_get('display_errors') === 'on') {
                $msg = null;
                $msg .= '<pre>';
                $msg .= 'Message: <b>' . $e->getMessage() . '</b><br><br>';

                $msg .= 'Accept: ' . $_SERVER['HTTP_ACCEPT'] . '<br>';
                if (isset($_SERVER['HTTP_REFERER'])) {
                    $msg .= 'Referer: ' . $_SERVER['HTTP_REFERER'] . '<br><br>';
                }

                $msg .= 'Request Method: ' . $_SERVER['REQUEST_METHOD'] . '<br><br>';
                $msg .= 'Current file Path: <b>' . $this->router->currentPath() . '</b><br>';
                $msg .= 'File Exception: ' . $e->getFile() . ':' . $e->getLine() . '<br><br>';
                $msg .= 'Trace: <br>' . $e->getTraceAsString() . '<br>';
                $msg .= '</pre>';

                return Response::create($msg)->display();
            }

            $routes = Config::load('router')->get('routes');
            if (!empty($routes['error/:code'])) {
                return Response::redirect('error/:code?code=400', 400)->display();
            }

            return Response::create()->status(500)->display();
        }

        return $controller;
    }
Establish the requested controller as an object.

@param string      $controller
@param null|string $namespace

@return mixed