<?php
namespace App\EventListener\Api\TokenInterceptor;
use App\Exception\Authorization\MybizApplicationVersionNotSupportedException;
use App\Exception\Authorization\MybizAuthorizationException;
use App\Service\Authorization\MybizRequestAuthorizationChecker;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\KernelEvents;
final class MybizTokenSubscriber implements EventSubscriberInterface
{
private MybizRequestAuthorizationChecker $mybizRequestAuthorizationChecker;
public function __construct(
MybizRequestAuthorizationChecker $mybizRequestAuthorizationChecker
)
{
$this->mybizRequestAuthorizationChecker = $mybizRequestAuthorizationChecker;
}
/**
* @param ControllerEvent $event
* @throws MybizAuthorizationException
* @throws MybizApplicationVersionNotSupportedException
*/
public function onKernelController(ControllerEvent $event): void
{
$controller = $event->getController();
if (!is_array($controller)) {
return;
}
if ($controller[0] instanceof MybizTokenAuthenticatorInterface) {
$this->mybizRequestAuthorizationChecker->checkAuthorization($event->getRequest());
}
}
/**
* @return string[]
*/
public static function getSubscribedEvents(): array
{
return [
KernelEvents::CONTROLLER => 'onKernelController'
];
}
}