src/Eccube/Twig/Environment.php line 54

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Eccube\Twig;
  13. use Eccube\Event\TemplateEvent;
  14. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  15. class Environment extends \Twig_Environment
  16. {
  17.     /**
  18.      * @var \Twig_Environment
  19.      */
  20.     protected $twig;
  21.     /**
  22.      * @var EventDispatcherInterface
  23.      */
  24.     protected $eventDispatcher;
  25.     public function __construct(\Twig_Environment $twigEventDispatcherInterface $eventDispatcher)
  26.     {
  27.         $this->twig $twig;
  28.         $this->eventDispatcher $eventDispatcher;
  29.     }
  30.     public function render($name, array $context = [])
  31.     {
  32.         // twigファイルのソースコードを読み込み文字列化する.
  33.         $source $this->twig->getLoader()
  34.             ->getSourceContext($name)
  35.             ->getCode();
  36.         // プラグインにはテンプレートファイル名, 文字列化されたtwigファイル, パラメータを渡す.
  37.         $event = new TemplateEvent($name$source$context);
  38.         // テンプレートフックポイントの実行.
  39.         $this->eventDispatcher->dispatch($name$event);
  40.         // プラグインで変更された文字列から, テンプレートオブジェクトを生成.
  41.         $template $this->twig->createTemplate($event->getSource());
  42.         // レンダリング実行.
  43.         $content $template->render($event->getParameters());
  44.         return $content;
  45.     }
  46. }