app/Customize/Event.php line 46

Open in your IDE?
  1. <?php
  2. namespace Customize;
  3. use Eccube\Request\Context;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  6. use Symfony\Component\HttpKernel\KernelEvents;
  7. use Twig\Environment;
  8. class Event implements EventSubscriberInterface
  9. {
  10.     /** @var Context */
  11.     protected $requestContext;
  12.     /** @var Environment */
  13.     protected $twig;
  14.     /**
  15.      * Event constructor.
  16.      *
  17.      * @param Context $requestContext
  18.      * @param Environment $twig
  19.      */
  20.     public function __construct(
  21.         Context $requestContext,
  22.         Environment $twig
  23.     )
  24.     {
  25.         $this->requestContext $requestContext;
  26.         $this->twig $twig;
  27.     }
  28.     /**
  29.      * @return array
  30.      */
  31.     public static function getSubscribedEvents()
  32.     {
  33.         return [
  34.             KernelEvents::REQUEST => ['onKernelRequest'100000000]
  35.         ];
  36.     }
  37.     /**
  38.      * @param GetResponseEvent $event
  39.      */
  40.     public function onKernelRequest()
  41.     {
  42.         if ($this->requestContext->isAdmin()) {
  43.             return;
  44.         }
  45.         $isProd $_SERVER['APP_ENV'] === 'prod';
  46.         $this->twig->addGlobal('IS_PROD'$isProd);
  47.     }
  48. }