app/Plugin/TabaFileManager/EventListener/InitializeListener.php line 69

Open in your IDE?
  1. <?php
  2. /*
  3.  * Copyright (C) SPREAD WORKS Inc. All Rights Reserved.
  4.  *
  5.  * For the full copyright and license information, please view the LICENSE
  6.  * file that was distributed with this source code.
  7.  */
  8. namespace Plugin\TabaFileManager\EventListener;
  9. use Plugin\TabaFileManager\Common\Constants;
  10. use Plugin\TabaFileManager\Common\UserConfig;
  11. use Symfony\Component\DependencyInjection\ContainerInterface;
  12. class InitializeListener
  13. {
  14.     /**
  15.      * @var ContainerInterface
  16.      */
  17.     private $container;
  18.     /**
  19.      * @var \Twig_Environment
  20.      */
  21.     private $twig;
  22.     /**
  23.      * コンストラクタ
  24.      *
  25.      * @param ContainerInterface $container
  26.      * @param \Twig_Environment $twig
  27.      */
  28.     public function __construct(ContainerInterface $container,\Twig_Environment $twig)
  29.     {
  30.         $this->container $container;
  31.         $this->twig $twig;
  32.         // 設定ファイルの読み込み
  33.         UserConfig::getInstance()->load($this->container->getParameter('kernel.project_dir') . Constants::PLUGIN_DATA_DIR DIRECTORY_SEPARATOR Constants::USER_CONFIG_FILE);
  34.         $this->twig->addGlobal(Constants::PLUGIN_CODE.'UserConfig'UserConfig::getInstance());
  35.         // Twigグローバル変数セット
  36.         $this->twig->addGlobal(Constants::PLUGIN_CODE.'Constants', new Constants());
  37.         // コンテナにプラグイン間で共有するデータホルダーを登録します。
  38.         if (!$this->container->has(Constants::CONTAINER_KEY_NAME)) {
  39.             $this->container->set(
  40.                 Constants::CONTAINER_KEY_NAME,
  41.                 new class {
  42.                     private $data;
  43.                     public function set($key$val)
  44.                     {
  45.                         $this->data[$key] = $val;
  46.                     }
  47.                     public function get($key)
  48.                     {
  49.                         if (isset($this->data[$key])) return $this->data[$key];
  50.                         return null;
  51.                     }
  52.                 }
  53.             );
  54.         }
  55.     }
  56.     /**
  57.      * {@inheritDoc}
  58.      * @see \Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest()
  59.      */
  60.     public function onKernelRequest() {
  61.     }
  62. }