Completed
Push — return-of-the-e2e ( 1da670 )
by Kiyotaka
04:24
created

Template::display()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 3
nop 2
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
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