|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace WsdlToPhp\DomHandler; |
|
4
|
|
|
|
|
5
|
|
|
abstract class AbstractElementHandler extends AbstractNodeHandler |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* @param \DOMElement $element |
|
9
|
|
|
* @param AbstractDomDocumentHandler $domDocument |
|
10
|
|
|
* @param int $index |
|
11
|
|
|
*/ |
|
12
|
148 |
|
public function __construct(\DOMElement $element, AbstractDomDocumentHandler $domDocument, $index = -1) |
|
13
|
|
|
{ |
|
14
|
148 |
|
parent::__construct($element, $domDocument, $index); |
|
15
|
148 |
|
} |
|
16
|
|
|
/** |
|
17
|
|
|
* @see \WsdlToPhp\DomHandler\AbstractNodeHandler::getNode() |
|
18
|
|
|
* @return \DOMElement |
|
19
|
|
|
*/ |
|
20
|
144 |
|
public function getNode() |
|
21
|
|
|
{ |
|
22
|
144 |
|
return parent::getNode(); |
|
23
|
|
|
} |
|
24
|
|
|
/** |
|
25
|
|
|
* Alias to getNode() |
|
26
|
|
|
* @return \DOMElement |
|
27
|
|
|
*/ |
|
28
|
116 |
|
public function getElement() |
|
29
|
|
|
{ |
|
30
|
116 |
|
return $this->getNode(); |
|
31
|
|
|
} |
|
32
|
|
|
/** |
|
33
|
|
|
* @param string $name |
|
34
|
|
|
* @return boolean |
|
35
|
|
|
*/ |
|
36
|
112 |
|
public function hasAttribute($name) |
|
37
|
|
|
{ |
|
38
|
112 |
|
return $this->getElement()->hasAttribute($name); |
|
39
|
|
|
} |
|
40
|
|
|
/** |
|
41
|
|
|
* @param string $name |
|
42
|
|
|
* @return AttributeHandler|null |
|
43
|
|
|
*/ |
|
44
|
108 |
|
public function getAttribute($name) |
|
45
|
|
|
{ |
|
46
|
108 |
|
return $this->hasAttribute($name) ? $this->getDomDocumentHandler()->getHandler($this->getNode()->getAttributeNode($name)) : null; |
|
47
|
|
|
} |
|
48
|
|
|
/** |
|
49
|
|
|
* @param string $name |
|
50
|
|
|
* @return mixed |
|
51
|
|
|
*/ |
|
52
|
84 |
|
public function getAttributeValue($name, $withNamespace = false, $withinItsType = true, $asType = AbstractAttributeHandler::DEFAULT_VALUE_TYPE) |
|
53
|
3 |
|
{ |
|
54
|
84 |
|
$value = null; |
|
55
|
84 |
|
$attribute = $this->getAttribute($name); |
|
56
|
84 |
|
if ($attribute instanceof AbstractAttributeHandler) { |
|
57
|
72 |
|
$value = $attribute->getValue($withNamespace, $withinItsType, $asType); |
|
58
|
54 |
|
} |
|
59
|
84 |
|
return $value; |
|
60
|
|
|
} |
|
61
|
|
|
/** |
|
62
|
|
|
* @param string $name |
|
63
|
|
|
* @return NodeHandler[]|ElementHandler[] |
|
64
|
|
|
*/ |
|
65
|
8 |
|
public function getChildrenByName($name) |
|
66
|
|
|
{ |
|
67
|
8 |
|
$children = array(); |
|
68
|
8 |
|
if ($this->hasChildren()) { |
|
69
|
8 |
|
foreach ($this->getElement()->getElementsByTagName($name) as $index => $node) { |
|
70
|
8 |
|
$children[] = $this->getDomDocumentHandler()->getHandler($node, $index); |
|
71
|
6 |
|
} |
|
72
|
6 |
|
} |
|
73
|
8 |
|
return $children; |
|
74
|
|
|
} |
|
75
|
|
|
/** |
|
76
|
|
|
* @return ElementHandler[] |
|
77
|
|
|
*/ |
|
78
|
4 |
|
public function getElementChildren() |
|
79
|
|
|
{ |
|
80
|
4 |
|
$children = array(); |
|
81
|
4 |
|
if ($this->hasChildren()) { |
|
82
|
4 |
|
$children = $this->getDomDocumentHandler()->getElementsHandlers($this->getChildNodes()); |
|
83
|
3 |
|
} |
|
84
|
4 |
|
return $children; |
|
85
|
|
|
} |
|
86
|
|
|
/** |
|
87
|
|
|
* @param string $name |
|
88
|
|
|
* @param array $attributes |
|
89
|
|
|
* @return ElementHandler[] |
|
90
|
|
|
*/ |
|
91
|
4 |
|
public function getChildrenByNameAndAttributes($name, array $attributes) |
|
92
|
|
|
{ |
|
93
|
4 |
|
return $this->getDomDocumentHandler()->getElementsByNameAndAttributes($name, $attributes, $this->getNode()); |
|
94
|
|
|
} |
|
95
|
|
|
/** |
|
96
|
|
|
* @param string $name |
|
97
|
|
|
* @param array $attributes |
|
98
|
|
|
* @return ElementHandler|null |
|
99
|
|
|
*/ |
|
100
|
4 |
|
public function getChildByNameAndAttributes($name, array $attributes) |
|
101
|
|
|
{ |
|
102
|
4 |
|
$children = $this->getChildrenByNameAndAttributes($name, $attributes); |
|
103
|
4 |
|
return empty($children) ? null : array_shift($children); |
|
104
|
|
|
} |
|
105
|
|
|
/** |
|
106
|
|
|
* Info at {@link https://www.w3.org/TR/xmlschema-0/#OccurrenceConstraints} |
|
107
|
|
|
* @return mixed |
|
108
|
|
|
*/ |
|
109
|
20 |
|
public function getMaxOccurs() |
|
110
|
|
|
{ |
|
111
|
20 |
|
$maxOccurs = $this->getAttributeValue(AbstractAttributeHandler::ATTRIBUTE_MAX_OCCURS); |
|
112
|
20 |
|
if ($maxOccurs === AbstractAttributeHandler::VALUE_UNBOUNDED) { |
|
113
|
8 |
|
return $maxOccurs; |
|
114
|
|
|
} |
|
115
|
12 |
|
if (!is_numeric($maxOccurs)) { |
|
116
|
|
|
return AbstractAttributeHandler::DEFAULT_OCCURENCE_VALUE; |
|
117
|
|
|
} |
|
118
|
12 |
|
return (int) $maxOccurs; |
|
119
|
|
|
} |
|
120
|
|
|
/** |
|
121
|
|
|
* Info at {@link https://www.w3.org/TR/xmlschema-0/#OccurrenceConstraints} |
|
122
|
|
|
* @return int |
|
123
|
|
|
*/ |
|
124
|
40 |
|
public function getMinOccurs() |
|
125
|
|
|
{ |
|
126
|
40 |
|
$minOccurs = $this->getAttributeValue(AbstractAttributeHandler::ATTRIBUTE_MIN_OCCURS); |
|
127
|
40 |
|
if (!is_numeric($minOccurs)) { |
|
128
|
8 |
|
return AbstractAttributeHandler::DEFAULT_OCCURENCE_VALUE; |
|
129
|
|
|
} |
|
130
|
32 |
|
return (int) $minOccurs; |
|
131
|
|
|
} |
|
132
|
|
|
/** |
|
133
|
|
|
* Info at {@link http://www.w3schools.com/xml/el_element.asp} |
|
134
|
|
|
* @return bool |
|
135
|
|
|
*/ |
|
136
|
24 |
|
public function getNillable() |
|
137
|
|
|
{ |
|
138
|
24 |
|
return (bool) $this->getAttributeValue(AbstractAttributeHandler::ATTRIBUTE_NILLABLE, false, true, 'bool'); |
|
139
|
|
|
} |
|
140
|
|
|
/** |
|
141
|
|
|
* Info at {@link https://www.w3.org/TR/xmlschema-0/#OccurrenceConstraints} |
|
142
|
|
|
* @return bool |
|
143
|
|
|
*/ |
|
144
|
4 |
|
public function canOccurSeveralTimes() |
|
145
|
|
|
{ |
|
146
|
4 |
|
return ($this->getMinOccurs() > 1) || ($this->getMaxOccurs() > 1) || ($this->getMaxOccurs() === AbstractAttributeHandler::VALUE_UNBOUNDED); |
|
147
|
|
|
} |
|
148
|
|
|
/** |
|
149
|
|
|
* Info at {@link https://www.w3.org/TR/xmlschema-0/#OccurrenceConstraints} |
|
150
|
|
|
* @return bool |
|
151
|
|
|
*/ |
|
152
|
8 |
|
public function canOccurOnlyOnce() |
|
153
|
|
|
{ |
|
154
|
8 |
|
return $this->getMaxOccurs() === 1; |
|
155
|
|
|
} |
|
156
|
|
|
/** |
|
157
|
|
|
* Info at {@link https://www.w3.org/TR/xmlschema-0/#OccurrenceConstraints} |
|
158
|
|
|
* @return bool |
|
159
|
|
|
*/ |
|
160
|
20 |
|
public function isOptional() |
|
161
|
|
|
{ |
|
162
|
20 |
|
return $this->getMinOccurs() === 0; |
|
163
|
|
|
} |
|
164
|
|
|
/** |
|
165
|
|
|
* Info at {@link https://www.w3.org/TR/xmlschema-0/#OccurrenceConstraints} |
|
166
|
|
|
* @return bool |
|
167
|
|
|
*/ |
|
168
|
8 |
|
public function isRequired() |
|
169
|
|
|
{ |
|
170
|
8 |
|
return $this->getMinOccurs() >= 1; |
|
171
|
|
|
} |
|
172
|
|
|
/** |
|
173
|
|
|
* @return bool |
|
174
|
|
|
*/ |
|
175
|
16 |
|
public function isRemovable() |
|
176
|
|
|
{ |
|
177
|
16 |
|
return $this->isOptional() && $this->getNillable(); |
|
178
|
|
|
} |
|
179
|
|
|
} |
|
180
|
|
|
|