Zend\Mvc\Controller\Plugin\Forward::dispatch PHP Method

dispatch() public method

Dispatch another controller
public dispatch ( string $name, array $params = null ) : mixed
$name string Controller name; either a class name or an alias used in the controller manager
$params array Parameters with which to seed a custom RouteMatch object for the new controller
return mixed
    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;
    }

Usage Example

コード例 #1
0
 public function testPluginWithoutLocatorAwareControllerRaisesDomainException()
 {
     $controller = new UnlocatableEventfulController();
     $controller->setEvent($this->controller->getEvent());
     $plugin     = new ForwardPlugin();
     $plugin->setController($controller);
     $this->setExpectedException('Zend\Mvc\Exception\DomainException', 'implements ServiceLocatorAwareInterface');
     $plugin->dispatch('forward');
 }
All Usage Examples Of Zend\Mvc\Controller\Plugin\Forward::dispatch