getActionEventEmitter() public method

public getActionEventEmitter ( ) : Prooph\Common\Event\ActionEventEmitter
return Prooph\Common\Event\ActionEventEmitter
 /**
  * @param EventStore $eventStore
  * @param AggregateType $aggregateType
  * @param AggregateTranslator $aggregateTranslator
  * @param SnapshotStore|null $snapshotStore
  * @param StreamName|null $streamName
  * @param bool $oneStreamPerAggregate
  */
 public function __construct(EventStore $eventStore, AggregateType $aggregateType, AggregateTranslator $aggregateTranslator, SnapshotStore $snapshotStore = null, StreamName $streamName = null, $oneStreamPerAggregate = false)
 {
     $this->eventStore = $eventStore;
     $this->eventStore->getActionEventEmitter()->attachListener('commit.pre', [$this, 'addPendingEventsToStream']);
     $this->aggregateType = $aggregateType;
     $this->aggregateTranslator = $aggregateTranslator;
     $this->snapshotStore = $snapshotStore;
     $this->streamName = $streamName;
     $this->oneStreamPerAggregate = $oneStreamPerAggregate;
 }
 /**
  * @param EventStore $eventStore
  * @param AggregateType $aggregateType
  * @param AggregateTranslator $aggregateTranslator
  * @param StreamStrategy|null $streamStrategy
  */
 public function __construct(EventStore $eventStore, AggregateType $aggregateType, AggregateTranslator $aggregateTranslator, StreamStrategy $streamStrategy = null)
 {
     $this->eventStore = $eventStore;
     $this->eventStore->getActionEventEmitter()->attachListener('commit.pre', $this);
     $this->aggregateType = $aggregateType;
     $this->aggregateTranslator = $aggregateTranslator;
     if (null === $streamStrategy) {
         $streamStrategy = new SingleStreamStrategy($this->eventStore);
     }
     $this->streamStrategy = $streamStrategy;
 }
Beispiel #3
0
 /**
  * @param EventStore $eventStore
  * @return void
  */
 public function setUp(EventStore $eventStore)
 {
     $eventStore->getActionEventEmitter()->attachListener('commit.post', [$this, 'onEventStoreCommitPost'], -1000);
 }
Beispiel #4
0
 use My\Infrastructure\UserRepositoryImpl;
 use My\Model\User;
 use Prooph\Common\Event\ActionEvent;
 use Prooph\Common\Event\ProophActionEventEmitter;
 use Prooph\EventStore\Adapter\InMemoryAdapter;
 use Prooph\EventStore\EventStore;
 $eventStore = new EventStore(new InMemoryAdapter(), new ProophActionEventEmitter());
 //Now we set up our user repository and inject the EventStore
 //Normally this should be done in an IoC-Container and the receiver of the repository should require My\Model\UserRepository
 $userRepository = new UserRepositoryImpl($eventStore);
 //Ok lets start a new transaction and create a user
 $eventStore->beginTransaction();
 $user = User::nameNew('John Doe');
 $userRepository->add($user);
 //Before we commit the transaction let's attach a listener to check that the UserWasCreated event is published after commit
 $eventStore->getActionEventEmitter()->attachListener('commit.post', function (ActionEvent $event) {
     foreach ($event->getParam('recordedEvents', new \ArrayIterator()) as $streamEvent) {
         echo sprintf("Event with name %s was recorded. It occurred on %s UTC /// ", $streamEvent->messageName(), $streamEvent->createdAt()->format('Y-m-d H:i:s'));
     }
 });
 $eventStore->commit();
 $userId = $user->userId();
 unset($user);
 //Ok, great. Now let's see how we can grab the user from the repository and change the name
 //First we need to start a new transaction
 $eventStore->beginTransaction();
 //The repository automatically tracks changes of the user...
 $loadedUser = $userRepository->get($userId);
 $loadedUser->changeName('Max Mustermann');
 //... so we only need to commit the transaction and the UserWasRenamed event should be recorded
 //(check output of the previously attached listener)
 /**
  * @param EventStore $eventStore
  */
 public function setUp(EventStore $eventStore)
 {
     $eventEmitter = $eventStore->getActionEventEmitter();
     $eventEmitter->attachListener('create.pre', [$this, 'onEventStoreCreateStream'], -1000);
     $eventEmitter->attachListener('appendTo.pre', [$this, 'onEventStoreAppendToStream'], -1000);
 }
 /**
  * @param EventStore $eventStore
  * @return void
  */
 public function setUp(EventStore $eventStore)
 {
     $eventStore->getActionEventEmitter()->attachListener('commit.post', [$this, "onPostCommit"]);
 }