1
|
|
|
<?php namespace FlatPlan\Components; |
2
|
|
|
|
3
|
|
|
class Structure extends AbstractComponent { |
4
|
|
|
|
5
|
|
|
protected $components = array(); |
6
|
|
|
|
7
|
|
|
protected $roles = ['aside', 'chapter', 'container', 'divider', 'header', 'section', 'stack']; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @param string $role |
11
|
|
|
* @return void |
12
|
|
|
*/ |
13
|
|
|
public function __construct($role) |
14
|
|
|
{ |
15
|
|
|
$this->setRole($role); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function setComponents($components) |
19
|
|
|
{ |
20
|
|
|
if (is_array($components)) { |
21
|
|
|
foreach ($components as $component) { |
22
|
|
|
if ($component instanceof AbstractComponent && !is_null($component->getRole())) { |
23
|
|
|
$component->updateStyles($this->role); |
24
|
|
|
array_push($this->components, $component); |
25
|
|
|
} |
26
|
|
|
} |
27
|
|
|
} else if ($components instanceof AbstractComponent && !is_null($components->getRole())) { |
28
|
|
|
$components->updateStyles($this->role); |
29
|
|
|
array_push($this->components, $components); |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
private function getComponents() |
34
|
|
|
{ |
35
|
|
|
$componentList = array(); |
36
|
|
|
foreach ($this->components as $subComponent) { |
37
|
|
|
array_push($componentList, $subComponent->getComponent()); |
38
|
|
|
} |
39
|
|
|
return $componentList; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function getComponent() |
43
|
|
|
{ |
44
|
|
|
$component = new \stdClass(); |
45
|
|
|
if ($this->getIdentifier() !== null) { |
46
|
|
|
$component->identifier = $this->getIdentifier(); |
47
|
|
|
} |
48
|
|
|
$component->role = $this->getRole(); |
49
|
|
|
$components = $this->getComponents(); |
50
|
|
|
if (!empty($components)) { |
51
|
|
|
$component->components = $this->getComponents(); |
52
|
|
|
} |
53
|
|
|
$component->layout = $this->layout; |
54
|
|
|
$component->style = $this->style; |
55
|
|
|
if (!is_null($this->behaviour)) { |
56
|
|
|
$component->behaviour = $this->getBehaviour(); |
57
|
|
|
} |
58
|
|
|
return $component; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|