1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of EC-CUBE |
5
|
|
|
* |
6
|
|
|
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved. |
7
|
|
|
* |
8
|
|
|
* http://www.ec-cube.co.jp/ |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Eccube\Twig; |
15
|
|
|
|
16
|
|
|
use Eccube\Event\TemplateEvent; |
17
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
18
|
|
|
|
19
|
|
|
class Template extends \Twig\Template |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* {@inheritdoc} |
23
|
|
|
* |
24
|
|
|
* @throws \Twig\Error\LoaderError |
25
|
|
|
* @throws \Twig\Error\SyntaxError |
26
|
|
|
*/ |
27
|
|
|
public function display(array $context, array $blocks = []) |
28
|
|
|
{ |
29
|
|
|
$globals = $this->env->getGlobals(); |
30
|
|
|
if (isset($globals['event_dispatcher']) && strpos($this->getTemplateName(), '__string_template__') !== 0) { |
31
|
|
|
/** @var EventDispatcherInterface $eventDispatcher */ |
32
|
|
|
$eventDispatcher = $globals['event_dispatcher']; |
33
|
|
|
$originCode = $this->env->getLoader()->getSourceContext($this->getTemplateName())->getCode(); |
34
|
|
|
$event = new TemplateEvent($this->getTemplateName(), $originCode, $context); |
35
|
|
|
$eventDispatcher->dispatch($this->getTemplateName(), $event); |
36
|
|
|
if ($event->getSource() !== $originCode) { |
37
|
|
|
$newTemplate = $this->env->createTemplate($event->getSource()); |
38
|
|
|
$newTemplate->display($event->getParameters(), $blocks); |
39
|
|
|
} else { |
40
|
|
|
parent::display($event->getParameters(), $blocks); |
41
|
|
|
} |
42
|
|
|
} else { |
43
|
|
|
parent::display($context, $blocks); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function getTemplateName() |
48
|
|
|
{ |
49
|
|
|
// Templateのキャッシュ作成時に動的に作成されるメソッド |
50
|
|
|
// デバッグツールバーでエラーが発生するため空文字を返しておく。 |
51
|
|
|
// @see https://github.com/EC-CUBE/ec-cube/issues/4529 |
52
|
|
|
return ''; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function getDebugInfo() |
56
|
|
|
{ |
57
|
|
|
// Templateのキャッシュ作成時に動的に作成されるメソッド |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
protected function doDisplay(array $context, array $blocks = []) |
61
|
|
|
{ |
62
|
|
|
// Templateのキャッシュ作成時に動的に作成されるメソッド |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|