diff --git a/lib/private/app/infoparser.php b/lib/private/app/infoparser.php index e220fb40df6210aad9ffe390d29fa3bbd714a2fa..3d2b42765aae36de609dc4da8be5dbc8d0f5f403 100644 --- a/lib/private/app/infoparser.php +++ b/lib/private/app/infoparser.php @@ -47,7 +47,7 @@ class InfoParser { if ($xml == false) { return null; } - $array = json_decode(json_encode((array)$xml), TRUE); + $array = $this->xmlToArray($xml, false); if (is_null($array)) { return null; } @@ -86,4 +86,59 @@ class InfoParser { return $array; } + + /** + * @param \SimpleXMLElement $xml + * @return array + */ + function xmlToArray($xml) { + if (!$xml->children()) { + return (string)$xml; + } + + $array = array(); + foreach ($xml->children() as $element => $node) { + $totalElement = count($xml->{$element}); + + if (!isset($array[$element])) { + $array[$element] = ""; + } + /** + * @var \SimpleXMLElement $node + */ + + // Has attributes + if ($attributes = $node->attributes()) { + $data = array( + '@attributes' => array(), + ); + if (!count($node->children())){ + $value = (string)$node; + if (!empty($value)) { + $data['@value'] = (string)$node; + } + } else { + $data = array_merge($data, $this->xmlToArray($node)); + } + foreach ($attributes as $attr => $value) { + $data['@attributes'][$attr] = (string)$value; + } + + if ($totalElement > 1) { + $array[$element][] = $data; + } else { + $array[$element] = $data; + } + // Just a value + } else { + if ($totalElement > 1) { + $array[$element][] = $this->xmlToArray($node); + } else { + $array[$element] = $this->xmlToArray($node); + } + } + } + + return $array; + } } diff --git a/tests/data/app/expected-info.json b/tests/data/app/expected-info.json index 9be6062220ffe9c6eb446d96e5e7baffa6b633c6..6da69fb9ad75866bbcb1d99f3cdecba8ab6c3ec9 100644 --- a/tests/data/app/expected-info.json +++ b/tests/data/app/expected-info.json @@ -18,8 +18,20 @@ "ocsid": "166047", "dependencies": { "php": { - "min-version": 5.4 + "@attributes" : { + "min-version": "5.4", + "max-version": "5.5" + } }, - "database":["sqlite", "mysql"] + "databases": { + "database": [ + { + "@attributes" : { + "min-version": "3.0" + }, + "@value": "sqlite"}, + "mysql" + ] + } } } diff --git a/tests/data/app/strange-types-info.json b/tests/data/app/strange-types-info.json deleted file mode 100644 index eedf8bd0518b5fad743cfcacedf6bcf18a79aa7f..0000000000000000000000000000000000000000 --- a/tests/data/app/strange-types-info.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "info": [], - "remote": [], - "public": [], - "id": "files_encryption", - "name": "Server-side Encryption", - "description": "\n\tThis application encrypts all files accessed by ownCloud at rest, wherever they are stored. As an example, with this application enabled, external cloud based Amazon S3 storage will be encrypted, protecting this data on storage outside of the control of the Admin. When this application is enabled for the first time, all files are encrypted as users log in and are prompted for their password. The recommended recovery key option enables recovery of files in case the key is lost. \n\tNote that this app encrypts all files that are touched by ownCloud, so external storage providers and applications such as SharePoint will see new files encrypted when they are accessed. Encryption is based on AES 128 or 256 bit keys. More information is available in the Encryption documentation \n\t", - "licence": "AGPL", - "author": "Sam Tuke, Bjoern Schiessle, Florin Peter", - "requiremin": "4", - "shipped": "true", - "documentation": { - "user": "https://docs.example.com/server/go.php?to=user-encryption", - "admin": "https://docs.example.com/server/go.php?to=admin-encryption" - }, - "rememberlogin": "false", - "types": [], - "ocsid": "166047", - "dependencies": { - "php": { - "min-version": 5.4 - } - } -} diff --git a/tests/data/app/strange-types-info.xml b/tests/data/app/strange-types-info.xml deleted file mode 100644 index e7e8f0d02811df51f81e235b04b300fe89ba347a..0000000000000000000000000000000000000000 --- a/tests/data/app/strange-types-info.xml +++ /dev/null @@ -1,23 +0,0 @@ -<?xml version="1.0"?> -<info> - <id>files_encryption</id> - <name>Server-side Encryption</name> - <description> - This application encrypts all files accessed by ownCloud at rest, wherever they are stored. As an example, with this application enabled, external cloud based Amazon S3 storage will be encrypted, protecting this data on storage outside of the control of the Admin. When this application is enabled for the first time, all files are encrypted as users log in and are prompted for their password. The recommended recovery key option enables recovery of files in case the key is lost. - Note that this app encrypts all files that are touched by ownCloud, so external storage providers and applications such as SharePoint will see new files encrypted when they are accessed. Encryption is based on AES 128 or 256 bit keys. More information is available in the Encryption documentation - </description> - <licence>AGPL</licence> - <author>Sam Tuke, Bjoern Schiessle, Florin Peter</author> - <requiremin>4</requiremin> - <shipped>true</shipped> - <documentation> - <user>user-encryption</user> - <admin>admin-encryption</admin> - </documentation> - <rememberlogin>false</rememberlogin> - <types><base/></types> - <ocsid>166047</ocsid> - <dependencies> - <php><min-version>5.4</min-version></php> - </dependencies> -</info> diff --git a/tests/data/app/valid-info.xml b/tests/data/app/valid-info.xml index 3a40e62d147fdfdc9186e3ef45b810e184a9bb9e..cdb688c6b3f57241e3ea5b0eb474fbd2cd3db4ec 100644 --- a/tests/data/app/valid-info.xml +++ b/tests/data/app/valid-info.xml @@ -20,10 +20,10 @@ </types> <ocsid>166047</ocsid> <dependencies> - <php> - <min-version>5.4</min-version> - </php> - <database>sqlite</database> - <database>mysql</database> + <php min-version="5.4" max-version="5.5"/> + <databases> + <database min-version="3.0">sqlite</database> + <database>mysql</database> + </databases> </dependencies> </info> diff --git a/tests/lib/app/infoparser.php b/tests/lib/app/infoparser.php index 20668c050861396fb6c9abdec552009f37383c4b..13c0b51e117e212e9543bf39a6f42787ca00bf2b 100644 --- a/tests/lib/app/infoparser.php +++ b/tests/lib/app/infoparser.php @@ -55,7 +55,6 @@ class InfoParser extends \PHPUnit_Framework_TestCase { function providesInfoXml() { return array( array('expected-info.json', 'valid-info.xml'), - array('strange-types-info.json', 'strange-types-info.xml'), array(null, 'invalid-info.xml'), ); }