Exemple #1
0
 /**
  * {@inheritDoc}
  */
 public function publishEvent(EventInterface $event)
 {
     // Check if event exists after invoking the PublishEventCommand because
     // the PublishEventCommand tells that a event is dispatched but does not care
     // if it succeeded. Later the EventPublishedEvent can be used to check if a
     // event succeeded.
     if (!is_null($this->gate->getSystemBus())) {
         $publishEventCommand = new PublishEventCommand();
         $publishEventCommand->setMessageClass(get_class($event));
         $publishEventCommand->setMessageVars($event->getMessageVars());
         $publishEventCommand->setBusName($this->getName());
         $this->gate->getSystemBus()->invokeCommand($publishEventCommand);
     }
     try {
         $response = $this->bus->publishEvent($event);
         if ($response === false) {
             return false;
         }
     } catch (BusException $ex) {
         //throw it again
         throw $ex;
     } catch (\Exception $ex) {
         throw BusException::defaultBusError($ex->getMessage(), null, $ex);
     }
     // Dispatch the EventPublishedEvent here! If for example a event could not be dispatched
     // because it does not exist in the eventListenerMap[<empty>] this Event would never
     // be dispatched!
     if (!is_null($this->gate->getSystemBus())) {
         $eventPublishedEvent = new EventPublishedEvent();
         $eventPublishedEvent->setMessageClass(get_class($event));
         $eventPublishedEvent->setMessageVars($event->getMessageVars());
         $eventPublishedEvent->setBusName($this->getName());
         $this->gate->getSystemBus()->publishEvent($eventPublishedEvent);
     }
     return $response;
 }