Simplify the output of api results

This commit is contained in:
Michael 2021-11-09 06:42:59 +00:00
parent 83056df565
commit fb6c3e2912
5 changed files with 8 additions and 11 deletions

View file

@ -70,7 +70,6 @@ class Index extends BaseApi
]; ];
} }
echo self::format('events', ['events' => $items]); self::exit('events', ['events' => $items]);
exit;
} }
} }

View file

@ -30,7 +30,6 @@ class Version extends BaseApi
{ {
public static function rawContent(array $parameters = []) public static function rawContent(array $parameters = [])
{ {
echo self::format('version', ['version' => '0.9.7']); self::exit('version', ['version' => '0.9.7']);
exit;
} }
} }

View file

@ -36,7 +36,6 @@ class Test extends BaseApi
$ok = 'ok'; $ok = 'ok';
} }
echo self::format('ok', ['ok' => $ok]); self::exit('ok', ['ok' => $ok]);
exit;
} }
} }

View file

@ -66,8 +66,7 @@ class Show extends BaseApi
'profiles' => $profiles 'profiles' => $profiles
]; ];
echo self::format('friendica_profiles', ['$result' => $result]); self::exit('friendica_profiles', ['$result' => $result]);
exit;
} }
/** /**

View file

@ -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 string $root_element
* @param array $data An array with a single element containing the returned result * @param array $data An array with a single element containing the returned result
* @return false|string * @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); $return = self::formatData($root_element, self::$format, $data);
@ -382,7 +382,8 @@ class BaseApi extends BaseModule
break; break;
} }
return $return; echo $return;
exit;
} }
/** /**