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 Symfony\Component\EventDispatcher\EventDispatcherInterface; |
17
|
|
|
use Eccube\Event\TemplateEvent; |
18
|
|
|
|
19
|
|
|
abstract class Template extends \Twig\Template |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* {@inheritDoc} |
23
|
|
|
* |
24
|
|
|
* @param array $context |
25
|
|
|
* @param array $blocks |
26
|
|
|
* @throws \Twig\Error\LoaderError |
27
|
|
|
* @throws \Twig\Error\SyntaxError |
28
|
|
|
*/ |
29
|
|
|
public function display(array $context, array $blocks = []) |
30
|
|
|
{ |
31
|
|
|
$globals = $this->env->getGlobals(); |
32
|
|
|
if (isset($globals['event_dispatcher']) && strpos($this->getTemplateName(), '__string_template__') !== 0) { |
33
|
|
|
/** @var EventDispatcherInterface $eventDispatcher */ |
34
|
|
|
$eventDispatcher = $globals['event_dispatcher']; |
35
|
|
|
$event = new TemplateEvent($this->getTemplateName(), $this->getSourceContext()->getCode(), $context); |
36
|
|
|
$eventDispatcher->dispatch($this->getTemplateName(), $event); |
37
|
|
|
if ($event->getSource() !== $this->getSourceContext()->getCode()) { |
38
|
|
|
$newTemplate = $this->env->createTemplate($event->getSource()); |
39
|
|
|
$newTemplate->display($event->getParameters(), $blocks); |
40
|
|
|
} else { |
41
|
|
|
parent::display($event->getParameters(), $blocks); |
42
|
|
|
} |
43
|
|
|
} else { |
44
|
|
|
parent::display($context, $blocks); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|