예제 #1
0
 public function testConstructor()
 {
     $name = 'Foo';
     $context = 'Bar';
     $params = ['baz' => 'bat'];
     $event = new SystemEvent($name, $context, $params);
     $this->assertSame($name, $event->getName());
     $this->assertSame($context, $event->getContext());
     $this->assertSame($params, $event->getParams());
 }
 /**
  * Triggers the DispatchEvent.
  *
  * @param \Es\System\SystemEvent $event The system event
  *
  * @throws \RuntimeException If the ServerRequest not contain the
  *                           "controller" attribute
  */
 public function onDispatch(SystemEvent $event)
 {
     $server = $this->getServer();
     $request = $server->getRequest();
     $controllerName = $request->getAttribute('controller');
     if (!$controllerName) {
         throw new RuntimeException('Unable to dispatch the system event, the server request not ' . 'contains the "controller" attribute.');
     }
     $actionName = $request->getAttribute('action', 'index');
     $events = $this->getEvents();
     $controllers = $this->getControllers();
     $controller = $controllers->get($controllerName);
     $event->setContext($controller);
     $dispatchEvent = new DispatchEvent($controller, $controllerName, $actionName, $event->getParams());
     $events->trigger($dispatchEvent);
     $result = $dispatchEvent->getResult();
     $target = SystemEvent::DISPATCH;
     if ($result instanceof ResponseInterface) {
         $target = SystemEvent::FINISH;
     }
     $event->setResult($target, $result);
 }