Completed
Push — master ( 7de731...d1e03a )
by Francesco
03:03
created

searchPatternAndHighlight()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 3
1
<?php
2
3
/*
4
 * This file is part of the MesHighlightBundle package.
5
 *
6
 * (c) Francesco Cartenì <http://www.multimediaexperiencestudio.it/>
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 Mes\Misc\HighlightBundle\Twig\Extension;
13
14
use Mes\Misc\HighlightBundle\HighlighterInterface;
15
16
/**
17
 * Class Highlight_RuntimeExtension.
18
 */
19
class HighlightRuntimeExtension extends \Twig_Extension
20
{
21
    /**
22
     * @var HighlighterInterface
23
     */
24
    private $highlighter;
25
26
    /**
27
     * Highlight_RuntimeExtension constructor.
28
     *
29
     * @param \Mes\Misc\HighlightBundle\HighlighterInterface $h
30
     */
31
    public function __construct(HighlighterInterface $h)
32
    {
33
        $this->highlighter = $h;
34
    }
35
36
    /**
37
     * @param $content
38
     * @param null $language
39
     * @param null $rootPath
40
     *
41
     * @return string
42
     */
43
    public function searchPatternAndHighlight($content, $language = null, $rootPath = null)
44
    {
45
        if (null !== $rootPath) {
46
            $this->highlighter->setRootPath($rootPath);
47
        }
48
49
        return $this->highlighter->searchPatternAndHighlight($content, $language);
50
    }
51
52
    /**
53
     * @param $content
54
     * @param null $language
55
     *
56
     * @return string
57
     */
58
    public function highlight($content, $language = null)
59
    {
60
        return $this->highlighter->highlight($content, $language);
61
    }
62
}
63