src/Event/Subscriber/LoggerSubscriberBase.php line 35
<?phpnamespace App\Event\Subscriber;use App\Entity\LogEntryInterface;use App\Event\CommonEventInterface;use App\Utility\LogUtility;use Doctrine\ORM\EntityManagerInterface;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\HttpFoundation\RequestStack;abstract class LoggerSubscriberBase implements EventSubscriberInterface{public function __construct(protected readonly RequestStack $requestStack,protected readonly EntityManagerInterface $entityManager,protected readonly LogUtility $logUtility) {}abstract protected function getBaseLogEntry(): LogEntryInterface;final protected function addCommonDetailsToLogEntry(LogEntryInterface $entry, CommonEventInterface $event): LogEntryInterface{return $entry->setDetails($this->logUtility->encodeEventDetails($event->getEventDetails()))->setTagGroups($event->getEventTags())->setEventType($event::class);}public function addAdditionalDetailsToLogEntry(LogEntryInterface $entry, CommonEventInterface $event): LogEntryInterface{return $entry;}final public function onEvent(CommonEventInterface $event): void{$entry = $this->getBaseLogEntry();$entry = $this->addCommonDetailsToLogEntry($entry, $event);$entry = $this->addAdditionalDetailsToLogEntry($entry, $event);$this->entityManager->persist($entry);$this->entityManager->flush();}}