Completed
Push — master ( 69416a...547cab )
by Nikola
03:28
created

Extension::getName()   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 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
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' => array(),
19
            'whitelist' => array(),
20
            'blacklist' => array(),
21
            'bufferManager' => 'RunOpenCode\\Twig\\BufferizedTemplate\\Buffer\\BufferManager',
22
            'defaultExecutionPriority' => 0,
23
            'nodeVisitorPriority' => 10
24
        ), $settings);
25
26 2
        $this->settings['nodes']['RunOpenCode\\Twig\\BufferizedTemplate\\Tag\\Bufferize\\Node'] = $this->settings['defaultExecutionPriority'];
27
28 2
        if (count($this->settings['blacklist']) > 0 && count($this->settings['whitelist'])) {
29
            throw new \InvalidArgumentException('You can use either black list or white list setting or non for bufferizing templates, but not both.');
30
        }
31 2
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 2
    public function getNodeVisitors()
37
    {
38 2
        if ($this->settings['enabled']) {
39
40
            return array(
41 2
                new NodeVisitor($this->settings)
42
            );
43
        } else {
44
            return array();
45
        }
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 2
    public function getTokenParsers()
52
    {
53
        return array(
54 2
            new TokenParser()
55
        );
56
    }
57
58 2
    public function createBuffer()
59
    {
60 2
        return new $this->settings['bufferManager']();
61
    }
62
}
63