Passed
Pull Request — master (#12)
by
unknown
03:27
created

NestedNavigationExtension::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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