/**
  * Attaches itself to the command dispatch of the application command bus
  *
  * @param ActionEventEmitter $emitter
  *
  * @return void
  */
 public function attach(ActionEventEmitter $emitter)
 {
     //Attach with a high priority, so that it invokes before the handler is invoked
     $this->trackHandler($emitter->attachListener(CommandBus::EVENT_INVOKE_HANDLER, [$this, 'onInvokeHandler'], 1000));
     //Attach with a high priority to rollback transaction early in case of an error
     $this->trackHandler($emitter->attachListener(CommandBus::EVENT_FINALIZE, [$this, 'onFinalize'], 1000));
 }
 /**
  * @param ActionEventEmitter $dispatcher
  */
 public function attach(ActionEventEmitter $dispatcher)
 {
     $onFinalizeCommandHandler = $dispatcher->attachListener(MessageBus::EVENT_FINALIZE, [$this, 'onFinalizeCommand']);
     $onErrorCommandHandler = $dispatcher->attachListener(MessageBus::EVENT_HANDLE_ERROR, [$this, 'onErrorCommand']);
     $this->trackHandler($onFinalizeCommandHandler);
     $this->trackHandler($onErrorCommandHandler);
 }
Beispiel #3
0
 /**
  * Inject an ActionEventDispatcher instance
  *
  * @param  ActionEventEmitter $actionEventDispatcher
  * @return void
  */
 public function setActionEventEmitter(ActionEventEmitter $actionEventDispatcher)
 {
     $actionEventDispatcher->attachListener(self::EVENT_INVOKE_HANDLER, function (ActionEvent $actionEvent) {
         $commandHandler = $actionEvent->getParam(self::EVENT_PARAM_MESSAGE_HANDLER);
         if (is_callable($commandHandler)) {
             $command = $actionEvent->getParam(self::EVENT_PARAM_MESSAGE);
             $commandHandler($command);
         }
     });
     $this->events = $actionEventDispatcher;
 }
Beispiel #4
0
 /**
  * Inject an ActionEventDispatcher instance
  *
  * @param  ActionEventEmitter $actionEventDispatcher
  * @return void
  */
 public function setActionEventEmitter(ActionEventEmitter $actionEventDispatcher)
 {
     $actionEventDispatcher->attachListener(self::EVENT_INVOKE_FINDER, function (ActionEvent $actionEvent) {
         $finder = $actionEvent->getParam(self::EVENT_PARAM_MESSAGE_HANDLER);
         if (is_callable($finder)) {
             $query = $actionEvent->getParam(self::EVENT_PARAM_MESSAGE);
             $deferred = $actionEvent->getParam(self::EVENT_PARAM_DEFERRED);
             $finder($query, $deferred);
         }
     });
     $this->events = $actionEventDispatcher;
 }
Beispiel #5
0
 /**
  * Rollback transaction
  *
  * @triggers rollback
  */
 public function rollback()
 {
     if ($this->transactionLevel === 0) {
         throw new RuntimeException('Cannot rollback transaction. EventStore has no active transaction');
     }
     if (!$this->adapter instanceof CanHandleTransaction) {
         throw new RuntimeException('Adapter cannot handle transaction and therefore cannot rollback');
     }
     $this->adapter->rollback();
     $this->transactionLevel = 0;
     $event = $this->actionEventEmitter->getNewActionEvent(__FUNCTION__, $this);
     $this->actionEventEmitter->dispatch($event);
     $this->recordedEvents = [];
 }
 /**
  * @param ActionEventEmitter $dispatcher
  */
 public function attach(ActionEventEmitter $dispatcher)
 {
     $this->trackHandler($dispatcher->attachListener("test", [$this, "onTest"], 100));
 }
 /**
  * @param ActionEventEmitter $events
  *
  * @return void
  */
 public function attach(ActionEventEmitter $events)
 {
     $this->trackHandler($events->attachListener(MessageBus::EVENT_ROUTE, [$this, "onRoute"], 1000));
 }
 /**
  * Attach one or more listeners
  *
  * @param ActionEventEmitter $events
  *
  * @return void
  */
 public function attach(ActionEventEmitter $events)
 {
     $this->trackHandler($events->attachListener(MessageBus::EVENT_INVOKE_HANDLER, $this, $this->priority));
 }
 /**
  * @param ActionEventEmitter $emitter
  */
 public function attach(ActionEventEmitter $emitter)
 {
     $emitter->attachListener(MessageBus::EVENT_INITIALIZE, [$this, 'onInitializeEvent']);
 }
 /**
  * @param ActionEventEmitter $emitter
  */
 public function attach(ActionEventEmitter $emitter)
 {
     $this->trackHandler($emitter->attachListener(MessageBus::EVENT_INITIALIZE, [$this, 'onDispatchInitialize']));
 }
 /**
  * @param ActionEventEmitter $events
  *
  * @return void
  */
 public function attach(ActionEventEmitter $events)
 {
     $this->trackHandler($events->attachListener(MessageBus::EVENT_LOCATE_HANDLER, [$this, 'onLocateMessageHandler']));
 }
 /**
  * @param ActionEventEmitter $dispatcher
  */
 public function attach(ActionEventEmitter $dispatcher)
 {
     $this->trackHandler($dispatcher->attachListener(QueryBus::EVENT_INVOKE_FINDER, $this));
 }
Beispiel #13
0
 /**
  * @param ActionEventEmitter $events
  *
  * @return void
  */
 public function attach(ActionEventEmitter $events)
 {
     $this->trackHandler($events->attachListener(MessageBus::EVENT_FINALIZE, [$this, "onFinalize"], -1000));
 }
 /**
  * @param ActionEventEmitter $dispatcher
  */
 public function attach(ActionEventEmitter $dispatcher)
 {
     $this->trackHandler($dispatcher->attachListener(MessageBus::EVENT_INITIALIZE, $this));
 }