<?php
declare(strict_types=1);
namespace App\Event;
use ApiPlatform\Core\Validator\ValidatorInterface;
use App\Dto\PreValidatedInput;
use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
class ControllerInputValidator
{
public function __construct(
private readonly ValidatorInterface $validator,
) {
}
public function onKernelControllerArguments(ControllerArgumentsEvent $event): void
{
foreach ($event->getArguments() as $argument) {
if (is_a($argument, PreValidatedInput::class, true)) {
$this->validator->validate($argument);
}
}
}
}