|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * This file is part of event-engine/php-messaging. |
| 4 | + * (c) 2018-2019 prooph software GmbH <contact@prooph.de> |
| 5 | + * |
| 6 | + * For the full copyright and license information, please view the LICENSE |
| 7 | + * file that was distributed with this source code. |
| 8 | + */ |
| 9 | + |
| 10 | +declare(strict_types=1); |
| 11 | + |
| 12 | +namespace EventEngine\Messaging; |
| 13 | + |
| 14 | +final class CommandDispatchResult |
| 15 | +{ |
| 16 | + /** |
| 17 | + * @var Message |
| 18 | + */ |
| 19 | + private $dispatchedCommand; |
| 20 | + |
| 21 | + /** |
| 22 | + * @var string |
| 23 | + */ |
| 24 | + private $effectedAggregateId; |
| 25 | + |
| 26 | + /** |
| 27 | + * @var Message[] |
| 28 | + */ |
| 29 | + private $recordedEvents; |
| 30 | + |
| 31 | + public static function forCommandHandledByAggregate(Message $dispatchedCommand, string $effectedAggregateId, Message ...$recordedEvents): self |
| 32 | + { |
| 33 | + return new self($dispatchedCommand, $effectedAggregateId, ...$recordedEvents); |
| 34 | + } |
| 35 | + |
| 36 | + public static function forCommandHandledByPreProcessor(Message $dispatchedCommand): self |
| 37 | + { |
| 38 | + return new self($dispatchedCommand); |
| 39 | + } |
| 40 | + |
| 41 | + public static function forCommandHandledByController(Message $dispatedCommand): self |
| 42 | + { |
| 43 | + return new self($dispatedCommand); |
| 44 | + } |
| 45 | + |
| 46 | + private function __construct(Message $dispatchedCommand, string $effectedAggregateId = null, Message ...$recordedEvents) |
| 47 | + { |
| 48 | + $this->dispatchedCommand = $dispatchedCommand; |
| 49 | + $this->effectedAggregateId = $effectedAggregateId; |
| 50 | + $this->recordedEvents = $recordedEvents; |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * @return Message |
| 55 | + */ |
| 56 | + public function dispatchedCommand(): Message |
| 57 | + { |
| 58 | + return $this->dispatchedCommand; |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * @return string|null |
| 63 | + */ |
| 64 | + public function effectedAggregateId(): ?string |
| 65 | + { |
| 66 | + return $this->effectedAggregateId; |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * @return Message[] |
| 71 | + */ |
| 72 | + public function recordedEvents(): array |
| 73 | + { |
| 74 | + return $this->recordedEvents; |
| 75 | + } |
| 76 | +} |
0 commit comments