Esempio n. 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());
 }
 /**
  * Injects the template name to a view model.
  *
  * @param \Es\System\SystemEvent $event The system event
  *
  * @throws \RuntimeException         If the module namespace is not specified
  * @throws \UnexpectedValueException If the context of system event is
  *                                   not object
  */
 public function __invoke(SystemEvent $event)
 {
     $result = $event->getResult(SystemEvent::DISPATCH);
     if ($result instanceof ViewModelInterface && !$result->getTemplate()) {
         $module = $result->getModule();
         if (!$module) {
             throw new RuntimeException('Unable to resolve template for View Model. ' . 'The module namespace is not specified.');
         }
         $context = $event->getContext();
         if (!is_object($context)) {
             throw new UnexpectedValueException(sprintf('Invalid context of system event; must be an object, ' . '"%s" received.', gettype($context)));
         }
         $template = $this->resolveTemplate($context, $module);
         $result->setTemplate($template);
     }
 }
 /**
  * Injects the module namespace of the dispatched controller to a view model
  * and to layout.
  *
  * @param \Es\System\SystemEvent $event The system event
  *
  * @throws \UnexpectedValueException If the context of system event is
  *                                   not object
  */
 public function __invoke(SystemEvent $event)
 {
     $context = $event->getContext();
     if (!is_object($context)) {
         throw new UnexpectedValueException(sprintf('Invalid context of system event; must be an object, ' . '"%s" received.', gettype($context)));
     }
     $module = $this->resolveModule($context);
     $view = $this->getView();
     $layout = $view->getLayout();
     if (!$layout->getModule()) {
         $layout->setModule($module);
     }
     $result = $event->getResult(SystemEvent::DISPATCH);
     if ($result instanceof ViewModelInterface && !$result->getModule()) {
         $result->setModule($module);
     }
 }