src/EventSubscriber/CheckHeadersSubscriber.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use ApiPlatform\Core\EventListener\EventPriorities;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  6. use Symfony\Component\HttpKernel\KernelEvents;
  7. class CheckHeadersSubscriber implements EventSubscriberInterface
  8. {
  9.     public static function getSubscribedEvents(): array
  10.     {
  11.         return [
  12.             KernelEvents::CONTROLLER => [
  13.                 ['hasFilter'EventPriorities::PRE_READ],
  14.             ],
  15.         ];
  16.     }
  17.     public function hasFilter(ControllerEvent $event): void
  18.     {
  19. //        // first check if this affects the requested resource
  20. //        $resource = $event->getRequest()->attributes->get('_api_resource_class');
  21. //
  22. //        if (EvaluationCriterion::class !== $resource) {
  23. //            return;
  24. //        }
  25. //
  26. //        // second check if this is the get_collection controller
  27. //        $controller = $event->getRequest()->attributes->get('_controller');
  28. //
  29. //        if ('api_platform.action.get_collection' !== $controller) {
  30. //            return;
  31. //        }
  32. //
  33. //        // third validate the required filter is set
  34. //        // we expect a filter via GET parameter 'filter-query-parameter'
  35. //        if (!$event->getRequest()->query->has('template') || $event->getRequest()->query->get('template') == '') {
  36. //            throw new BadRequestHttpException('Template Filter is required');
  37. //        }
  38.     }
  39. }