app/Plugin/TabaCustomFields2/EventListener/InitializeListener.php line 76

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\TabaCustomFields2\EventListener;
  9. use Plugin\TabaCustomFields2\Common\Constants;
  10. use Plugin\TabaCustomFields2\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.      */
  28.     public function __construct(ContainerInterface $container,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.         // Doctrineタイプを追加
  56.         if (!\Doctrine\DBAL\Types\Type::hasType(Constants::$CUSTOM_FIELD_TYPE['db_type_name'])) {
  57.             \Doctrine\DBAL\Types\Type::addType(Constants::$CUSTOM_FIELD_TYPE['db_type_name'], Constants::$CUSTOM_FIELD_TYPE['class_name']);
  58.             if ($this->container->get('doctrine.orm.entity_manager')->getConnection()->getDatabasePlatform()->hasDoctrineTypeMappingFor(Constants::$CUSTOM_FIELD_TYPE['doctrine_type_name'])) {
  59.                 $this->container->get('doctrine.orm.entity_manager')->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping(Constants::$CUSTOM_FIELD_TYPE['doctrine_type_name'], Constants::$CUSTOM_FIELD_TYPE['db_type_name']);
  60.             }
  61.         }
  62.     }
  63.     /**
  64.      * {@inheritDoc}
  65.      * @see \Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest()
  66.      */
  67.     public function onKernelRequest() {
  68.     }
  69. }