1 | <?php |
||
49 | abstract class SimpleXMLElementWrapper |
||
50 | { |
||
51 | /** |
||
52 | * @var array |
||
53 | */ |
||
54 | public $namespaces; |
||
55 | |||
56 | /** |
||
57 | * @var SimpleXMLElement |
||
58 | */ |
||
59 | public $el; |
||
60 | |||
61 | /** |
||
62 | * QuiteSimpleXMLElement constructor. |
||
63 | * |
||
64 | * @param string|SimpleXMLElement|QuiteSimpleXMLElement $elem |
||
65 | * @param QuiteSimpleXMLElement $inherit_from |
||
66 | * @throws InvalidXMLException |
||
67 | * @throws InvalidArgumentException |
||
68 | */ |
||
69 | public function __construct($elem, QuiteSimpleXMLElement $inherit_from = null) |
||
86 | |||
87 | /** |
||
88 | * Internal helper method to get a SimpleXMLElement from either a string |
||
89 | * or a SimpleXMLElement/QuiteSimpleXMLElement object. |
||
90 | * |
||
91 | * @param string|SimpleXMLElement|QuiteSimpleXMLElement $elem |
||
92 | * @return SimpleXMLElement |
||
93 | * @throws InvalidXMLException |
||
94 | * @throws InvalidArgumentException |
||
95 | */ |
||
96 | private function getSimpleXMLElement($elem) |
||
106 | |||
107 | /** |
||
108 | * Internal helper method to parse content from string. |
||
109 | * |
||
110 | * @param string $content |
||
111 | * @return SimpleXMLElement |
||
112 | */ |
||
113 | private function initFromString($content) |
||
121 | |||
122 | /** |
||
123 | * Internal helper method to parse content from string. |
||
124 | * |
||
125 | * @param QuiteSimpleXMLElement|SimpleXMLElement $elem |
||
126 | * @return SimpleXMLElement |
||
127 | */ |
||
128 | private function initFromObject($elem) |
||
137 | |||
138 | /** |
||
139 | * Register a new xpath namespace. |
||
140 | * |
||
141 | * @param string $prefix |
||
142 | * @param string $uri |
||
143 | */ |
||
144 | public function registerXPathNamespace($prefix, $uri) |
||
149 | |||
150 | /** |
||
151 | * Register an array of new xpath namespaces. |
||
152 | * |
||
153 | * @param array $namespaces |
||
154 | */ |
||
155 | public function registerXPathNamespaces($namespaces) |
||
162 | |||
163 | /** |
||
164 | * Get the wrapped SimpleXMLElement object. |
||
165 | * |
||
166 | * @return SimpleXMLElement |
||
167 | */ |
||
168 | public function el() |
||
172 | |||
173 | /** |
||
174 | * Returns the *untrimmed* text content of the node. |
||
175 | * @return string |
||
176 | */ |
||
177 | public function __toString() |
||
181 | |||
182 | /** |
||
183 | * Returns the child elements. |
||
184 | * |
||
185 | * Note: By default, only children without namespace will be returned. You can |
||
186 | * specify a namespace prefix to get children with that namespace prefix. |
||
187 | * |
||
188 | * Tip: You could also use `xpath('child::node()')`. |
||
189 | * |
||
190 | * @param null $ns |
||
191 | * @return QuiteSimpleXMLElement[] |
||
192 | */ |
||
193 | public function children($ns=null) |
||
206 | |||
207 | /** |
||
208 | * Returns the number of child elements. |
||
209 | * |
||
210 | * Note: By default, only children without namespace will be counted. You can |
||
211 | * specify a namespace prefix to count children with that namespace prefix. |
||
212 | * |
||
213 | * @param null $ns |
||
214 | * @return int |
||
215 | */ |
||
216 | public function count($ns = null) |
||
220 | |||
221 | /** |
||
222 | * Returns and element's attributes. |
||
223 | * |
||
224 | * @return SimpleXMLElement a `SimpleXMLElement` object that can be |
||
225 | * iterated over to loop through the attributes on the tag. |
||
226 | */ |
||
227 | public function attributes() |
||
231 | |||
232 | /** |
||
233 | * Returns the XML as text. |
||
234 | * |
||
235 | * @return string |
||
236 | */ |
||
237 | public function asXML() |
||
241 | |||
242 | /** |
||
243 | * Get the element name. |
||
244 | * |
||
245 | * @return string |
||
246 | */ |
||
247 | public function getName() |
||
251 | |||
252 | /** |
||
253 | * Return a namespace array. |
||
254 | * |
||
255 | * @return array |
||
256 | */ |
||
257 | public function getNamespaces() |
||
261 | |||
262 | /** |
||
263 | * Set the node value. |
||
264 | * |
||
265 | * @param string $value |
||
266 | */ |
||
267 | public function setValue($value) |
||
271 | |||
272 | /** |
||
273 | * Return the current object as DOMElement. |
||
274 | * |
||
275 | * @return \DOMElement |
||
276 | */ |
||
277 | public function asDOMElement() |
||
281 | |||
282 | /** |
||
283 | * Replaces the current node. Thanks to @hakre |
||
284 | * <http://stackoverflow.com/questions/17661167/how-to-replace-xml-node-with-simplexmlelement-php>. |
||
285 | * |
||
286 | * @param QuiteSimpleXMLElement $element |
||
287 | */ |
||
288 | public function replace(QuiteSimpleXMLElement $element) |
||
297 | |||
298 | /** |
||
299 | * Static helper method to make initialization easier. |
||
300 | * |
||
301 | * @param $input |
||
302 | * @param array $ns |
||
303 | * @return QuiteSimpleXMLElement |
||
304 | */ |
||
305 | public static function make($input, $ns = []) |
||
312 | } |
||
313 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: