<?php
/*
* This file is part of the nellapp-core package.
*
* (c) Benjamin Georgeault
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nellapp\Bundle\SDKBundle\EventSubscriber;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
use Symfony\Component\HttpKernel\KernelEvents;
/**
* Class RouteSecuritySubscriber
*
* @author Benjamin Georgeault
*/
class RouteSecuritySubscriber implements EventSubscriberInterface
{
const REQUEST_KEY = '_nellapp_security';
public static function getSubscribedEvents(): array
{
return [
KernelEvents::CONTROLLER_ARGUMENTS => ['__invoke', 15],
];
}
public function __invoke(ControllerArgumentsEvent $event): void
{
if (!$event->isMainRequest()) {
return;
}
$request = $event->getRequest();
if (null === $expr = $request->attributes->get(self::REQUEST_KEY)) {
return;
}
$request->attributes->set('_security', [new Security($expr)]);
}
}