vendor/kematjaya/menu-bundle/src/Listener/CredentialListener.php line 39

Open in your IDE?
  1. <?php
  2. /**
  3.  * This file is part of the menu-bundle.
  4.  */
  5. namespace Kematjaya\MenuBundle\Listener;
  6. use Kematjaya\MenuBundle\Credential\RouteCredentialInterface;
  7. use Symfony\Component\HttpKernel\Event\RequestEvent;
  8. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  9. use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
  10. /**
  11.  * @package Kematjaya\MenuBundle\Listener
  12.  * @license https://opensource.org/licenses/MIT MIT
  13.  * @author  Nur Hidayatullah <[email protected]>
  14.  */
  15. class CredentialListener 
  16. {
  17.     /**
  18.      * 
  19.      * @var RouteCredentialInterface
  20.      */
  21.     private $routeCredential;
  22.     
  23.     /**
  24.      * 
  25.      * @var UrlGeneratorInterface
  26.      */
  27.     private $urlGenerator;
  28.     
  29.     public function __construct(RouteCredentialInterface $routeCredentialUrlGeneratorInterface $urlGenerator
  30.     {
  31.         $this->routeCredential $routeCredential;
  32.         $this->urlGenerator $urlGenerator;
  33.     }
  34.     
  35.     public function onKernelRequest(RequestEvent $event)
  36.     {
  37.         if(!$event->isMainRequest()) {
  38.             
  39.             return;
  40.         }
  41.         
  42.         $request    $event->getRequest();
  43.         $path       $request->attributes->get('_route');
  44.         if($this->routeCredential->isAllowed($path)) {
  45.             
  46.             return;
  47.         }
  48.         
  49.         throw new AccessDeniedHttpException();
  50.     }
  51. }