Completed
Branch dbal-improvement (06db1a)
by Anton
03:59
created

ExtendsBehaviour::extendedNode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
namespace Spiral\Stempler\Behaviours;
9
10
use Spiral\Stempler\BehaviourInterface;
11
use Spiral\Stempler\HtmlTokenizer;
12
use Spiral\Stempler\ImporterInterface;
13
use Spiral\Stempler\Node;
14
use Spiral\Stempler\Supervisor;
15
16
/**
17
 * Points node to it's parent.
18
 */
19
class ExtendsBehaviour implements BehaviourInterface
20
{
21
    /**
22
     * Parent (extended) node, treat it as page or element layout.
23
     *
24
     * @var Node
25
     */
26
    private $parent = null;
27
28
    /**
29
     * Attributes defined using extends tag.
30
     *
31
     * @var array
32
     */
33
    private $attributes = [];
34
35
    /**
36
     * @var array
37
     */
38
    private $token = [];
39
40
    /**
41
     * @param Node  $parent
42
     * @param array $token
43
     */
44
    public function __construct(Node $parent, array $token)
45
    {
46
        $this->parent = $parent;
47
        $this->token = $token;
48
        $this->attributes = $token[HtmlTokenizer::TOKEN_ATTRIBUTES];
49
    }
50
51
    /**
52
     * Node which are getting extended.
53
     *
54
     * @return Node
55
     */
56
    public function extendedNode()
57
    {
58
        return $this->parent;
59
    }
60
61
    /**
62
     * Every import defined in parent (extended node).
63
     *
64
     * @return ImporterInterface[]
65
     */
66
    public function parentImports()
67
    {
68
        $supervisor = $this->parent->supervisor();
69
        if (!$supervisor instanceof Supervisor) {
70
            return [];
71
        }
72
73
        return $supervisor->getImporters();
74
    }
75
76
    /**
77
     * Set of blocks defined at moment of extend definition.
78
     *
79
     * @return array
80
     */
81
    public function dynamicBlocks()
82
    {
83
        return $this->attributes;
84
    }
85
}