BreadcrumbsExtension::renderBreadcrumbs()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 3
1
<?php
2
3
/*
4
 * This file is part of the BreadcrumbsBundle.
5
 *
6
 * (c) Yonel Ceruto <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Yceruto\Bundle\BreadcrumbsBundle\Twig;
13
14
use Yceruto\Bundle\BreadcrumbsBundle\Breadcrumbs;
15
use Yceruto\Bundle\BreadcrumbsBundle\BreadcrumbsBuilder;
16
17
class BreadcrumbsExtension extends \Twig_Extension
18
{
19
    /**
20
     * @var BreadcrumbsBuilder
21
     */
22
    private $breadcrumbsBuilder;
23
24
    public function __construct(BreadcrumbsBuilder $breadcrumbsBuilder)
25
    {
26
        $this->breadcrumbsBuilder = $breadcrumbsBuilder;
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function getFunctions()
33
    {
34
        return array(
35
            new \Twig_SimpleFunction('render_breadcrumbs', array($this, 'renderBreadcrumbs'), array('is_safe' => array('html'), 'needs_environment' => true)),
36
        );
37
    }
38
39
    public function renderBreadcrumbs(\Twig_Environment $twig, Breadcrumbs $breadcrumbs = null, $template = '@Breadcrumbs/breadcrumbs.html.twig')
40
    {
41
        if (null === $breadcrumbs) {
42
            $breadcrumbs = $this->breadcrumbsBuilder->createFromRequest();
43
        }
44
45
        return $twig->render($template, array('breadcrumbs' => $breadcrumbs));
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function getName()
52
    {
53
        return 'breadcrumbs_extension';
54
    }
55
}
56