Passed
Pull Request — master (#13)
by
unknown
02:26
created

NestedNavigationExtension::getFunctions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Everlution\NavigationBundle\Twig;
6
7
use Twig\Environment;
8
9
/**
10
 * Class NestedNavigationExtension.
11
 *
12
 * @author Martin Lutter <[email protected]>
13
 */
14
class NestedNavigationExtension extends \Twig_Extension
15
{
16
    /** @var ItemHelper */
17
    private $helper;
18
    /** @var NestedNavigationHelper */
19
    private $navigationHelper;
20
21
    public function __construct(ItemHelper $helper, NestedNavigationHelper $navigationHelper)
22
    {
23
        $this->helper = $helper;
24
        $this->navigationHelper = $navigationHelper;
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function renderAdvancedNavigation(
31
        Environment $environment,
32
        string $identifier,
33
        string $template
34
    ): string {
35
        return $environment->render(
36
            $template,
37
            [
38
                'root' => $this->navigationHelper->getNavigation($identifier)->getCurrent(),
39
                'identifier' => $identifier,
40
                'helper' => $this->helper,
41
                'navigation_helper' => $this->navigationHelper,
42
            ]
43
        );
44
    }
45
46
    public function getFunctions()
47
    {
48
        return [
49
            new \Twig_SimpleFunction(
50
                'render_advanced_navigation',
51
                [$this, 'renderAdvancedNavigation'],
52
                ['needs_environment' => true, 'is_safe' => ['html']]
53
            ),
54
        ];
55
    }
56
}
57