Exemplo n.º 1
0
 public function testDisableSystemBus()
 {
     if (is_null($this->gate->getSystemBus())) {
         $this->gate->enableSystemBus();
     }
     $this->gate->disableSystemBus();
     $systemBus = $this->gate->getSystemBus();
     $this->assertNull($systemBus);
 }
Exemplo n.º 2
0
 /**
  *
  */
 public function __construct()
 {
     // The gate manages the bus system
     $this->gate = new Gate();
     // Create a bus and attach it to the gate
     $this->bus = new Iteration4Bus();
     $this->bus->setCommandHandlerLoader(new ClassMapCommandHandlerLoader());
     $this->bus->setEventListenerLoader(new ClassMapEventListenerLoader());
     $this->bus->setQueryHandlerLoader(new ClassMapQueryHandlerLoader());
     $this->gate->attach($this->bus);
     // Use of AnnotationAdapter, adapters always us pipe
     $adapter = new AnnotationAdapter();
     $adapter->pipe($this->bus, array('Iteration\\Iteration4\\Iteration4Handler'));
     // Enable the SystemBus and pipe it to some Monitoring
     $this->gate->enableSystemBus();
     $adapter->pipe($this->gate->getSystemBus(), array('Iteration\\Iteration4\\Iteration4Monitor'));
     // Send a command to the bus
     // Iteration4Handler::editCommand is mapped against this command and will be called
     $this->bus->invokeCommand(new Iteration4Command('Hello'));
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
0
 public function testInvokeNonMappedEvent()
 {
     $gate = new Gate();
     $gate->enableSystemBus();
     $mockEvent = new MockEvent();
     $this->assertFalse($gate->getSystemBus()->publishEvent($mockEvent));
 }