From fb6c3e2912124473c9d6d6e529ee551b9ce40451 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 9 Nov 2021 06:42:59 +0000 Subject: [PATCH] Simplify the output of api results --- src/Module/Api/Friendica/Events/Index.php | 3 +-- src/Module/Api/Friendica/GNUSocial/Version.php | 3 +-- src/Module/Api/Friendica/Help/Test.php | 3 +-- src/Module/Api/Friendica/Profile/Show.php | 3 +-- src/Module/BaseApi.php | 7 ++++--- 5 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/Module/Api/Friendica/Events/Index.php b/src/Module/Api/Friendica/Events/Index.php index 7103d1dff4..ec8cc077ae 100644 --- a/src/Module/Api/Friendica/Events/Index.php +++ b/src/Module/Api/Friendica/Events/Index.php @@ -70,7 +70,6 @@ class Index extends BaseApi ]; } - echo self::format('events', ['events' => $items]); - exit; + self::exit('events', ['events' => $items]); } } diff --git a/src/Module/Api/Friendica/GNUSocial/Version.php b/src/Module/Api/Friendica/GNUSocial/Version.php index 3a9bc9c56c..83949de7b7 100644 --- a/src/Module/Api/Friendica/GNUSocial/Version.php +++ b/src/Module/Api/Friendica/GNUSocial/Version.php @@ -30,7 +30,6 @@ class Version extends BaseApi { public static function rawContent(array $parameters = []) { - echo self::format('version', ['version' => '0.9.7']); - exit; + self::exit('version', ['version' => '0.9.7']); } } diff --git a/src/Module/Api/Friendica/Help/Test.php b/src/Module/Api/Friendica/Help/Test.php index 2a5ba7bf52..394c5e4830 100644 --- a/src/Module/Api/Friendica/Help/Test.php +++ b/src/Module/Api/Friendica/Help/Test.php @@ -36,7 +36,6 @@ class Test extends BaseApi $ok = 'ok'; } - echo self::format('ok', ['ok' => $ok]); - exit; + self::exit('ok', ['ok' => $ok]); } } diff --git a/src/Module/Api/Friendica/Profile/Show.php b/src/Module/Api/Friendica/Profile/Show.php index 4167e6c61f..67dcfdb6e7 100644 --- a/src/Module/Api/Friendica/Profile/Show.php +++ b/src/Module/Api/Friendica/Profile/Show.php @@ -66,8 +66,7 @@ class Show extends BaseApi 'profiles' => $profiles ]; - echo self::format('friendica_profiles', ['$result' => $result]); - exit; + self::exit('friendica_profiles', ['$result' => $result]); } /** diff --git a/src/Module/BaseApi.php b/src/Module/BaseApi.php index 7e46931864..75ee9ca29a 100644 --- a/src/Module/BaseApi.php +++ b/src/Module/BaseApi.php @@ -348,13 +348,13 @@ class BaseApi extends BaseModule } /** - * Formats the data according to the data type + * Outputs formatted data according to the data type and then exits the execution. * * @param string $root_element * @param array $data An array with a single element containing the returned result * @return false|string */ - protected static function format(string $root_element, array $data) + protected static function exit(string $root_element, array $data) { $return = self::formatData($root_element, self::$format, $data); @@ -382,7 +382,8 @@ class BaseApi extends BaseModule break; } - return $return; + echo $return; + exit; } /**