|
6 | 6 |
|
7 | 7 | use Domain\Collection\DinosaursCollection; |
8 | 8 | use Domain\Event\DinosaurIsBorn; |
9 | | -use Domain\Event\EventInterface; |
10 | | -use Domain\Exception\DinosaurNotFoundException; |
11 | | -use Domain\Model\Dinosaur; |
12 | 9 | use Psr\Log\LoggerInterface; |
13 | | -use Symfony\Component\Messenger\Handler\MessageSubscriberInterface; |
| 10 | +use Symfony\Component\Messenger\Attribute\AsMessageHandler; |
14 | 11 |
|
15 | | -class LogWhenDinosaurIsBorn implements MessageSubscriberInterface |
| 12 | +#[AsMessageHandler] |
| 13 | +final class LogWhenDinosaurIsBorn |
16 | 14 | { |
17 | 15 | public function __construct( |
18 | | - private DinosaursCollection $dinosaursCollection, |
19 | | - private LoggerInterface $logger |
| 16 | + private readonly DinosaursCollection $dinosaursCollection, |
| 17 | + private readonly LoggerInterface $logger |
20 | 18 | ) { |
21 | 19 | } |
22 | 20 |
|
23 | | - public function __invoke(EventInterface $event): void |
| 21 | + public function __invoke(DinosaurIsBorn $event): void |
24 | 22 | { |
25 | 23 | $dinosaurId = $event->getAggregateRootId(); |
26 | 24 |
|
27 | 25 | $dinosaur = $this->dinosaursCollection->find($dinosaurId); |
28 | 26 |
|
| 27 | +<<<<<<< HEAD |
29 | 28 | if (!$dinosaur instanceof Dinosaur) { |
30 | 29 | throw new DinosaurNotFoundException($dinosaurId); |
31 | 30 | } |
32 | 31 |
|
| 32 | +======= |
| 33 | +>>>>>>> 4c18e77 (refactor: update and fix some issues for symfony 7) |
33 | 34 | $this->logger->info(\sprintf( |
34 | 35 | 'Dinosaur %s was born', |
35 | 36 | $dinosaur->getName() |
36 | 37 | )); |
37 | 38 | } |
38 | | - |
39 | | - public static function getHandledMessages(): iterable |
40 | | - { |
41 | | - yield DinosaurIsBorn::class; |
42 | | - } |
43 | 39 | } |
0 commit comments