/** * 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); }
/** * Creates a new domain message from given array * * @param array $messageData * @return static */ public static function fromArray(array $messageData) : DelayedCommand { $message = parent::fromArray($messageData); /** @var $message self */ $message->executeAt = DateTimeImmutable::createFromFormat('Y-m-d\\TH:i:s.u', $message->metadata['execute_at'], new DateTimeZone('UTC')); return $message; }
/** * @param string $messageName * @param null $payload * @param int $version * @param Uuid $uuid * @param \DateTimeImmutable $createdAt * @param array $metadata * @throws \RuntimeException */ protected function __construct($messageName, $payload = null, $version = 1, Uuid $uuid = null, \DateTimeImmutable $createdAt = null, array $metadata = []) { $this->assertCommonPayload($payload); $this->assertPayload($payload); parent::__construct($messageName, $payload, $version, $uuid, $createdAt, $metadata); }
/** * @test */ public function it_is_of_type_command() { $this->assertEquals(DomainMessage::TYPE_COMMAND, $this->command->messageType()); }