app/Plugin/TabaCustomFields/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\TabaCustomFields\EventListener;
  9. use Plugin\TabaCustomFields\Common\Constants;
  10. use Plugin\TabaCustomFields\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.      */
  27.     public function __construct(ContainerInterface $container,\Twig_Environment $twig)
  28.     {
  29.         $this->container $container;
  30.         $this->twig $twig;
  31.         // 設定ファイルの読み込み
  32.         UserConfig::getInstance()->load($this->container->getParameter('kernel.project_dir') . Constants::PLUGIN_DATA_DIR DIRECTORY_SEPARATOR Constants::USER_CONFIG_FILE);
  33.         $this->twig->addGlobal(Constants::PLUGIN_CODE.'UserConfig'UserConfig::getInstance());
  34.         // Twigグローバル変数セット
  35.         $this->twig->addGlobal(Constants::PLUGIN_CODE.'Constants', new Constants());
  36.         // コンテナにプラグイン間で共有するデータホルダーを登録します。
  37.         if (!$this->container->has(Constants::CONTAINER_KEY_NAME)) {
  38.             $this->container->set(
  39.                 Constants::CONTAINER_KEY_NAME,
  40.                 new class {
  41.                     private $data;
  42.                     public function set($key$val)
  43.                     {
  44.                         $this->data[$key] = $val;
  45.                     }
  46.                     public function get($key)
  47.                     {
  48.                         if (isset($this->data[$key])) return $this->data[$key];
  49.                         return null;
  50.                     }
  51.                 }
  52.             );
  53.         }
  54.         // Doctrineタイプを追加
  55.         if (!\Doctrine\DBAL\Types\Type::hasType(Constants::$CUSTOM_FIELD_TYPE['db_type_name'])) {
  56.             \Doctrine\DBAL\Types\Type::addType(Constants::$CUSTOM_FIELD_TYPE['db_type_name'], Constants::$CUSTOM_FIELD_TYPE['class_name']);
  57.             if ($this->container->get('doctrine.orm.entity_manager')->getConnection()->getDatabasePlatform()->hasDoctrineTypeMappingFor(Constants::$CUSTOM_FIELD_TYPE['doctrine_type_name'])) {
  58.                 $this->container->get('doctrine.orm.entity_manager')->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping(Constants::$CUSTOM_FIELD_TYPE['doctrine_type_name'], Constants::$CUSTOM_FIELD_TYPE['db_type_name']);
  59.             }
  60.         }
  61.     }
  62.     /**
  63.      * {@inheritDoc}
  64.      * @see \Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest()
  65.      */
  66.     public function onKernelRequest() {
  67.     }
  68. }