src/Event/ControllerInputValidator.php line 18

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Event;
  4. use ApiPlatform\Core\Validator\ValidatorInterface;
  5. use App\Dto\PreValidatedInput;
  6. use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
  7. class ControllerInputValidator
  8. {
  9.     public function __construct(
  10.         private readonly ValidatorInterface $validator,
  11.     ) {
  12.     }
  13.     public function onKernelControllerArguments(ControllerArgumentsEvent $event): void
  14.     {
  15.         foreach ($event->getArguments() as $argument) {
  16.             if (is_a($argumentPreValidatedInput::class, true)) {
  17.                 $this->validator->validate($argument);
  18.             }
  19.         }
  20.     }
  21. }