src/EventListener/DoctrineExtensionListener.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use Symfony\Component\HttpKernel\Event\RequestEvent;
  4. use Symfony\Component\DependencyInjection\ContainerAwareInterface;
  5. use Symfony\Component\DependencyInjection\ContainerInterface;
  6. use Symfony\Component\HttpKernel\Kernel;
  7. class DoctrineExtensionListener implements ContainerAwareInterface
  8. {
  9.     /**
  10.      * @var ContainerInterface
  11.      */
  12.     protected $container;
  13.     public function setContainer(ContainerInterface $container null)
  14.     {
  15.         $this->container $container;
  16.     }
  17.     public function onLateKernelRequest(RequestEvent $event)
  18.     {
  19.         $translatable $this->container->get('gedmo.listener.translatable');
  20.         $translatable->setTranslatableLocale($event->getRequest()->getLocale());
  21.     }
  22.     public function onConsoleCommand()
  23.     {
  24.         $this->container->get('gedmo.listener.translatable')
  25.             ->setTranslatableLocale($this->container->get('translator')->getLocale());
  26.     }
  27.     public function onKernelRequest(RequestEvent $event)
  28.     {
  29.         if (Kernel::MAJOR_VERSION == && Kernel::MINOR_VERSION 6) {
  30.             $securityContext $this->container->get('security.context'ContainerInterface::NULL_ON_INVALID_REFERENCE);
  31.             if (null !== $securityContext && null !== $securityContext->getToken() && $securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
  32.                 # for loggable behavior
  33.                 $loggable $this->container->get('gedmo.listener.loggable');
  34.                 $loggable->setUsername($securityContext->getToken()->getUsername());
  35.                 # for blameable behavior
  36.                 $blameable $this->container->get('gedmo.listener.blameable');
  37.                 $blameable->setUserValue($securityContext->getToken()->getUser());
  38.             }
  39.         }
  40.         else {
  41.             $tokenStorage $this->container->get('security.token_storage')->getToken();
  42.             $authorizationChecker $this->container->get('security.authorization_checker');
  43.             if (null !== $tokenStorage && $authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
  44.                 # for loggable behavior
  45.                 $loggable $this->container->get('gedmo.listener.loggable');
  46.                 $loggable->setUsername($tokenStorage->getUser());
  47.                 # for blameable behavior
  48.                 $blameable $this->container->get('gedmo.listener.blameable');
  49.                 $blameable->setUserValue($tokenStorage->getUser());
  50.             }
  51.         }
  52.     }
  53. }