Transform ApiResponse::createXML() into dynamic method
This commit is contained in:
parent
319f91301d
commit
f28e64299e
|
@ -430,6 +430,15 @@ abstract class DI
|
|||
return self::$dice->create(Model\Log\ParsedLogIterator::class);
|
||||
}
|
||||
|
||||
//
|
||||
// "Module" namespace
|
||||
//
|
||||
|
||||
public static function apiResponse(): Module\Api\ApiResponse
|
||||
{
|
||||
return self::$dice->create(Module\Api\ApiResponse::class);
|
||||
}
|
||||
|
||||
//
|
||||
// "Network" namespace
|
||||
//
|
||||
|
|
|
@ -40,15 +40,17 @@ class ApiResponse
|
|||
*
|
||||
* @return string The XML data
|
||||
*/
|
||||
public static function createXML(array $data, string $root_element): string
|
||||
public function createXML(array $data, string $root_element): string
|
||||
{
|
||||
$childname = key($data);
|
||||
$data2 = array_pop($data);
|
||||
|
||||
$namespaces = ['' => 'http://api.twitter.com',
|
||||
$namespaces = [
|
||||
'' => 'http://api.twitter.com',
|
||||
'statusnet' => 'http://status.net/schema/api/1/',
|
||||
'friendica' => 'http://friendi.ca/schema/api/1/',
|
||||
'georss' => 'http://www.georss.org/georss'];
|
||||
'georss' => 'http://www.georss.org/georss'
|
||||
];
|
||||
|
||||
/// @todo Auto detection of needed namespaces
|
||||
if (in_array($root_element, ['ok', 'hash', 'config', 'version', 'ids', 'notes', 'photos'])) {
|
||||
|
@ -91,7 +93,7 @@ class ApiResponse
|
|||
case 'atom':
|
||||
case 'rss':
|
||||
case 'xml':
|
||||
$ret = static::createXML($data, $root_element);
|
||||
$ret = DI::apiResponse()->createXML($data, $root_element);
|
||||
break;
|
||||
case 'json':
|
||||
default:
|
||||
|
|
|
@ -1114,7 +1114,7 @@ class ApiTest extends FixtureTest
|
|||
'xmlns:georss="http://www.georss.org/georss">' . "\n" .
|
||||
' <data>some_data</data>' . "\n" .
|
||||
'</root_element>' . "\n",
|
||||
ApiResponse::createXML(['data' => ['some_data']], 'root_element')
|
||||
DI::apiResponse()->createXML(['data' => ['some_data']], 'root_element')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1130,7 +1130,7 @@ class ApiTest extends FixtureTest
|
|||
'<ok>' . "\n" .
|
||||
' <data>some_data</data>' . "\n" .
|
||||
'</ok>' . "\n",
|
||||
ApiResponse::createXML(['data' => ['some_data']], 'ok')
|
||||
DI::apiResponse()->createXML(['data' => ['some_data']], 'ok')
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue