router = $router; } public function onKernelRequest(KernelEvent $event): void { $request = $event->getRequest(); if (!$request) { throw new BadRequestHttpException('Please provide a valid request!'); } $context = new RequestContext(); $context->fromRequest(Request::createFromGlobals()); $matcher = new UrlMatcher($this->router->getRouteCollection(), $context); $matcher->setContext($context); $checkRoute = $matcher->match($request->getPathInfo()); if (!$request->headers->get('x-auth-token') && (false === in_array($checkRoute['_route'], self::PROJECT_ROUTER, true))) { throw new AccessDeniedHttpException('This action needs a valid token!'); } } public static function getSubscribedEvents(): array { return [ KernelEvents::REQUEST => ['onKernelRequest', 32], ]; } }