|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* ownCloud - Music app |
|
5
|
|
|
* |
|
6
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
7
|
|
|
* later. See the COPYING file. |
|
8
|
|
|
* |
|
9
|
|
|
* @author Pauli Järvinen <[email protected]> |
|
10
|
|
|
* @copyright Pauli Järvinen 2019 |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace OCA\Music\Http; |
|
14
|
|
|
|
|
15
|
|
|
use OCP\AppFramework\Http\Response; |
|
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* This class creates an XML response out of a passed in associative array, |
|
19
|
|
|
* similarly how the class JSONResponse works. The content is described with |
|
20
|
|
|
* a recursive array structure, where arrays may have string or integer keys. |
|
21
|
|
|
* One array should not mix string and integer keys, that will lead to undefined |
|
22
|
|
|
* outcome. Furthermore, array with integer keys is supported only as payload of |
|
23
|
|
|
* an array with string keys. |
|
24
|
|
|
* |
|
25
|
|
|
* Note that this response type has been created to fulfill the needs of the |
|
26
|
|
|
* SubsonicController and may not be suitable for all other purposes. |
|
27
|
|
|
*/ |
|
28
|
|
|
class XMLResponse extends Response { |
|
29
|
|
|
|
|
30
|
|
|
private $content; |
|
31
|
|
|
|
|
32
|
|
|
public function __construct(array $content) { |
|
33
|
|
|
$this->addHeader('Content-Type', 'application/xml'); |
|
34
|
|
|
|
|
35
|
|
|
// The content must have exactly one root element, add one if necessary |
|
36
|
|
|
if (\count($content) != 1) { |
|
37
|
|
|
$content = ['root' => $content]; |
|
38
|
|
|
} |
|
39
|
|
|
$this->content = $content; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function render() { |
|
43
|
|
|
$rootName = \array_keys($this->content)[0]; |
|
44
|
|
|
|
|
45
|
|
|
$xmlTree = new \SimpleXMLElement("<?xml version='1.0' encoding='UTF-8'?><$rootName/>"); |
|
46
|
|
|
foreach ($this->content[$rootName] as $key => $value) { |
|
47
|
|
|
self::addChildElement($xmlTree, $key, $value); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
return $xmlTree->asXML(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
private static function addChildElement($parentNode, $key, $value) { |
|
54
|
|
|
if (\is_bool($value)) { |
|
55
|
|
|
$value = $value ? 'true' : 'false'; |
|
56
|
|
|
$parentNode->addAttribute($key, $value); |
|
57
|
|
|
} |
|
58
|
|
|
elseif (\is_string($value) || \is_numeric($value)) { |
|
59
|
|
|
$parentNode->addAttribute($key, $value); |
|
60
|
|
|
} |
|
61
|
|
|
elseif (\is_array($value)) { |
|
62
|
|
|
if (self::arrayIsIndexed($value)) { |
|
63
|
|
|
foreach ($value as $child) { |
|
64
|
|
|
self::addChildElement($parentNode, $key, $child); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
else { |
|
68
|
|
|
// associative array |
|
69
|
|
|
$element = $parentNode->addChild($key); |
|
70
|
|
|
foreach ($value as $childKey => $childValue) { |
|
71
|
|
|
self::addChildElement($element, $childKey, $childValue); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
elseif ($value === null) { |
|
76
|
|
|
// skip |
|
77
|
|
|
} |
|
78
|
|
|
else { |
|
79
|
|
|
throw new \Exception("Unexpected value type for key $key"); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Array is considered to be "indexed" if its first element has numerical key. |
|
85
|
|
|
* @param array $array |
|
86
|
|
|
*/ |
|
87
|
|
|
private static function arrayIsIndexed(array $array) { |
|
88
|
|
|
reset($array); |
|
89
|
|
|
return empty($array) || \is_int(key($array)); |
|
90
|
|
|
} |
|
91
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths