Browse Source

Don't create ControllerFactory instance until needed.

ADmad 6 years ago
parent
commit
dc5fb811a1
1 changed files with 6 additions and 2 deletions
  1. 6 2
      src/Http/BaseApplication.php

+ 6 - 2
src/Http/BaseApplication.php

@@ -66,7 +66,7 @@ abstract class BaseApplication implements
     /**
      * Controller factory
      *
-     * @var \Cake\Http\ControllerFactoryInterface
+     * @var \Cake\Http\ControllerFactoryInterface|null
      */
     protected $controllerFactory;
 
@@ -85,7 +85,7 @@ abstract class BaseApplication implements
         $this->configDir = $configDir;
         $this->plugins = Plugin::getCollection();
         $this->_eventManager = $eventManager ?: EventManager::instance();
-        $this->controllerFactory = $controllerFactory ?: new ControllerFactory();
+        $this->controllerFactory = $controllerFactory;
     }
 
     /**
@@ -216,6 +216,10 @@ abstract class BaseApplication implements
     public function handle(
         ServerRequestInterface $request
     ): ResponseInterface {
+        if ($this->controllerFactory === null) {
+            $this->controllerFactory = new ControllerFactory();
+        }
+
         if (Router::getRequest() !== $request) {
             Router::setRequest($request);
         }