app/Plugin/TabaHtmlEditor2/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\TabaHtmlEditor2\EventListener;
  9. use Plugin\TabaHtmlEditor2\Common\Constants;
  10. use Plugin\TabaHtmlEditor2\Common\UserConfig;
  11. use Symfony\Component\DependencyInjection\ContainerInterface;
  12. use Twig\Environment;
  13. class InitializeListener
  14. {
  15.     /**
  16.      * @var ContainerInterface
  17.      */
  18.     private $container;
  19.     /**
  20.      * @var Environment
  21.      */
  22.     private $twig;
  23.     /**
  24.      * コンストラクタ
  25.      *
  26.      * @param ContainerInterface $container
  27.      * @param Environment $twig
  28.      */
  29.     public function __construct(ContainerInterface $container,Environment $twig)
  30.     {
  31.         $this->container $container;
  32.         $this->twig $twig;
  33.         // 設定ファイルの読み込み
  34.         UserConfig::getInstance()->load($this->container->getParameter('kernel.project_dir') . Constants::PLUGIN_DATA_DIR DIRECTORY_SEPARATOR Constants::USER_CONFIG_FILE);
  35.         $this->twig->addGlobal(Constants::PLUGIN_CODE.'UserConfig'UserConfig::getInstance());
  36.         // Twigグローバル変数セット
  37.         $this->twig->addGlobal(Constants::PLUGIN_CODE.'Constants', new Constants());
  38.         // コンテナにプラグイン間で共有するデータホルダーを登録します。
  39.         if (!$this->container->has(Constants::CONTAINER_KEY_NAME)) {
  40.             $this->container->set(
  41.                 Constants::CONTAINER_KEY_NAME,
  42.                 new class {
  43.                     private $data;
  44.                     public function set($key$val)
  45.                     {
  46.                         $this->data[$key] = $val;
  47.                     }
  48.                     public function get($key)
  49.                     {
  50.                         if (isset($this->data[$key])) return $this->data[$key];
  51.                         return null;
  52.                     }
  53.                 }
  54.             );
  55.         }
  56.     }
  57.     /**
  58.      * {@inheritDoc}
  59.      * @see \Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest()
  60.      */
  61.     public function onKernelRequest() {
  62.     }
  63. }