diff --git a/src/DI/ZendFramework2/Service/ControllerManager.php b/src/DI/ZendFramework2/Service/ControllerManager.php index 10b0826..f74582b 100644 --- a/src/DI/ZendFramework2/Service/ControllerManager.php +++ b/src/DI/ZendFramework2/Service/ControllerManager.php @@ -10,9 +10,11 @@ namespace DI\ZendFramework2\Service; use Interop\Container\ContainerInterface; +use Zend\Mvc\Controller\AbstractController; use Zend\ServiceManager\Exception; use Zend\Mvc\Controller\ControllerManager as ZendControllerManager; use Zend\ServiceManager\ConfigInterface; +use Zend\ServiceManager\InitializerInterface; use Zend\Stdlib\DispatchableInterface; /** @@ -63,6 +65,7 @@ public function get($name, $options = array(), $usePeeringServiceManagers = true if ($this->container->has($name)) { $controller = $this->container->get($name); + $this->initialize($controller); } elseif (parent::has($name, true, $usePeeringServiceManagers)) { $controller = parent::get($name, $options, $usePeeringServiceManagers); } @@ -95,4 +98,20 @@ public function has($name, $checkAbstractFactories = true, $usePeeringServiceMan return false; } + + /** + * injects Zend core services into the given controller + * + * @param AbstractController $controller + */ + private function initialize(AbstractController $controller) + { + foreach ($this->initializers as $initializer) { + if ($initializer instanceof InitializerInterface) { + $initializer->initialize($controller, $this); + } else { + call_user_func($initializer, $controller, $this); + } + } + } }