Completed
Pull Request — master (#471)
by Leny
07:09
created

SvgTwigExtension::includeSvg()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Victoire\Bundle\MediaBundle\Twig;
4
5
use Victoire\Bundle\MediaBundle\Helper\Menu\MenuBuilder;
6
7
/**
8
 * MenuTwigExtension.
9
 */
10
class SvgTwigExtension extends \Twig_Extension
11
{
12
    protected $kernelRootDir;
13
14
    /**
15
     * SvgTwigExtension constructor.
16
     *
17
     * @param $kernelRootDir
18
     */
19
    public function __construct($kernelRootDir)
20
    {
21
        $this->kernelRootDir = $kernelRootDir;
22
    }
23
24
    public function getFunctions()
25
    {
26
        return [
27
            new \Twig_SimpleFunction('include_svg', array($this, 'includeSvg'), ['is_safe' => ['html']]),
28
        ];
29
    }
30
31
    public function includeSvg($url)
32
    {
33
        return file_get_contents($this->kernelRootDir.'/../web'.$url);
34
    }
35
36
    public function getName()
37
    {
38
        return 'victoire_media_svg_extension';
39
    }
40
}
41