Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public function register(View $view)
 {
     $view->on('render', function ($event) {
         $name = $event->getTemplate();
         if (isset($this->placeholder[$name])) {
             $this->deferred[$name] = clone $event;
             $event->setResult($this->placeholder[$name]);
             $event->stopPropagation();
         }
     }, 15);
     $this->events->on('response', function ($e, $request, $response) use($view) {
         foreach ($this->deferred as $name => $event) {
             $view->trigger($event->setName($name), [$view]);
             $response->setContent(str_replace($this->placeholder[$name], $event->getResult(), $response->getContent()));
         }
     }, 10);
 }
 /**
  * Subscribes model lifecycle callbacks.
  *
  * @param Metadata $metadata
  */
 protected function subscribe(Metadata $metadata)
 {
     foreach ($metadata->getEvents() as $event => $methods) {
         foreach ($methods as $method) {
             $this->events->on($metadata->getEventPrefix() . '.' . $event, [$metadata->getClass(), $method]);
         }
     }
 }
 /**
  * Constructor.
  *
  * @param Router                   $router
  * @param EventDispatcherInterface $events
  * @param string                   $cache
  * @param string                   $file
  */
 public function __construct(Router $router, EventDispatcherInterface $events, $cache, $file = '%s.cache')
 {
     $this->router = $router;
     $this->cache = $cache;
     $this->file = $file;
     $events->on('request', function ($event, $request) {
         $this->route = $request->attributes->get('_route');
     });
 }
Exemple #4
0
 /**
  * Adds an event listener.
  *
  * @param  string   $event
  * @param  callable $listener
  * @param  int      $priority
  */
 public function on($event, $listener, $priority = 0)
 {
     $this->events->on($event, $listener, $priority);
 }
 /**
  * Sets a callback to act after a route is executed.
  *
  * @param string   $name
  * @param callable $callback
  * @param int      $priority
  */
 public function after($name, $callback, $priority)
 {
     $this->events->on('after' . $name, $callback, $priority);
 }