Completed
Push — master ( 3b9aa0...812432 )
by Anton
03:38
created

ExtendLayout   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 67
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2

4 Methods

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