vendor/elements/style-lab-bundle/src/EventSubscriber/UserSubscriber.php line 21

Open in your IDE?
  1. <?php
  2. namespace Elements\Bundle\StyleLabBundle\EventSubscriber;
  3. use Elements\Bundle\StyleLabBundle\Controller\AuthController;
  4. use Elements\Bundle\StyleLabBundle\Security\User\User;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  7. use Symfony\Component\HttpKernel\KernelEvents;
  8. use Symfony\Component\Security\Core\Security;
  9. class UserSubscriber implements EventSubscriberInterface
  10. {
  11.     private $security;
  12.     public function __construct(Security $security)
  13.     {
  14.         $this->security $security;
  15.     }
  16.     public function onKernelController(ControllerEvent $event)
  17.     {
  18.         $controller $event->getController();
  19.         // when a controller class defines multiple action methods, the controller
  20.         // is returned as [$controllerInstance, 'methodName']
  21.         if (is_array($controller)) {
  22.             $controller $controller[0];
  23.         }
  24.         if ($controller instanceof AuthController) {
  25.             $user $this->security->getUser();
  26.             $adminUser false;
  27.             if ($user) {
  28.                 if (($user instanceof User && $user->getUsername() == 'stylelab') || (method_exists($user'getUser') && (strpos($user->getUser()->getEmail(), '@elements.at') !== false))) {
  29.                     $adminUser true;
  30.                 }
  31.             }
  32.             //todo set right
  33. //            $event->getRequest()->attributes->set('isAdmin', $adminUser);
  34.             $event->getRequest()->attributes->set('isAdmin'$adminUser);
  35.         }
  36.     }
  37.     public static function getSubscribedEvents()
  38.     {
  39.         return [
  40.             KernelEvents::CONTROLLER => 'onKernelController',
  41.         ];
  42.     }
  43. }