/**
  * 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());
     }
 }
Exemple #2
0
 public function getRequestByHash($hash)
 {
     $node = $this->getNodeByHash($hash);
     if (empty($node) || $node->level < 3) {
         return false;
     }
     $params = array();
     if ($node->level == 3) {
         $action = $node;
     } elseif ($node->level == 4) {
         $action = $this->getParentByHash($hash);
         $params = $node->params;
     }
     $controller = $this->getParentByHash($action->hash);
     $module = $this->getParentByHash($controller->hash);
     $request = new \Zend\Mvc\Router\RouteMatch(array('module' => $module->name, 'controller' => $controller->name, 'action' => $action->name));
     $request->setMatchedRouteName($action->hash);
     return $request;
 }