src/EventSubscriber/LogginSubscriber.php line 30

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: rostandnj
  5.  * Date: 27/5/19
  6.  * Time: 9:38 AM
  7.  */
  8. namespace App\EventSubscriber;
  9. use App\Controller\LogginInterfaceController;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  12. use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
  13. use Symfony\Component\HttpKernel\KernelEvents;
  14. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  15. use Symfony\Component\DependencyInjection\ContainerInterface;
  16. class LogginSubscriber implements EventSubscriberInterface
  17. {
  18.     private $session;
  19.     public function __construct(SessionInterface $s,ContainerInterface $c)
  20.     {
  21.         $this->session = $s;
  22.         $this->mycontainer = $c;
  23.     }
  24.     public function onKernelController(ControllerEvent $event)
  25.     {
  26.         $controller = $event->getController();
  27.         /*
  28.          * $controller passed can be either a class or a Closure.
  29.          * This is not usual in Symfony but it may happen.
  30.          * If it is a class, it comes in array format
  31.          */
  32.         if (!is_array($controller)) {
  33.             return 0;
  34.         }
  35.         if ($controller[0] instanceof LogginInterfaceController) {
  36.            return 0;
  37.         }
  38.     }
  39.     public static function getSubscribedEvents()
  40.     {
  41.         return [
  42.             KernelEvents::CONTROLLER => 'onKernelController',
  43.         ];
  44.     }
  45. }