Completed
Push — master ( dfe684...c4d587 )
by WEBEWEB
06:45
created

RendererTwigExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 50
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A coreScriptFilter() 0 13 2
A getFilters() 0 5 1
1
<?php
2
3
/**
4
 * This file is part of the core-bundle package.
5
 *
6
 * (c) 2018 WEBEWEB
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 WBW\Bundle\CoreBundle\Twig\Extension;
13
14
use Twig_Environment;
15
use Twig_SimpleFilter;
16
17
/**
18
 * Renderer Twig extension.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Bundle\CoreBundle\Twig\Extension
22
 */
23
class RendererTwigExtension extends AbstractTwigExtension {
24
25
    /**
26
     * Service name.
27
     *
28
     * @var string
29
     */
30
    const SERVICE_NAME = "webeweb.core.twig.extension.renderer";
31
32
    /**
33
     * Constructor.
34
     *
35
     * @param Twig_Environment $twigEnvironment The twig environment.
36
     */
37
    public function __construct(Twig_Environment $twigEnvironment) {
38
        parent::__construct($twigEnvironment);
39
    }
40
41
    /**
42
     * Displays a script.
43
     *
44
     * @param string $content The content.
45
     * @return string Returns a script.
46
     */
47
    public function coreScriptFilter($content) {
48
49
        // Initialize the attributes.
50
        $attributes = [];
51
52
        $attributes["type"] = "text/javascript";
53
54
        // Initialize the parameters.
55
        $innerHTML = null !== $content ? "\n" . $content . "\n" : "";
56
57
        // Return the HTML.
58
        return static::coreHTMLElement("script", $innerHTML, $attributes);
59
    }
60
61
    /**
62
     * Get the Twig filters.
63
     *
64
     * @return Twig_SimpleFilter[] Returns the Twig filters.
65
     */
66
    public function getFilters() {
67
        return [
68
            new Twig_SimpleFilter("coreScript", [$this, "coreScriptFilter"], ["is_safe" => ["html"]]),
69
        ];
70
    }
71
72
}
73