浏览代码

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

Allow stdClass in XML responses
tags/v28.0.0beta1
Kate 1年前
父节点
当前提交
38d64f45be
没有帐户链接到提交者的电子邮件
共有 2 个文件被更改,包括 6 次插入1 次删除
  1. 4
    0
      lib/private/AppFramework/OCS/BaseResponse.php
  2. 2
    1
      tests/lib/AppFramework/OCS/BaseResponseTest.php

+ 4
- 0
lib/private/AppFramework/OCS/BaseResponse.php 查看文件

@@ -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);

+ 2
- 1
tests/lib/AppFramework/OCS/BaseResponseTest.php 查看文件

@@ -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)
);
}

正在加载...
取消
保存