From 0e8066cfa7e54985de740be93ed27464d3180190 Mon Sep 17 00:00:00 2001 From: Maxim Zemskov Date: Fri, 8 Jun 2012 10:23:52 +0600 Subject: [PATCH] Fixed LinkedIn xml parser. --- services/LinkedinOAuthService.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/services/LinkedinOAuthService.php b/services/LinkedinOAuthService.php index bef3249..ecafc58 100644 --- a/services/LinkedinOAuthService.php +++ b/services/LinkedinOAuthService.php @@ -46,16 +46,22 @@ protected function fetchAttributes() { * @return array */ protected function parseInfo($xml) { + /* @var $simplexml SimpleXMLElement */ $simplexml = simplexml_load_string($xml); - $array = json_decode(json_encode($simplexml), TRUE); - - foreach (array_slice($array, 0) as $key => $value) { - if (empty($value)) - $array[$key] = NULL; - elseif (is_array($value)) - $array[$key] = toArray($value); + return $this->xmlToArray($simplexml); + } + + /** + * + * @param SimpleXMLElement $element + * @return array + */ + protected function xmlToArray($element) { + $array = (array)$element; + foreach ($array as $key => $value) { + if (is_object($value)) + $array[$key] = $this->xmlToArray($value); } - - return $array; + return $array; } } \ No newline at end of file