<?php
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Profiler\Profiler;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Security;
class EnvSwitcherSubscriber implements EventSubscriberInterface
{
private Security $security;
private ?Profiler $profiler;
public function __construct(Security $security, ?Profiler $profiler)
{
$this->security = $security;
$this->profiler = $profiler;
}
public function onKernelRequest(RequestEvent $event): void
{
$request = $event->getRequest();
// var_dump($request->headers);
$user = $this->security->getUser();
if (!$user || !in_array('ROLE_ADMIN', $user->getRoles())) {
//$this->profiler->disable();
}
// dd($event->getRequest()->server->get('APP_ENV'));
}
public static function getSubscribedEvents(): array
{
return [
'kernel.request' => 'onKernelRequest',
];
}
}