src/EventSubscriber/DocumentSubscriber.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use ApiPlatform\Symfony\EventListener\EventPriorities;
  4. use App\Entity\Document;
  5. use App\Evaluation\EvaluationPrepare;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpKernel\Event\ViewEvent;
  9. use Symfony\Component\HttpKernel\KernelEvents;
  10. use Symfony\Component\Security\Core\Security;
  11. final class DocumentSubscriber implements EventSubscriberInterface
  12. {
  13.     public function __construct(private EvaluationPrepare $evaluationPrepare, private Security $security)
  14.     {
  15.     }
  16.     public static function getSubscribedEvents()
  17.     {
  18.         return [
  19.             KernelEvents::VIEW => ['prepareEvaluations'EventPriorities::POST_WRITE],
  20.         ];
  21.     }
  22.     public function prepareEvaluations(ViewEvent $event): void
  23.     {
  24.         $document $event->getControllerResult();
  25.         $method $event->getRequest()->getMethod();
  26.         if ((!$document instanceof Document)) {
  27.             return;
  28.         }
  29.         $this->evaluationPrepare->prepare($document$this->security->getUser());
  30.     }
  31. }