<?php
namespace AppBundle\EventListener;
use CodersLab\Lms\SharedKernel\Domain\Bus\EventBus;
use CodersLab\Lms\SharedKernel\Domain\Bus\IEventRecorder;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
final class EventPublisherListener
{
private EventBus $eventBus;
private IEventRecorder $eventRecorder;
public function __construct(EventBus $eventBus, IEventRecorder $eventRecorder)
{
$this->eventBus = $eventBus;
$this->eventRecorder = $eventRecorder;
}
public function __invoke(ResponseEvent $event): void
{
foreach ($this->eventRecorder->pullEvents() as $recordedEvent) {
$this->eventBus->notify($recordedEvent);
}
}
}