<?php
namespace App\EventSubscriber;
use ApiPlatform\Core\EventListener\EventPriorities;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class CheckHeadersSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
KernelEvents::CONTROLLER => [
['hasFilter', EventPriorities::PRE_READ],
],
];
}
public function hasFilter(ControllerEvent $event): void
{
// // first check if this affects the requested resource
// $resource = $event->getRequest()->attributes->get('_api_resource_class');
//
// if (EvaluationCriterion::class !== $resource) {
// return;
// }
//
// // second check if this is the get_collection controller
// $controller = $event->getRequest()->attributes->get('_controller');
//
// if ('api_platform.action.get_collection' !== $controller) {
// return;
// }
//
// // third validate the required filter is set
// // we expect a filter via GET parameter 'filter-query-parameter'
// if (!$event->getRequest()->query->has('template') || $event->getRequest()->query->get('template') == '') {
// throw new BadRequestHttpException('Template Filter is required');
// }
}
}