vendor/nellapp/sdk-bundle/src/EventSubscriber/RouteSecuritySubscriber.php line 35

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the nellapp-core package.
  4. *
  5. * (c) Benjamin Georgeault
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Nellapp\Bundle\SDKBundle\EventSubscriber;
  11. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
  14. use Symfony\Component\HttpKernel\KernelEvents;
  15. /**
  16. * Class RouteSecuritySubscriber
  17. *
  18. * @author Benjamin Georgeault
  19. */
  20. class RouteSecuritySubscriber implements EventSubscriberInterface
  21. {
  22. const REQUEST_KEY = '_nellapp_security';
  23. public static function getSubscribedEvents(): array
  24. {
  25. return [
  26. KernelEvents::CONTROLLER_ARGUMENTS => ['__invoke', 15],
  27. ];
  28. }
  29. public function __invoke(ControllerArgumentsEvent $event): void
  30. {
  31. if (!$event->isMainRequest()) {
  32. return;
  33. }
  34. $request = $event->getRequest();
  35. if (null === $expr = $request->attributes->get(self::REQUEST_KEY)) {
  36. return;
  37. }
  38. $request->attributes->set('_security', [new Security($expr)]);
  39. }
  40. }