1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dgame\Soap\Hydrator\Dom; |
4
|
|
|
|
5
|
|
|
use Dgame\Soap\Attribute\Attribute; |
6
|
|
|
use Dgame\Soap\Attribute\XmlAttribute; |
7
|
|
|
use Dgame\Soap\Element; |
8
|
|
|
use Dgame\Soap\Hydrator\VisitorInterface; |
9
|
|
|
use Dgame\Soap\XmlElement; |
10
|
|
|
use Dgame\Soap\XmlNode; |
11
|
|
|
use DOMDocument; |
12
|
|
|
use DOMElement; |
13
|
|
|
use DOMNode; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class Assembler |
17
|
|
|
* @package Dgame\Soap\Hydrator\Dom |
18
|
|
|
*/ |
19
|
|
|
final class Assembler implements VisitorInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var DOMDocument |
23
|
|
|
*/ |
24
|
|
|
private $document; |
25
|
|
|
/** |
26
|
|
|
* @var DOMElement |
27
|
|
|
*/ |
28
|
|
|
private $node; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Assembler constructor. |
32
|
|
|
* |
33
|
|
|
* @param DOMNode|null $node |
34
|
|
|
*/ |
35
|
5 |
|
public function __construct(DOMNode $node = null) |
36
|
|
|
{ |
37
|
5 |
|
if ($node === null) { |
38
|
4 |
|
$this->node = $this->document = new DOMDocument('1.0', 'utf-8'); |
|
|
|
|
39
|
|
|
} else { |
40
|
5 |
|
$this->node = $node; |
|
|
|
|
41
|
5 |
|
$this->document = $node->ownerDocument ?? $this->node; |
|
|
|
|
42
|
|
|
} |
43
|
5 |
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return DOMDocument |
47
|
|
|
*/ |
48
|
4 |
|
public function getDocument(): DOMDocument |
49
|
|
|
{ |
50
|
4 |
|
return $this->document; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param Element $element |
55
|
|
|
* @param DOMNode $node |
56
|
|
|
* |
57
|
|
|
* @return DOMNode |
58
|
|
|
*/ |
59
|
5 |
|
private function assemble(Element $element, DOMNode $node): DOMNode |
60
|
|
|
{ |
61
|
5 |
|
$this->node->appendChild($node); |
62
|
5 |
|
$this->node = $node; |
|
|
|
|
63
|
|
|
|
64
|
5 |
|
foreach ($element->getAttributes() as $attribute) { |
65
|
5 |
|
$attribute->accept($this); |
66
|
|
|
} |
67
|
|
|
|
68
|
5 |
|
return $node; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param Element $element |
73
|
|
|
*/ |
74
|
|
|
public function visitElement(Element $element) |
75
|
|
|
{ |
76
|
|
|
$node = $this->document->createElement($element->getName(), $element->hasValue() ? $element->getValue() : null); |
77
|
|
|
$this->assemble($element, $node); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param XmlElement $element |
82
|
|
|
*/ |
83
|
5 |
|
public function visitXmlElement(XmlElement $element) |
84
|
|
|
{ |
85
|
5 |
|
$node = $this->document->createElement($element->getPrefixedName(), $element->hasValue() ? $element->getValue() : null); |
86
|
5 |
|
$node = $this->assemble($element, $node); |
87
|
5 |
|
if ($element->hasPrefix()) { |
88
|
4 |
|
$node->prefix = $element->getPrefix(); |
89
|
|
|
} |
90
|
5 |
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param XmlNode $node |
94
|
|
|
*/ |
95
|
5 |
|
public function visitXmlNode(XmlNode $node) |
96
|
|
|
{ |
97
|
5 |
|
$this->visitXmlElement($node); |
98
|
|
|
|
99
|
5 |
|
foreach ($node->getElements() as $child) { |
100
|
5 |
|
$assembler = new self($this->node); |
101
|
5 |
|
$child->accept($assembler); |
102
|
|
|
} |
103
|
5 |
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param Attribute $attribute |
107
|
|
|
*/ |
108
|
1 |
|
public function visitAttribute(Attribute $attribute) |
109
|
|
|
{ |
110
|
1 |
|
$this->node->setAttribute($attribute->getName(), $attribute->hasValue() ? $attribute->getValue() : null); |
111
|
1 |
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param XmlAttribute $attribute |
115
|
|
|
*/ |
116
|
4 |
|
public function visitXmlAttribute(XmlAttribute $attribute) |
117
|
|
|
{ |
118
|
4 |
|
$this->node->setAttribute($attribute->getPrefixedName(), $attribute->hasValue() ? $attribute->getValue() : null); |
119
|
|
|
} |
120
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..