<?php
declare(strict_types=1);
/*
* This file is part of the SynergyBot project.
*
* For the full copyright and license information,
* please read the LICENSE.md file that was distributed with this source code.
*
* The SymfonyBot project - inspiring people to chat!
*
* Copyright (c) 2022.
*/
namespace SynergyBot\InnerApiBundle\EventListener;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use SynergyBot\InnerApiBundle\Service\TokenService;
class InnerApiTokenListener
{
private const ROUTE = '/innerapi';
private TokenService $tokenService;
public function __construct(TokenService $tokenService)
{
$this->tokenService = $tokenService;
}
public function onKernelRequest(RequestEvent $event)
{
if (!$event->isMainRequest()) {
return;
}
$request = $event->getRequest();
if (!str_starts_with($request->getPathInfo(), self::ROUTE)) {
return;
}
$this->tokenService->checkRequest($request);
}
}