28 lines
735 B
PHP
28 lines
735 B
PHP
<?php
|
|
|
|
namespace App\Domain\Event;
|
|
|
|
use App\Domain\Event\PersistEvent;
|
|
use App\Domain\Model\Persisted\PersistedEvent;
|
|
use App\Infrastructure\Repository\EventRepository;
|
|
|
|
class PersistEventHandler
|
|
{
|
|
public function __construct(
|
|
private readonly EventRepository $eventRepository,
|
|
) {
|
|
}
|
|
|
|
public function handle(PersistEvent $event): void
|
|
{
|
|
$persistedEvent = new PersistedEvent();
|
|
if ($event->id !== null) {
|
|
$persistedEvent = $this->eventRepository->find($event->id);
|
|
if (!$persistedEvent) {
|
|
throw new \Exception('Event not found');
|
|
}
|
|
}
|
|
|
|
$this->eventRepository->save($event->draft->mergeIntoPersisted($persistedEvent));
|
|
}
|
|
} |