From f28e64299e8d73fccc3c1370127df02bab8000e3 Mon Sep 17 00:00:00 2001 From: Philipp Date: Fri, 12 Nov 2021 19:56:37 +0100 Subject: [PATCH] Transform ApiResponse::createXML() into dynamic method --- src/DI.php | 9 +++++++++ src/Module/Api/ApiResponse.php | 14 ++++++++------ tests/legacy/ApiTest.php | 4 ++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/DI.php b/src/DI.php index 692d87870..ead125cff 100644 --- a/src/DI.php +++ b/src/DI.php @@ -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 // diff --git a/src/Module/Api/ApiResponse.php b/src/Module/Api/ApiResponse.php index 768dacb5f..270185025 100644 --- a/src/Module/Api/ApiResponse.php +++ b/src/Module/Api/ApiResponse.php @@ -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', - 'statusnet' => 'http://status.net/schema/api/1/', - 'friendica' => 'http://friendi.ca/schema/api/1/', - 'georss' => 'http://www.georss.org/georss']; + $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' + ]; /// @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: diff --git a/tests/legacy/ApiTest.php b/tests/legacy/ApiTest.php index 4ea5c784a..c5d28f2d5 100644 --- a/tests/legacy/ApiTest.php +++ b/tests/legacy/ApiTest.php @@ -1114,7 +1114,7 @@ class ApiTest extends FixtureTest 'xmlns:georss="http://www.georss.org/georss">' . "\n" . ' some_data' . "\n" . '' . "\n", - ApiResponse::createXML(['data' => ['some_data']], 'root_element') + DI::apiResponse()->createXML(['data' => ['some_data']], 'root_element') ); } @@ -1130,7 +1130,7 @@ class ApiTest extends FixtureTest '' . "\n" . ' some_data' . "\n" . '' . "\n", - ApiResponse::createXML(['data' => ['some_data']], 'ok') + DI::apiResponse()->createXML(['data' => ['some_data']], 'ok') ); }