Completed
Push — master ( 77ab2d...0ed20a )
by Nikola
02:44
created

TwigExtension::getNodeVisitors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
/*
3
 * This file is part of the Twig Bufferized Template package, an RunOpenCode project.
4
 *
5
 * (c) 2017 RunOpenCode
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace RunOpenCode\Twig\BufferizedTemplate;
11
12
use RunOpenCode\Twig\BufferizedTemplate\Exception\InvalidArgumentException;
13
use RunOpenCode\Twig\BufferizedTemplate\Tag\Bufferize\TokenParser;
14
15
/**
16
 * Class TwigExtension
17
 *
18
 * @package RunOpenCode\Twig\BufferizedTemplate
19
 */
20
class TwigExtension extends \Twig_Extension
21
{
22
    /**
23
     * @var array
24
     */
25
    private $settings;
26
27 5
    public function __construct(array $settings = array())
28
    {
29 5
        $this->settings = array_merge(array(
30 5
            'nodes' => [],
31
            'whitelist' => [],
32
            'blacklist' => [],
33
            'default_execution_priority' => 0,
34
            'node_visitor_priority' => 10
35
        ), $settings);
36
37 5
        $this->settings['nodes']['RunOpenCode\\Twig\\BufferizedTemplate\\Tag\\Bufferize\\Node'] = $this->settings['default_execution_priority'];
38
39 5
        if (count($this->settings['blacklist']) > 0 && count($this->settings['whitelist'])) {
40 1
            throw new InvalidArgumentException('You can use either black list or white list setting or non for bufferizing templates, but not both.');
41
        }
42 4
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 3
    public function getNodeVisitors()
48
    {
49
        return [
50 3
            new NodeVisitor($this->settings)
51
        ];
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57 3
    public function getTokenParsers()
58
    {
59
        return [
60 3
            new TokenParser()
61
        ];
62
    }
63
}
64