/**
  * Inject required dependencies into the controller.
  *
  * @param  DispatchableInterface $controller
  * @param  ServiceLocatorInterface $serviceLocator
  * @return void
  */
 public function injectControllerDependencies($controller, ServiceLocatorInterface $serviceLocator)
 {
     if (!$controller instanceof DispatchableInterface) {
         return;
     }
     $parentLocator = $serviceLocator->getServiceLocator();
     if ($controller instanceof ServiceLocatorAwareInterface) {
         $controller->setServiceLocator($parentLocator->get('Zend\\ServiceManager\\ServiceLocatorInterface'));
     }
     if ($controller instanceof EventManagerAwareInterface) {
         // If we have an event manager composed already, make sure it gets
         // injected with the shared event manager.
         // The AbstractController lazy-instantiates an EM instance, which
         // is why the shared EM injection needs to happen; the conditional
         // will always pass.
         $events = $controller->getEventManager();
         if (!$events instanceof EventManagerInterface) {
             $controller->setEventManager($parentLocator->get('EventManager'));
         } else {
             $events->setSharedManager($parentLocator->get('SharedEventManager'));
         }
     }
     if (method_exists($controller, 'setPluginManager')) {
         $controller->setPluginManager($parentLocator->get('ControllerPluginManager'));
     }
 }
Beispiel #2
0
 /**
  * Inject required dependencies into the controller.
  *
  * @param  DispatchableInterface $controller
  * @param  ServiceLocatorInterface $serviceLocator
  * @return void
  */
 public function injectControllerDependencies($controller, ServiceLocatorInterface $serviceLocator)
 {
     if (!$controller instanceof DispatchableInterface) {
         return;
     }
     $parentLocator = $serviceLocator->getServiceLocator();
     if ($controller instanceof ServiceLocatorAwareInterface) {
         $controller->setServiceLocator($parentLocator->get('Zend\\ServiceManager\\ServiceLocatorInterface'));
     }
     if ($controller instanceof EventManagerAwareInterface) {
         $controller->setEventManager($parentLocator->get('EventManager'));
     }
     if (method_exists($controller, 'setPluginManager')) {
         $controller->setPluginManager($parentLocator->get('ControllerPluginBroker'));
     }
 }
Beispiel #3
0
 /**
  * Get an initialized instance of the controller plugin
  *
  * If controller setup is requested, the controller will be a
  * \Zend\Mvc\Controller\AbstractActionController mock. Its MvcEvent will be
  * initialized with a standard route 'test' (/module/controller/action/)
  * with defaults of "defaultcontroller" and "defaultaction".
  * The RouteMatch is initialized with "currentcontroller" and
  * "currentaction". An empty response is created.
  *
  * @param bool $setController Initialize the helper with a working controller (default: TRUE)
  * @return \Zend\Mvc\Controller\Plugin\PluginInterface Plugin instance
  */
 protected function _getPlugin($setController = true)
 {
     if ($setController) {
         $router = new \Zend\Router\Http\TreeRouteStack();
         $router->addRoute('test', \Zend\Router\Http\Segment::factory(array('route' => '/[module[/]][:controller[/][:action[/]]]', 'defaults' => array('controller' => 'defaultcontroller', 'action' => 'defaultaction'))));
         $routeMatch = new \Zend\Router\RouteMatch(array('controller' => 'currentcontroller', 'action' => 'currentaction'));
         $routeMatch->setMatchedRouteName('test');
         $event = new \Zend\Mvc\MvcEvent();
         $event->setRouter($router);
         $event->setRouteMatch($routeMatch);
         $event->setResponse(new \Zend\Http\Response());
         $this->_controller = $this->getMockBuilder('Zend\\Mvc\\Controller\\AbstractActionController')->setMethods(null)->getMockForAbstractClass();
         $this->_controller->setPluginManager($this->_getPluginManager());
         $this->_controller->setEvent($event);
         return $this->_controller->plugin($this->_getPluginName());
     } else {
         return $this->_getPluginManager()->get($this->_getPluginName());
     }
 }
 /**
  * Get an initialized instance of the controller plugin
  *
  * If controller setup is requested, the controller will be a
  * \Library\Test\Mvc\Controller\TestController. Its MvcEvent will be
  * initialized with a standard route 'test' (/module/controller/action/)
  * with defaults of "defaultcontroller" and "defaultaction".
  * The RouteMatch is initialized with "currentcontroller" and
  * "currentaction". An empty response is created.
  *
  * @param bool $setController Initialize the helper with a working controller (default: TRUE)
  * @return \Zend\Mvc\Controller\Plugin\PluginInterface Plugin instance
  */
 protected function _getPlugin($setController = true)
 {
     if ($setController) {
         $router = new \Zend\Mvc\Router\Http\TreeRouteStack();
         $router->addRoute('test', \Zend\Mvc\Router\Http\Segment::factory(array('route' => '/[module[/]][:controller[/][:action[/]]]', 'defaults' => array('controller' => 'defaultcontroller', 'action' => 'defaultaction'))));
         $routeMatch = new \Zend\Mvc\Router\RouteMatch(array('controller' => 'currentcontroller', 'action' => 'currentaction'));
         $routeMatch->setMatchedRouteName('test');
         $event = new \Zend\Mvc\MvcEvent();
         $event->setRouter($router);
         $event->setRouteMatch($routeMatch);
         $event->setResponse(new \Zend\Http\Response());
         // Register TestController with the service manager because this is
         // not done in the module setup
         $manager = Application::getService('ControllerManager');
         $manager->setInvokableClass('test', 'Library\\Test\\Mvc\\Controller\\TestController');
         $this->_controller = $manager->get('test');
         $this->_controller->setEvent($event);
         return $this->_controller->plugin($this->_getPluginName());
     } else {
         return $this->_getPluginManager()->get($this->_getPluginName());
     }
 }