<?php
declare(strict_types=1);
namespace FlexApp\Sentry;
use Sentry\State\HubInterface;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;
final class SentryFlushSubscriber implements EventSubscriberInterface
{
/** @var HubInterface */
private $hub;
public function __construct(HubInterface $hub)
{
$this->hub = $hub;
}
public static function getSubscribedEvents(): array
{
return [
KernelEvents::TERMINATE => ['flush', -1024],
ConsoleEvents::TERMINATE => ['flush', -1024],
];
}
public function flush(): void
{
$client = $this->hub->getClient();
if ($client !== null) {
$client->flush();
}
}
}