Completed
Push — master ( a923e4...fe6df8 )
by Craig
05:56
created

TwigExtension::safeHtml()   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 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Zikula package.
5
 *
6
 * Copyright Zikula Foundation - http://zikula.org/
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 Zikula\SecurityCenterModule\Twig;
13
14
use Zikula\SecurityCenterModule\Api\ApiInterface\HtmlFilterApiInterface;
15
16
/**
17
 * Twig extension class.
18
 */
19
class TwigExtension extends \Twig_Extension
20
{
21
    /**
22
     * @var HtmlFilterApiInterface
23
     */
24
    private $htmlFilterApi;
25
26
    /**
27
     * TwigExtension constructor.
28
     *
29
     * @param HtmlFilterApiInterface $htmlFilterApi
30
     */
31
    public function __construct(HtmlFilterApiInterface $htmlFilterApi)
32
    {
33
        $this->htmlFilterApi = $htmlFilterApi;
34
    }
35
36
    public function getFilters()
37
    {
38
        return [
39
            new \Twig_SimpleFilter('safeHtml', [$this, 'safeHtml'], ['is_safe' => ['html']])
40
        ];
41
    }
42
43
    /**
44
     * @param $string
45
     * @return string
46
     */
47
    public function safeHtml($string)
48
    {
49
        return $this->htmlFilterApi->filter($string);
50
    }
51
}
52