1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dgame\Soap; |
4
|
|
|
|
5
|
|
|
use Dgame\Soap\Hydrator\VisitorInterface; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class XmlNode |
9
|
|
|
* @package Dgame\Soap |
10
|
|
|
*/ |
11
|
|
|
class XmlNode extends XmlElement |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var XmlElement[] |
15
|
|
|
*/ |
16
|
|
|
private $elements = []; |
17
|
|
|
/** |
18
|
|
|
* @var bool |
19
|
|
|
*/ |
20
|
|
|
private $childPrefixInheritance = false; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param string $prefix |
24
|
|
|
*/ |
25
|
12 |
|
public function setPrefix(string $prefix) |
26
|
|
|
{ |
27
|
12 |
|
parent::setPrefix($prefix); |
28
|
|
|
|
29
|
12 |
|
foreach ($this->elements as $element) { |
30
|
4 |
|
$this->syncPrefix($element); |
31
|
|
|
} |
32
|
12 |
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param XmlElement $element |
36
|
|
|
*/ |
37
|
12 |
|
public function appendElement(XmlElement $element) |
38
|
|
|
{ |
39
|
12 |
|
$this->elements[] = $element; |
40
|
12 |
|
$this->syncPrefix($element); |
41
|
12 |
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param XmlElement $element |
45
|
|
|
*/ |
46
|
12 |
|
private function syncPrefix(XmlElement $element) |
47
|
|
|
{ |
48
|
12 |
|
if (!$element->hasPrefix() && $this->hasPrefix()) { |
49
|
6 |
|
$element->setPrefix($this->getPrefix()); |
50
|
|
|
} |
51
|
12 |
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return XmlElement[]|XmlNode[] |
55
|
|
|
*/ |
56
|
12 |
|
public function getElements(): array |
57
|
|
|
{ |
58
|
12 |
|
return $this->elements; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return bool |
63
|
|
|
*/ |
64
|
2 |
|
public function hasElements(): bool |
65
|
|
|
{ |
66
|
2 |
|
return !empty($this->elements); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param VisitorInterface $visitor |
71
|
|
|
*/ |
72
|
10 |
|
public function accept(VisitorInterface $visitor) |
73
|
|
|
{ |
74
|
10 |
|
$visitor->visitXmlNode($this); |
75
|
10 |
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return bool |
79
|
|
|
*/ |
80
|
|
|
final public function isChildPrefixInheritanceEnabled(): bool |
81
|
|
|
{ |
82
|
|
|
return $this->childPrefixInheritance; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* |
87
|
|
|
*/ |
88
|
|
|
final public function enableChildPrefixInheritance() |
89
|
|
|
{ |
90
|
|
|
$this->childPrefixInheritance = true; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* |
95
|
|
|
*/ |
96
|
|
|
final public function disableChildPrefixInheritance() |
97
|
|
|
{ |
98
|
|
|
$this->childPrefixInheritance = false; |
99
|
|
|
} |
100
|
|
|
} |