Completed
Push — master ( ebbaf0...77ab2d )
by Nikola
04:22
created

Extension::createBuffer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace RunOpenCode\Twig\BufferizedTemplate;
4
5
use RunOpenCode\Twig\BufferizedTemplate\Tag\Bufferize\TokenParser;
6
7
class Extension extends \Twig_Extension
8
{
9
    /**
10
     * @var array
11
     */
12
    private $settings;
13
14 2
    public function __construct(array $settings = array())
15
    {
16 2
        $this->settings = array_merge(array(
17 2
            'enabled' => true,
18
            'nodes' => [],
19
            'whitelist' => [],
20
            'blacklist' => [],
21
            'default_execution_priority' => 0,
22
            'node_visitor_priority' => 10
23
        ), $settings);
24
25 2
        $this->settings['nodes']['RunOpenCode\\Twig\\BufferizedTemplate\\Tag\\Bufferize\\Node'] = $this->settings['default_execution_priority'];
26
27 2
        if (count($this->settings['blacklist']) > 0 && count($this->settings['whitelist'])) {
28
            throw new \InvalidArgumentException('You can use either black list or white list setting or non for bufferizing templates, but not both.');
29
        }
30 2
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 2
    public function getNodeVisitors()
36
    {
37 2
        return $this->settings['enabled'] ? [ new NodeVisitor($this->settings) ] : [];
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 2
    public function getTokenParsers()
44
    {
45
        return [
46 2
            new TokenParser()
47
        ];
48
    }
49
}
50