|
23 | 23 | * @method static string toXmlString(array $var)
|
24 | 24 | * @method static DOMDocument toDomObject(string $var)
|
25 | 25 | * @method static string toMultipartString(array $var, string $boundary)
|
| 26 | + * @method static array toXmlArray(string $xml) |
26 | 27 | */
|
27 | 28 | class DataParser
|
28 | 29 | {
|
@@ -81,11 +82,11 @@ public static function __callStatic($name, $arguments)
|
81 | 82 | }
|
82 | 83 | $callMap = static::getCallableMap();
|
83 | 84 | if (TypeDetector::canBeArray($var) && isset($callMap[$name]['supports']['array'])) {
|
84 |
| - return $callMap[$name]['supports']['array']($var); |
| 85 | + return $callMap[$name]['supports']['array'](...$arguments); |
85 | 86 | } elseif (TypeDetector::canBeString($var) && isset($callMap[$name]['supports']['string'])) {
|
86 |
| - return $callMap[$name]['supports']['string']($var); |
| 87 | + return $callMap[$name]['supports']['string'](...$arguments); |
87 | 88 | } elseif (is_object($var) && isset($callMap[$name]['supports']['object'])) {
|
88 |
| - return $callMap[$name]['supports']['object']($var); |
| 89 | + return $callMap[$name]['supports']['object'](...$arguments); |
89 | 90 | }
|
90 | 91 |
|
91 | 92 | throw new InvalidArgumentException(
|
@@ -177,4 +178,12 @@ public static function arrayToMultipartString(array $var, string $boundary): str
|
177 | 178 |
|
178 | 179 | return $ret;
|
179 | 180 | }
|
| 181 | + |
| 182 | + public static function stringToXmlArray(string $xml): array |
| 183 | + { |
| 184 | + libxml_disable_entity_loader(true); |
| 185 | + $xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); |
| 186 | + |
| 187 | + return json_decode(json_encode($xmlstring), true); |
| 188 | + } |
180 | 189 | }
|
0 commit comments