<?php
namespace App\EventSubscriber;
use ApiPlatform\Symfony\EventListener\EventPriorities;
use App\Entity\Category;
use App\Entity\Document;
use App\Evaluation\EvaluationPrepare;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\ViewEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Security\Core\Security;
final class DocumentSubscriber implements EventSubscriberInterface
{
private LoggerInterface $logger;
public function __construct(private EvaluationPrepare $evaluationPrepare, private Security $security, LoggerInterface $logger
)
{
$this->logger = $logger;
}
public static function getSubscribedEvents()
{
return [
KernelEvents::VIEW => ['prepareEvaluations', EventPriorities::POST_WRITE],
];
}
public function prepareEvaluations(ViewEvent $event): void
{
$document = $event->getControllerResult();
$method = $event->getRequest()->getMethod();
if ((!$document instanceof Document)) {
return;
}
$this->logger->info('Processing Document ID :'.$document->getId());
$this->evaluationPrepare->prepare($document, $this->security->getUser());
}
}