<?php
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Profiler\Profiler;
class AdminSyncProfilerSubscriber implements EventSubscriberInterface
{
private $profiler;
public function __construct(?Profiler $profiler = null)
{
$this->profiler = $profiler;
}
public static function getSubscribedEvents(): array
{
return [
KernelEvents::REQUEST => ['disableProfilerForAdminSync', 255],
];
}
public function disableProfilerForAdminSync(RequestEvent $event): void
{
if (!$event->isMasterRequest() || $this->profiler === null) {
return;
}
if (strpos($event->getRequest()->getPathInfo(), '/admin/sync/') === 0) {
$this->profiler->disable();
}
}
}