vendor/appaydin/pd-api/Listener/ZoneMatcherListener.php line 26

Open in your IDE?
  1. <?php
  2. /**
  3.  * This file is part of the pd-admin pd-api package.
  4.  *
  5.  * @package     pd-api
  6.  * @license     LICENSE
  7.  * @author      Ramazan APAYDIN <apaydin541@gmail.com>
  8.  * @link        https://github.com/appaydin/pd-api
  9.  */
  10. namespace Pd\ApiBundle\Listener;
  11. use Pd\ApiBundle\PdApiBundle;
  12. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. use Symfony\Component\HttpKernel\Event\RequestEvent;
  15. use Symfony\Component\HttpKernel\KernelEvents;
  16. class ZoneMatcherListener implements EventSubscriberInterface
  17. {
  18.     public function __construct(private ParameterBagInterface $bag)
  19.     {
  20.     }
  21.     public function onKernelRequest(RequestEvent $event): void
  22.     {
  23.         $request $event->getRequest();
  24.         foreach ($this->bag->get('pd_api.zone') as $zone) {
  25.             if (preg_match("{{$zone}}"$request->getPathInfo())) {
  26.                 $request->attributes->set(PdApiBundle::ZONE_ATTRIBUTEtrue);
  27.                 return;
  28.             }
  29.         }
  30.         $request->attributes->set(PdApiBundle::ZONE_ATTRIBUTEfalse);
  31.     }
  32.     public static function getSubscribedEvents(): array
  33.     {
  34.         return [
  35.             KernelEvents::REQUEST => [['onKernelRequest'248]],
  36.         ];
  37.     }
  38. }