Completed
Push — experimental/sf ( 0de2cd...dd9b91 )
by
unknown
62:10
created

TwigIncludeExtension::getFunctions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.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\Extension;
15
16
use Twig\Extension\AbstractExtension;
17
18
class TwigIncludeExtension extends AbstractExtension
19
{
20
    protected $twig;
21
22
    public function __construct(\Eccube\Twig\Environment $twig)
23
    {
24
        $this->twig = $twig;
25
    }
26
27
    public function getFunctions()
28
    {
29
        return [
30
            new \Twig_Function('include_dispatch', [$this, 'include_dispatch'],
31
                array('needs_context' => true, 'is_safe' => array('all'))),
32
        ];
33
    }
34
35
    public function include_dispatch($context, $template, $variables = [])
36
    {
37
        if (!empty($variables)) {
38
            $context = array_merge($context, $variables);
39
        }
40
41
        return $this->twig->render($template, $context);
42
    }
43
}
44