-
Notifications
You must be signed in to change notification settings - Fork 1
/
CreateEventMessageHandler.php
36 lines (28 loc) · 1.17 KB
/
CreateEventMessageHandler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
declare(strict_types=1);
namespace FrameworkCompatibilityProject\Event\Application\MessageHandler;
use FrameworkCompatibilityProject\Event\Application\Datamapper\EventDataMapperInterface;
use FrameworkCompatibilityProject\Event\Application\Message\CreateEventMessage;
use FrameworkCompatibilityProject\Event\Domain\Model\EventInterface;
use FrameworkCompatibilityProject\Event\Domain\Repository\EventRepositoryInterface;
final class CreateEventMessageHandler
{
/**
* @param iterable<EventDataMapperInterface> $eventDataMappers
*/
public function __construct(
private EventRepositoryInterface $eventRepository,
private iterable $eventDataMappers
) {
}
public function __invoke(CreateEventMessage $message): EventInterface
{
$event = $this->eventRepository->create($message->getLocale());
$eventTranslation = $this->eventRepository->createTranslation($event, $event->getDefaultLocale());
foreach ($this->eventDataMappers as $eventDataMapper) {
$eventDataMapper->map($event, $eventTranslation, $message->getData());
}
$this->eventRepository->add($event);
return $event;
}
}