src/EventListener/Api/TokenInterceptor/MybizTokenSubscriber.php line 29

Open in your IDE?
  1. <?php
  2. namespace App\EventListener\Api\TokenInterceptor;
  3. use App\Exception\Authorization\MybizApplicationVersionNotSupportedException;
  4. use App\Exception\Authorization\MybizAuthorizationException;
  5. use App\Service\Authorization\MybizRequestAuthorizationChecker;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  8. use Symfony\Component\HttpKernel\KernelEvents;
  9. final class MybizTokenSubscriber implements EventSubscriberInterface
  10. {
  11.     private MybizRequestAuthorizationChecker $mybizRequestAuthorizationChecker;
  12.     public function __construct(
  13.         MybizRequestAuthorizationChecker $mybizRequestAuthorizationChecker
  14.     )
  15.     {
  16.         $this->mybizRequestAuthorizationChecker $mybizRequestAuthorizationChecker;
  17.     }
  18.     /**
  19.      * @param ControllerEvent $event
  20.      * @throws MybizAuthorizationException
  21.      * @throws MybizApplicationVersionNotSupportedException
  22.      */
  23.     public function onKernelController(ControllerEvent $event): void
  24.     {
  25.         $controller $event->getController();
  26.         if (!is_array($controller)) {
  27.             return;
  28.         }
  29.         if ($controller[0] instanceof MybizTokenAuthenticatorInterface) {
  30.             $this->mybizRequestAuthorizationChecker->checkAuthorization($event->getRequest());
  31.         }
  32.     }
  33.     /**
  34.      * @return string[]
  35.      */
  36.     public static function getSubscribedEvents(): array
  37.     {
  38.         return [
  39.             KernelEvents::CONTROLLER => 'onKernelController'
  40.         ];
  41.     }
  42. }