src/Eccube/Twig/Template.php line 28

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. use Twig\Source;
  16. class Template extends \Twig\Template
  17. {
  18. /**
  19. * {@inheritdoc}
  20. *
  21. * @throws \Twig\Error\LoaderError
  22. * @throws \Twig\Error\SyntaxError
  23. */
  24. public function display(array $context, array $blocks = [])
  25. {
  26. $globals = $this->env->getGlobals();
  27. if (isset($globals['event_dispatcher']) && strpos($this->getTemplateName(), '__string_template__') !== 0) {
  28. /** @var EventDispatcherInterface $eventDispatcher */
  29. $eventDispatcher = $globals['event_dispatcher'];
  30. $originCode = $this->env->getLoader()->getSourceContext($this->getTemplateName())->getCode();
  31. $event = new TemplateEvent($this->getTemplateName(), $originCode, $context);
  32. $eventDispatcher->dispatch($event, $this->getTemplateName());
  33. if ($event->getSource() !== $originCode) {
  34. $newTemplate = $this->env->createTemplate($event->getSource());
  35. $newTemplate->display($event->getParameters(), $blocks);
  36. } else {
  37. parent::display($event->getParameters(), $blocks);
  38. }
  39. } else {
  40. parent::display($context, $blocks);
  41. }
  42. }
  43. public function getTemplateName()
  44. {
  45. // Templateのキャッシュ作成時に動的に作成されるメソッド
  46. // デバッグツールバーでエラーが発生するため空文字を返しておく。
  47. // @see https://github.com/EC-CUBE/ec-cube/issues/4529
  48. return '';
  49. }
  50. public function getDebugInfo()
  51. {
  52. // Templateのキャッシュ作成時に動的に作成されるメソッド
  53. return [];
  54. }
  55. protected function doDisplay(array $context, array $blocks = [])
  56. {
  57. // Templateのキャッシュ作成時に動的に作成されるメソッド
  58. }
  59. public function getSourceContext()
  60. {
  61. // FIXME Twig\Loader\FilesystemLoader の実装を持ってきたが,これで問題ないか要確認
  62. return new Source('', $this->getTemplateName(), '');
  63. }
  64. }