Esempio n. 1
0
 /**
  * Dispatch another controller
  *
  * @param  string $name Controller name; either a class name or an alias used in the controller manager
  * @param  null|array $params Parameters with which to seed a custom RouteMatch object for the new controller
  * @return mixed
  * @throws Exception\DomainException if composed controller does not define InjectApplicationEventInterface
  *         or Locator aware; or if the discovered controller is not dispatchable
  */
 public function dispatch($name, array $params = null)
 {
     $event = clone $this->getEvent();
     $controller = $this->controllers->get($name);
     if ($controller instanceof InjectApplicationEventInterface) {
         $controller->setEvent($event);
     }
     // Allow passing parameters to seed the RouteMatch with & copy matched route name
     if ($params !== null) {
         $routeMatch = new RouteMatch($params);
         $routeMatch->setMatchedRouteName($event->getRouteMatch()->getMatchedRouteName());
         $event->setRouteMatch($routeMatch);
     }
     if ($this->numNestedForwards > $this->maxNestedForwards) {
         throw new Exception\DomainException("Circular forwarding detected: greater than {$this->maxNestedForwards} nested forwards");
     }
     $this->numNestedForwards++;
     // Detach listeners that may cause problems during dispatch:
     $sharedEvents = $event->getApplication()->getEventManager()->getSharedManager();
     $listeners = $this->detachProblemListeners($sharedEvents);
     $return = $controller->dispatch($event->getRequest(), $event->getResponse());
     // If we detached any listeners, reattach them now:
     $this->reattachProblemListeners($sharedEvents, $listeners);
     $this->numNestedForwards--;
     return $return;
 }