| @@ 14-59 (lines=46) @@ | ||
| 11 | * |
|
| 12 | * @author Márk Sági-Kazár <[email protected]> |
|
| 13 | */ |
|
| 14 | final class Zend1Parser implements Parser |
|
| 15 | { |
|
| 16 | /** |
|
| 17 | * {@inheritdoc} |
|
| 18 | */ |
|
| 19 | public function parse($xmlString, &$isFault) |
|
| 20 | { |
|
| 21 | $response = new \Zend_XmlRpc_Response(); |
|
| 22 | ||
| 23 | try { |
|
| 24 | $response->loadXml($xmlString); |
|
| 25 | } catch (\Exception $e) { |
|
| 26 | throw new ParserException($e->getMessage(), $e->getCode(), $e); |
|
| 27 | } |
|
| 28 | ||
| 29 | $isFault = $response->isFault(); |
|
| 30 | ||
| 31 | if ($isFault) { |
|
| 32 | $fault = $response->getFault(); |
|
| 33 | ||
| 34 | return [ |
|
| 35 | 'faultCode' => $fault->getCode(), |
|
| 36 | 'faultString' => $fault->getMessage(), |
|
| 37 | ]; |
|
| 38 | } |
|
| 39 | ||
| 40 | $result = $response->getReturnValue(); |
|
| 41 | ||
| 42 | $toBeVisited = [&$result]; |
|
| 43 | ||
| 44 | while (isset($toBeVisited[0]) && $value = &$toBeVisited[0]) { |
|
| 45 | $type = gettype($value); |
|
| 46 | if ($type === 'array') { |
|
| 47 | foreach ($value as &$element) { |
|
| 48 | $toBeVisited[] = &$element; |
|
| 49 | } |
|
| 50 | ||
| 51 | reset($value); // Reset all array pointers |
|
| 52 | } |
|
| 53 | ||
| 54 | array_shift($toBeVisited); |
|
| 55 | } |
|
| 56 | ||
| 57 | return $result; |
|
| 58 | } |
|
| 59 | } |
|
| 60 | ||
| @@ 15-60 (lines=46) @@ | ||
| 12 | * |
|
| 13 | * @author Márk Sági-Kazár <[email protected]> |
|
| 14 | */ |
|
| 15 | final class Zend2Parser implements Parser |
|
| 16 | { |
|
| 17 | /** |
|
| 18 | * {@inheritdoc} |
|
| 19 | */ |
|
| 20 | public function parse($xmlString, &$isFault) |
|
| 21 | { |
|
| 22 | $response = new Response(); |
|
| 23 | ||
| 24 | try { |
|
| 25 | $response->loadXml($xmlString); |
|
| 26 | } catch (\Exception $e) { |
|
| 27 | throw new ParserException($e->getMessage(), $e->getCode(), $e); |
|
| 28 | } |
|
| 29 | ||
| 30 | $isFault = $response->isFault(); |
|
| 31 | ||
| 32 | if ($isFault) { |
|
| 33 | $fault = $response->getFault(); |
|
| 34 | ||
| 35 | return [ |
|
| 36 | 'faultCode' => $fault->getCode(), |
|
| 37 | 'faultString' => $fault->getMessage(), |
|
| 38 | ]; |
|
| 39 | } |
|
| 40 | ||
| 41 | $result = $response->getReturnValue(); |
|
| 42 | ||
| 43 | $toBeVisited = [&$result]; |
|
| 44 | ||
| 45 | while (isset($toBeVisited[0]) && $value = &$toBeVisited[0]) { |
|
| 46 | $type = gettype($value); |
|
| 47 | if ($type === 'array') { |
|
| 48 | foreach ($value as &$element) { |
|
| 49 | $toBeVisited[] = &$element; |
|
| 50 | } |
|
| 51 | ||
| 52 | reset($value); // Reset all array pointers |
|
| 53 | } |
|
| 54 | ||
| 55 | array_shift($toBeVisited); |
|
| 56 | } |
|
| 57 | ||
| 58 | return $result; |
|
| 59 | } |
|
| 60 | } |
|
| 61 | ||