Example #1
0
 /**
  * On dispatch event listener - called on any event
  *
  * @param Event $event
  * @param string $eventName
  * @return void
  */
 public function onException(Event $event)
 {
     if ($event instanceof Amqp\ErrorEvent) {
         $event->getEvent()->addHeader("x-exception", ["message" => $event->getException()->getMessage(), "code" => $event->getException()->getCode(), "class" => get_class($event->getException())]);
         $this->postpone($event->getEvent());
         $event->getEvent()->ack();
         if ($this->stopPropagation) {
             $event->stopPropagation();
         }
     }
 }
 /**
  * On dispatch event listener - called on any event
  *
  * @param Event $event
  * @param string $eventName
  * @return void
  */
 public function onException(Event $event, $eventName)
 {
     if ($event instanceof Amqp\ErrorEvent) {
         $event->getEvent()->addHeader("x-exception", ["message" => $event->getException()->getMessage(), "code" => $event->getException()->getCode(), "class" => get_class($event->getException())]);
         $this->deadLetter($event->getEvent(), $event->getException());
         $event->getEvent()->reject(null);
         if ($this->stopPropagation) {
             $event->stopPropagation();
         }
     }
 }
 public function __invoke(SymfonyEvent $symfonyEvent)
 {
     if ($symfonyEvent instanceof Event) {
         $event = $symfonyEvent;
     } elseif ($symfonyEvent instanceof SymfonyEventWrapper) {
         $event = $symfonyEvent->getWrappedEvent();
     } else {
         $event = new EventWrapper($symfonyEvent);
     }
     if (!$this->subscription->dispatch($event, $this->dispatcher)) {
         $symfonyEvent->stopPropagation();
     }
 }
Example #4
0
 public function testStopPropagationAndIsPropagationStopped()
 {
     $this->event->stopPropagation();
     $this->assertTrue($this->event->isPropagationStopped());
 }
 public function postFoo(Event $e)
 {
     $this->postFooInvoked = true;
     $e->stopPropagation();
 }
 private function forward($controller, Event $event)
 {
     $attributes = ['_controller' => $controller];
     if ($event instanceof CustomActionResourceEvent) {
         $attributes['id'] = $event->getResource()->getId();
     }
     $subRequest = $this->request->duplicate([], null, $attributes);
     $response = $this->kernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
     if ($event instanceof DisplayToolEvent || $event instanceof DisplayWidgetEvent) {
         $event->setContent($response->getContent());
     } else {
         $event->setResponse($response);
     }
     $event->stopPropagation();
 }
 public function test_dispatch_with_stop_propagation()
 {
     myEventDispatch::reset();
     $dispatcher = myEventDispatch::getDispatcher();
     $event = new Event();
     $event->triggeredEvent = [];
     $uniqueId1 = md5(rand() . microtime());
     $dispatcher->addListener('testevent', function (Event $event) {
         $event->triggeredEvent[] = 1;
         $event->stopPropagation();
     }, $uniqueId1);
     $dispatcher->addListener('testevent', function (Event $event) {
         $event->triggeredEvent[] = 2;
     }, $uniqueId1);
     $dispatcher->dispatch('testevent', $event, $uniqueId1);
     $this->assertEquals(array(1), $event->triggeredEvent);
     $event = new Event();
     $event->triggeredEvent = [];
     $dispatcher->dispatch('testevent', $event);
     $this->assertEquals(array(1), $event->triggeredEvent);
 }
Example #8
0
 public function cancel($reason = null)
 {
     $this->event->stopPropagation();
     parent::cancel($reason);
 }
Example #9
0
 /**
  * Stop the propagation of the event to other listeners.
  *
  * @return void
  */
 public function stop()
 {
     return parent::stopPropagation();
 }