Allow stdClass in XML responses

Signed-off-by: jld3103 <jld3103yt@gmail.com>
This commit is contained in:
jld3103 2023-05-24 09:01:56 +02:00
parent 39b716cc78
commit 7f4651637a
No known key found for this signature in database
GPG key ID: 9062417B9E8EB7B3
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)
);
}