コード例 #1
0
 /**
  * This method takes domain events as argument which are going to be added to the event stream and
  * adds the causation_id (command UUID) and causation_name (name of the command which has caused the events)
  * as metadata to each event.
  *
  * @param Iterator $recordedEvents
  * @return Iterator
  */
 private function handleRecordedEvents(Iterator $recordedEvents)
 {
     if (is_null($this->currentCommand) || !$this->currentCommand instanceof Message) {
         return $recordedEvents;
     }
     $causationId = $this->currentCommand->uuid()->toString();
     $causationName = $this->currentCommand->messageName();
     $enrichedRecordedEvents = [];
     foreach ($recordedEvents as $recordedEvent) {
         $recordedEvent = $recordedEvent->withAddedMetadata('causation_id', $causationId);
         $recordedEvent = $recordedEvent->withAddedMetadata('causation_name', $causationName);
         $enrichedRecordedEvents[] = $recordedEvent;
     }
     return new ArrayIterator($enrichedRecordedEvents);
 }
コード例 #2
0
ファイル: CommandTest.php プロジェクト: MattKetmo/common
 /**
  * @test
  */
 public function it_has_a_name()
 {
     $this->assertEquals('TestCommand', $this->command->messageName());
 }