function dispatch($uri) { $this->request->setUri($uri); $event = new \Zend\Mvc\MvcEvent(); $event->setRouter($this->router); $event->setRequest($this->request); $this->events->trigger('route', $event); $this->routeMatch = $event->getRouteMatch(); }
public function getServiceConfig() { return array('factories' => array('MaglLegacyApplicationOptions' => function ($sl) { $config = $sl->get('Config'); $options = $config['magl_legacy_application']; return new Options\LegacyControllerOptions($options); }, 'MaglControllerService' => function (ServiceManager $sl) { $eventManager = $sl->get('Application')->getEventManager(); $event = new \Zend\Mvc\MvcEvent(); $event->setApplication($sl->get('Application')); $event->setTarget($sl->get('Application')); $event->setRequest($sl->get('Request')); $event->setRouter($sl->get('Router')); $event->setRouteMatch(new RouteMatch(array())); return new Service\ControllerService($eventManager, $event); })); }
/** * 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()); } }
/** * 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()); } }