<?php
declare(strict_types=1);
namespace MedBrief\MSR\EventSubscriber;
use MedBrief\MSR\Service\ProjectMatch\ExpertReportRequestService;
use Override;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;
/**
* Writes the expert report requests queued during a request once the caller's own saves are done.
*/
final class ExpertReportRequestSubscriber implements EventSubscriberInterface
{
public function __construct(
private readonly ExpertReportRequestService $expertReportRequestService,
) {
}
/**
* @return array<string, string>
*/
#[Override]
public static function getSubscribedEvents(): array
{
return [
KernelEvents::TERMINATE => 'onTerminate',
ConsoleEvents::TERMINATE => 'onTerminate',
];
}
public function onTerminate(): void
{
$this->expertReportRequestService->flushPending();
}
}