src/Listener/Pos/GetPosIdWithoutCinemaContextListener.php line 26

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Listener\Pos;
  4. use App\Annotation\GetPosIdWithoutCinemaContext;
  5. use App\Exception\RegionReflectionException;
  6. use App\Subscriber\Pos\PosNumberSubscriber;
  7. use Doctrine\Common\Annotations\Reader;
  8. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  9. use ReflectionClass;
  10. use ReflectionException;
  11. class GetPosIdWithoutCinemaContextListener
  12. {
  13.     private PosNumberSubscriber $posNumberSubscriber;
  14.     private Reader $annotationReader;
  15.     public function __construct(PosNumberSubscriber $posNumberSubscriberReader $annotationReader)
  16.     {
  17.         $this->posNumberSubscriber $posNumberSubscriber;
  18.         $this->annotationReader $annotationReader;
  19.     }
  20.     public function onKernelController(ControllerEvent $event): void
  21.     {
  22.         $controllers $event->getController();
  23.         if (!is_array($controllers)) {
  24.             return;
  25.         }
  26.         $this->handleAnnotation($controllers);
  27.     }
  28.     private function handleAnnotation(iterable $controllers)
  29.     {
  30.         [$controller$method] = $controllers;
  31.         try {
  32.             $controller = new ReflectionClass($controller);
  33.             $method $controller->getMethod($method);
  34.         } catch (ReflectionException) {
  35.             throw new RegionReflectionException();
  36.         }
  37.         $annotation $this->annotationReader->getMethodAnnotation($methodGetPosIdWithoutCinemaContext::class);
  38.         if ($annotation instanceof GetPosIdWithoutCinemaContext) {
  39.             $this->posNumberSubscriber->setSkip(false);
  40.         }
  41.     }
  42. }