src/IlaveU/FrontBundle/EventSubscriber/ApiPlatformKernelListener.php line 29
<?phpnamespace App\IlaveU\FrontBundle\EventSubscriber;use App\Entity\Settings;use Doctrine\Persistence\ManagerRegistry;use Exception;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\HttpKernel\Event\ExceptionEvent;use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;use Symfony\Component\EventDispatcher\Attribute\AsEventListener;use Symfony\Component\HttpFoundation\JsonResponse;use Symfony\Component\HttpFoundation\RedirectResponse;use Symfony\Component\HttpKernel\Event\RequestEvent;use Symfony\Component\Security\Core\Security;#[AsEventListener(event: RequestEvent::class, method: 'onKernelRequest')]class ApiPlatformKernelListener{public function __construct(private readonly ManagerRegistry $doctrine,private readonly Security $security){}public function onKernelRequest(RequestEvent $event){$request = $event->getRequest();// Check if the request is targeting the API platformif (strpos($request->getPathInfo(), '/'.$request->getLocale().'/api') !== 0) {return;}$settings = $this->doctrine->getRepository(Settings::class)->findOneBy(["code"=>"main"]);if($settings->getAssetFolderName() == "Taxiciel"){$allowedURIs = ['/'.$request->getLocale().'/api/booking/ajax-preview-mission','/'.$request->getLocale().'/api/missions-by-invoice','/'.$request->getLocale().'/api_login_check','/'.$request->getLocale().'/api/customers','/'.$request->getLocale().'/api/city_regions','/'.$request->getLocale().'/api/shipping_vehicle_types',];foreach($allowedURIs as $singleURI){if (strpos($request->getPathInfo(), $singleURI) === 0) {return;}}//User is not authenticated or doesn't have admin role$response = new JsonResponse(["message"=>'No Api Available'], Response::HTTP_FORBIDDEN);$event->setResponse($response);}}}