Merge pull request #38745 from nextcloud/feature/ocs-xml-stdclass

Allow stdClass in XML responses
This commit is contained in:
Kate 2023-06-13 13:30:55 +02:00 committed by GitHub
commit 38d64f45be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View file

@ -143,6 +143,10 @@ abstract class BaseResponse extends Response {
$k = 'element';
}
if ($v instanceof \stdClass) {
$v = [];
}
if (\is_array($v)) {
$writer->startElement($k);
$this->toXML($v, $writer);

View file

@ -45,13 +45,14 @@ class BaseResponseTest extends \Test\TestCase {
'someElement' => 'withAttribute',
],
'value without key',
'object' => new \stdClass(),
];
$this->invokePrivate($response, 'toXml', [$data, $writer]);
$writer->endDocument();
$this->assertEquals(
"<?xml version=\"1.0\"?>\n<hello>hello</hello><information test=\"some data\"><someElement>withAttribute</someElement></information><element>value without key</element>\n",
"<?xml version=\"1.0\"?>\n<hello>hello</hello><information test=\"some data\"><someElement>withAttribute</someElement></information><element>value without key</element><object/>\n",
$writer->outputMemory(true)
);
}