Skip to content

Commit

Permalink
fix - ControllerManager injects ZF core services into created control…
Browse files Browse the repository at this point in the history
…lers
  • Loading branch information
mfris committed Feb 9, 2016
1 parent 2b64b0f commit 25a35d0
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/DI/ZendFramework2/Service/ControllerManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
}
}
}

0 comments on commit 25a35d0

Please sign in to comment.