> */ public static function getSubscribedEvents(): array { return [ KernelEvents::VIEW => ['validate', EventPriorities::POST_VALIDATE], ]; } /** * Si l'entité est une instance de ApiResourcesInterface, alors on active le validator. * * @throws \Exception */ public function validate(ViewEvent $event): void { $entity = $event->getControllerResult(); if (!$entity instanceof ApiResourcesInterface) { return; } $violations = $this->validator->validate($entity); if (count($violations) !== 0) { $messages = []; // there are errors, now you can show them foreach ($violations as $violation) { $messages[] = $violation->getMessage(); } throw new \Exception(join(',', $messages), 500); } } }