protected function _getController()
    {
        $request = $this->request;
        $routerRequest = Router::getRequest(true);
        // Fallback to the request in the router or make a new one from
        // $_SERVER
        if ($request === null) {
            $request = $routerRequest ?: ServerRequestFactory::fromGlobals();
        }

        // If the current request doesn't have routing data, but we
        // found a request in the router context copy the params over
        if ($request->getParam('controller') === false && $routerRequest !== null) {
            $request = $request->withAttribute('params', $routerRequest->getAttribute('params'));
        }

        $response = new Response();
        $controller = null;

        try {
            $namespace = 'Controller';
            $prefix = $request->getParam('prefix');
            if ($prefix) {
                if (strpos($prefix, '/') === false) {
                    $namespace .= '/' . Inflector::camelize($prefix);
                } else {
                    $prefixes = array_map(
                        'Cake\Utility\Inflector::camelize',
                        explode('/', $prefix)
                    );
                    $namespace .= '/' . implode('/', $prefixes);
                }
            }

            $class = App::className('Error', $namespace, 'Controller');
            if (!$class && $namespace !== 'Controller') {
                $class = App::className('Error', 'Controller', 'Controller');
            }

            /* @var \Cake\Controller\Controller $controller */
            $controller = new $class($request, $response);
            $controller->startupProcess();
            $startup = true;
        } catch (Exception $e) {
            $startup = false;
        }

        // Retry RequestHandler, as another aspect of startupProcess()
        // could have failed. Ignore any exceptions out of startup, as
        // there could be userland input data parsers.
        if ($startup === false && !empty($controller) && isset($controller->RequestHandler)) {
            try {
                $event = new Event('Controller.startup', $controller);
                $controller->RequestHandler->startup($event);
            } catch (Exception $e) {
            }
        }
        if (empty($controller)) {
            $controller = new Controller($request, $response);
        }

        return $controller;
    }