<?php
namespace App\EventListener;
use App\Entity\System\Profile;
use App\Factory\Admin\StaticNotificationFactory;
use App\Service\EnvironmentService;
use App\Service\SecurityService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Twig\Environment;
class StaticNotificationListener implements EventSubscriberInterface
{
private Environment $environment;
private EnvironmentService $environmentService;
private SecurityService $securityService;
public function __construct(
Environment $environment,
EnvironmentService $environmentService,
SecurityService $securityService
) {
$this->environment = $environment;
$this->environmentService = $environmentService;
$this->securityService = $securityService;
}
/**
* {@inheritDoc}
*/
public static function getSubscribedEvents(): array
{
return [KernelEvents::REQUEST => ['onKernelRequest']];
}
public function onKernelRequest(): void
{
$employee = $this->securityService->findSessionEmployee();
if (!$employee || $this->environmentService->isApi()) {
return;
}
$staticNotices = [];
if ($employee->getProfile()->getId() === Profile::NEW_USER_ID) {
$staticNotices[] = StaticNotificationFactory::createFromValues(
'Usuario nuevo creado',
'Usuario sin permisos contacta con tu responsable para completar el proceso.'
);
}
$this->environment->addGlobal('static_notifications', $staticNotices);
}
}