src/EventListener/StaticNotificationListener.php line 37

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Entity\System\Profile;
  4. use App\Factory\Admin\StaticNotificationFactory;
  5. use App\Service\EnvironmentService;
  6. use App\Service\SecurityService;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Symfony\Component\HttpKernel\KernelEvents;
  9. use Twig\Environment;
  10. class StaticNotificationListener implements EventSubscriberInterface
  11. {
  12.     private Environment $environment;
  13.     private EnvironmentService $environmentService;
  14.     private SecurityService $securityService;
  15.     public function __construct(
  16.         Environment $environment,
  17.         EnvironmentService $environmentService,
  18.         SecurityService $securityService
  19.     ) {
  20.         $this->environment $environment;
  21.         $this->environmentService $environmentService;
  22.         $this->securityService $securityService;
  23.     }
  24.     /**
  25.      * {@inheritDoc}
  26.      */
  27.     public static function getSubscribedEvents(): array
  28.     {
  29.         return [KernelEvents::REQUEST => ['onKernelRequest']];
  30.     }
  31.     public function onKernelRequest(): void
  32.     {
  33.         $employee $this->securityService->findSessionEmployee();
  34.         if (!$employee || $this->environmentService->isApi()) {
  35.             return;
  36.         }
  37.         $staticNotices = [];
  38.         if ($employee->getProfile()->getId() === Profile::NEW_USER_ID) {
  39.             $staticNotices[] = StaticNotificationFactory::createFromValues(
  40.                 'Usuario nuevo creado',
  41.                 'Usuario sin permisos contacta con tu responsable para completar el proceso.'
  42.             );
  43.         }
  44.         $this->environment->addGlobal('static_notifications'$staticNotices);
  45.     }
  46. }