<?php
/*--------------------------------------------------- */
/* 共通変数を追加
/*--------------------------------------------------- */
namespace Customize\Controller;
use Eccube\Request\Context;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Twig\Environment;
class CommonEvent implements EventSubscriberInterface
{
/** @var Context */
protected $requestContext;
/** @var Environment */
protected $twig;
/**
* Event constructor.
*
* @param Context $requestContext
* @param Environment $twig
*/
public function __construct(
Context $requestContext,
Environment $twig
)
{
$this->requestContext = $requestContext;
$this->twig = $twig;
}
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
KernelEvents::REQUEST => ['onKernelRequest', 100000000]
];
}
/**
* @param GetResponseEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
{
// 管理画面は除外
if ($this->requestContext->isAdmin()) {
return;
}
// ⭐️ ここで共通変数設定
// $this->twig->addGlobal('test', 'testだよ');
}
}