From 642baa1f2a353fcdb3ea703f653dfe508530b757 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 22 Sep 2023 10:14:46 -0400 Subject: [PATCH] Rename ApipResponse->exit* methods to better show their meaning --- src/Module/Api/ApiResponse.php | 10 +++++----- src/Module/Api/Friendica/Activity.php | 2 +- src/Module/Api/Friendica/Circle/Create.php | 2 +- src/Module/Api/Friendica/Circle/Delete.php | 2 +- src/Module/Api/Friendica/Circle/Show.php | 2 +- src/Module/Api/Friendica/Circle/Update.php | 2 +- src/Module/Api/Friendica/DirectMessages/Search.php | 4 ++-- src/Module/Api/Friendica/DirectMessages/Setseen.php | 6 +++--- src/Module/Api/Friendica/Events/Create.php | 2 +- src/Module/Api/Friendica/Events/Delete.php | 2 +- src/Module/Api/Friendica/Events/Index.php | 2 +- src/Module/Api/Friendica/Notification.php | 2 +- src/Module/Api/Friendica/Notification/Seen.php | 4 ++-- src/Module/Api/Friendica/Photo.php | 2 +- src/Module/Api/Friendica/Photo/Create.php | 2 +- src/Module/Api/Friendica/Photo/Delete.php | 2 +- src/Module/Api/Friendica/Photo/Lists.php | 2 +- src/Module/Api/Friendica/Photo/Update.php | 6 +++--- src/Module/Api/Friendica/Photoalbum/Delete.php | 2 +- src/Module/Api/Friendica/Photoalbum/Index.php | 2 +- src/Module/Api/Friendica/Photoalbum/Show.php | 2 +- src/Module/Api/Friendica/Photoalbum/Update.php | 2 +- src/Module/Api/Friendica/Profile/Show.php | 2 +- src/Module/Api/GNUSocial/GNUSocial/Config.php | 2 +- src/Module/Api/GNUSocial/GNUSocial/Version.php | 2 +- src/Module/Api/GNUSocial/Help/Test.php | 2 +- src/Module/Api/GNUSocial/Statusnet/Conversation.php | 2 +- src/Module/Api/Mastodon/Accounts/UpdateCredentials.php | 2 +- src/Module/Api/Mastodon/Accounts/VerifyCredentials.php | 2 +- src/Module/Api/Mastodon/PushSubscription.php | 8 ++++---- src/Module/Api/Twitter/Account/RateLimitStatus.php | 2 +- src/Module/Api/Twitter/Account/UpdateProfile.php | 2 +- src/Module/Api/Twitter/Account/UpdateProfileImage.php | 2 +- src/Module/Api/Twitter/Account/VerifyCredentials.php | 2 +- src/Module/Api/Twitter/Blocks/Lists.php | 2 +- src/Module/Api/Twitter/DirectMessages/Destroy.php | 8 ++++---- src/Module/Api/Twitter/DirectMessages/NewDM.php | 2 +- src/Module/Api/Twitter/DirectMessagesEndpoint.php | 4 ++-- src/Module/Api/Twitter/Favorites.php | 2 +- src/Module/Api/Twitter/Favorites/Create.php | 2 +- src/Module/Api/Twitter/Favorites/Destroy.php | 2 +- src/Module/Api/Twitter/Followers/Lists.php | 2 +- src/Module/Api/Twitter/Friends/Lists.php | 2 +- src/Module/Api/Twitter/Friendships/Destroy.php | 2 +- src/Module/Api/Twitter/Friendships/Incoming.php | 2 +- src/Module/Api/Twitter/Friendships/Show.php | 2 +- src/Module/Api/Twitter/Lists/Create.php | 2 +- src/Module/Api/Twitter/Lists/Destroy.php | 2 +- src/Module/Api/Twitter/Lists/Lists.php | 2 +- src/Module/Api/Twitter/Lists/Ownership.php | 2 +- src/Module/Api/Twitter/Lists/Statuses.php | 2 +- src/Module/Api/Twitter/Lists/Update.php | 2 +- src/Module/Api/Twitter/Media/Upload.php | 2 +- src/Module/Api/Twitter/SavedSearches.php | 2 +- src/Module/Api/Twitter/Search/Tweets.php | 4 ++-- src/Module/Api/Twitter/Statuses/Destroy.php | 2 +- src/Module/Api/Twitter/Statuses/HomeTimeline.php | 2 +- src/Module/Api/Twitter/Statuses/Mentions.php | 2 +- .../Api/Twitter/Statuses/NetworkPublicTimeline.php | 2 +- src/Module/Api/Twitter/Statuses/PublicTimeline.php | 2 +- src/Module/Api/Twitter/Statuses/Retweet.php | 2 +- src/Module/Api/Twitter/Statuses/Show.php | 4 ++-- src/Module/Api/Twitter/Statuses/Update.php | 2 +- src/Module/Api/Twitter/Statuses/UserTimeline.php | 2 +- src/Module/Api/Twitter/Users/Lookup.php | 2 +- src/Module/Api/Twitter/Users/Search.php | 2 +- src/Module/Api/Twitter/Users/Show.php | 2 +- tests/src/Module/Api/ApiResponseTest.php | 4 ++-- 68 files changed, 88 insertions(+), 88 deletions(-) diff --git a/src/Module/Api/ApiResponse.php b/src/Module/Api/ApiResponse.php index 518bcf8cba..40e1122d4a 100644 --- a/src/Module/Api/ApiResponse.php +++ b/src/Module/Api/ApiResponse.php @@ -210,7 +210,7 @@ class ApiResponse extends Response $this->setHeader(($this->server['SERVER_PROTOCOL'] ?? 'HTTP/1.1') . ' ' . $code . ' ' . $description); - $this->exit('status', ['status' => $error], $format); + $this->addFormattedContent('status', ['status' => $error], $format); } /** @@ -224,7 +224,7 @@ class ApiResponse extends Response * @return void * @throws HTTPException\InternalServerErrorException */ - public function exit(string $root_element, array $data, string $format = null, int $cid = 0) + public function addFormattedContent(string $root_element, array $data, string $format = null, int $cid = 0) { $format = $format ?? 'json'; @@ -259,16 +259,16 @@ class ApiResponse extends Response } /** - * Wrapper around exit() for JSON only responses + * Wrapper around addFormattedContent() for JSON only responses * * @param array $data * * @return void * @throws HTTPException\InternalServerErrorException */ - public function exitWithJson(array $data) + public function addJsonContent(array $data) { - $this->exit('content', ['content' => $data], static::TYPE_JSON); + $this->addFormattedContent('content', ['content' => $data], static::TYPE_JSON); } /** diff --git a/src/Module/Api/Friendica/Activity.php b/src/Module/Api/Friendica/Activity.php index d5024db2c4..d8edfd1a3e 100644 --- a/src/Module/Api/Friendica/Activity.php +++ b/src/Module/Api/Friendica/Activity.php @@ -60,7 +60,7 @@ class Activity extends BaseApi if ($res) { $status_info = DI::twitterStatus()->createFromUriId($request['id'], $uid)->toArray(); - $this->response->exit('status', ['status' => $status_info], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('status', ['status' => $status_info], $this->parameters['extension'] ?? null); } else { $this->response->error(500, 'Error adding activity', '', $this->parameters['extension'] ?? null); } diff --git a/src/Module/Api/Friendica/Circle/Create.php b/src/Module/Api/Friendica/Circle/Create.php index b2787bdd55..8998dbdd95 100644 --- a/src/Module/Api/Friendica/Circle/Create.php +++ b/src/Module/Api/Friendica/Circle/Create.php @@ -82,6 +82,6 @@ class Create extends BaseApi $result = ['success' => true, 'gid' => $gid, 'name' => $name, 'status' => $status, 'wrong users' => $errorusers]; - $this->response->exit('group_create', ['$result' => $result], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('group_create', ['$result' => $result], $this->parameters['extension'] ?? null); } } diff --git a/src/Module/Api/Friendica/Circle/Delete.php b/src/Module/Api/Friendica/Circle/Delete.php index 18db1216b2..3bbe5bc7b3 100644 --- a/src/Module/Api/Friendica/Circle/Delete.php +++ b/src/Module/Api/Friendica/Circle/Delete.php @@ -70,7 +70,7 @@ class Delete extends BaseApi if ($ret) { // return success $success = ['success' => $ret, 'gid' => $request['gid'], 'name' => $request['name'], 'status' => 'deleted', 'wrong users' => []]; - $this->response->exit('group_delete', ['$result' => $success], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('group_delete', ['$result' => $success], $this->parameters['extension'] ?? null); } else { throw new BadRequestException('other API error'); } diff --git a/src/Module/Api/Friendica/Circle/Show.php b/src/Module/Api/Friendica/Circle/Show.php index 9f2f93ede5..c6936dbe3c 100644 --- a/src/Module/Api/Friendica/Circle/Show.php +++ b/src/Module/Api/Friendica/Circle/Show.php @@ -75,6 +75,6 @@ class Show extends BaseApi $grps[] = ['name' => $circle['name'], 'gid' => $circle['id'], $user_element => $users]; } - $this->response->exit('group_update', ['group' => $grps], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('group_update', ['group' => $grps], $this->parameters['extension'] ?? null); } } diff --git a/src/Module/Api/Friendica/Circle/Update.php b/src/Module/Api/Friendica/Circle/Update.php index 38bbea382d..d43082c794 100644 --- a/src/Module/Api/Friendica/Circle/Update.php +++ b/src/Module/Api/Friendica/Circle/Update.php @@ -84,6 +84,6 @@ class Update extends BaseApi // return success message incl. missing users in array $status = ($erroraddinguser ? 'missing user' : 'ok'); $success = ['success' => true, 'gid' => $gid, 'name' => $name, 'status' => $status, 'wrong users' => $errorusers]; - $this->response->exit('group_update', ['$result' => $success], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('group_update', ['$result' => $success], $this->parameters['extension'] ?? null); } } diff --git a/src/Module/Api/Friendica/DirectMessages/Search.php b/src/Module/Api/Friendica/DirectMessages/Search.php index 81fb4e89f0..508f374fd1 100644 --- a/src/Module/Api/Friendica/DirectMessages/Search.php +++ b/src/Module/Api/Friendica/DirectMessages/Search.php @@ -64,7 +64,7 @@ class Search extends BaseApi // error if no searchstring specified if ($request['searchstring'] == '') { $answer = ['result' => 'error', 'message' => 'searchstring not specified']; - $this->response->exit('direct_message_search', ['$result' => $answer], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('direct_message_search', ['$result' => $answer], $this->parameters['extension'] ?? null); return; } @@ -82,6 +82,6 @@ class Search extends BaseApi $success = ['success' => true, 'search_results' => $ret]; } - $this->response->exit('direct_message_search', ['$result' => $success], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('direct_message_search', ['$result' => $success], $this->parameters['extension'] ?? null); } } diff --git a/src/Module/Api/Friendica/DirectMessages/Setseen.php b/src/Module/Api/Friendica/DirectMessages/Setseen.php index 1831db9809..aa9fc0dac8 100644 --- a/src/Module/Api/Friendica/DirectMessages/Setseen.php +++ b/src/Module/Api/Friendica/DirectMessages/Setseen.php @@ -42,14 +42,14 @@ class Setseen extends BaseApi // return error if id is zero if (empty($request['id'])) { $answer = ['result' => 'error', 'message' => 'message id not specified']; - $this->response->exit('direct_messages_setseen', ['$result' => $answer], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('direct_messages_setseen', ['$result' => $answer], $this->parameters['extension'] ?? null); return; } // error message if specified id is not in database if (!DBA::exists('mail', ['id' => $request['id'], 'uid' => $uid])) { $answer = ['result' => 'error', 'message' => 'message id not in database']; - $this->response->exit('direct_messages_setseen', ['$result' => $answer], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('direct_messages_setseen', ['$result' => $answer], $this->parameters['extension'] ?? null); return; } @@ -60,6 +60,6 @@ class Setseen extends BaseApi $answer = ['result' => 'error', 'message' => 'unknown error']; } - $this->response->exit('direct_messages_setseen', ['$result' => $answer], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('direct_messages_setseen', ['$result' => $answer], $this->parameters['extension'] ?? null); } } diff --git a/src/Module/Api/Friendica/Events/Create.php b/src/Module/Api/Friendica/Events/Create.php index 4eb92e9c86..edc1c5936b 100644 --- a/src/Module/Api/Friendica/Events/Create.php +++ b/src/Module/Api/Friendica/Events/Create.php @@ -110,6 +110,6 @@ class Create extends BaseApi $result = ['success' => true, 'event_id' => $event_id, 'event' => $event]; - $this->response->exit('event_create', ['$result' => $result], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('event_create', ['$result' => $result], $this->parameters['extension'] ?? null); } } diff --git a/src/Module/Api/Friendica/Events/Delete.php b/src/Module/Api/Friendica/Events/Delete.php index ab15e666e5..b148c94e30 100644 --- a/src/Module/Api/Friendica/Events/Delete.php +++ b/src/Module/Api/Friendica/Events/Delete.php @@ -59,6 +59,6 @@ class Delete extends BaseApi Event::delete($eventid); $success = ['id' => $eventid, 'status' => 'deleted']; - $this->response->exit('event_delete', ['$result' => $success], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('event_delete', ['$result' => $success], $this->parameters['extension'] ?? null); } } diff --git a/src/Module/Api/Friendica/Events/Index.php b/src/Module/Api/Friendica/Events/Index.php index bb7381f729..a0986d8b0e 100644 --- a/src/Module/Api/Friendica/Events/Index.php +++ b/src/Module/Api/Friendica/Events/Index.php @@ -69,6 +69,6 @@ class Index extends BaseApi ]; } - $this->response->exit('events', ['events' => $items], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('events', ['events' => $items], $this->parameters['extension'] ?? null); } } diff --git a/src/Module/Api/Friendica/Notification.php b/src/Module/Api/Friendica/Notification.php index b7ae74b143..f61d3451c9 100644 --- a/src/Module/Api/Friendica/Notification.php +++ b/src/Module/Api/Friendica/Notification.php @@ -56,6 +56,6 @@ class Notification extends BaseApi $result = false; } - $this->response->exit('notes', ['note' => $result], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('notes', ['note' => $result], $this->parameters['extension'] ?? null); } } diff --git a/src/Module/Api/Friendica/Notification/Seen.php b/src/Module/Api/Friendica/Notification/Seen.php index d445e917c1..c0c50dbe70 100644 --- a/src/Module/Api/Friendica/Notification/Seen.php +++ b/src/Module/Api/Friendica/Notification/Seen.php @@ -70,13 +70,13 @@ class Seen extends BaseApi // we found the item, return it to the user $ret = [DI::twitterStatus()->createFromUriId($item['uri-id'], $item['uid'], $include_entities)->toArray()]; $data = ['status' => $ret]; - $this->response->exit('statuses', $data, $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('statuses', $data, $this->parameters['extension'] ?? null); return; } // the item can't be found, but we set the notification as seen, so we count this as a success } - $this->response->exit('statuses', ['result' => 'success'], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('statuses', ['result' => 'success'], $this->parameters['extension'] ?? null); } catch (NotFoundException $e) { throw new BadRequestException('Invalid argument', $e); } catch (Exception $e) { diff --git a/src/Module/Api/Friendica/Photo.php b/src/Module/Api/Friendica/Photo.php index 0a331f6333..7973c3b6e8 100644 --- a/src/Module/Api/Friendica/Photo.php +++ b/src/Module/Api/Friendica/Photo.php @@ -60,6 +60,6 @@ class Photo extends BaseApi // prepare json/xml output with data from database for the requested photo $data = ['photo' => $this->friendicaPhoto->createFromId($photo_id, $scale, $uid, $type)]; - $this->response->exit('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); + $this->response->addFormattedContent('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); } } diff --git a/src/Module/Api/Friendica/Photo/Create.php b/src/Module/Api/Friendica/Photo/Create.php index 4190145aa0..780060ca23 100644 --- a/src/Module/Api/Friendica/Photo/Create.php +++ b/src/Module/Api/Friendica/Photo/Create.php @@ -90,7 +90,7 @@ class Create extends BaseApi if (!empty($photo)) { Photo::clearAlbumCache($uid); $data = ['photo' => $this->friendicaPhoto->createFromId($photo['resource_id'], null, $uid, $type)]; - $this->response->exit('photo_create', $data, $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('photo_create', $data, $this->parameters['extension'] ?? null); } else { throw new HTTPException\InternalServerErrorException('unknown error - uploading photo failed, see Friendica log for more information'); } diff --git a/src/Module/Api/Friendica/Photo/Delete.php b/src/Module/Api/Friendica/Photo/Delete.php index 3bbd261545..6237f48519 100644 --- a/src/Module/Api/Friendica/Photo/Delete.php +++ b/src/Module/Api/Friendica/Photo/Delete.php @@ -62,7 +62,7 @@ class Delete extends BaseApi Item::deleteForUser($condition, $uid); Photo::clearAlbumCache($uid); $result = ['result' => 'deleted', 'message' => 'photo with id `' . $request['photo_id'] . '` has been deleted from server.']; - $this->response->exit('photo_delete', ['$result' => $result], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('photo_delete', ['$result' => $result], $this->parameters['extension'] ?? null); } else { throw new InternalServerErrorException("unknown error on deleting photo from database table"); } diff --git a/src/Module/Api/Friendica/Photo/Lists.php b/src/Module/Api/Friendica/Photo/Lists.php index 957575aa98..662107f98d 100644 --- a/src/Module/Api/Friendica/Photo/Lists.php +++ b/src/Module/Api/Friendica/Photo/Lists.php @@ -77,6 +77,6 @@ class Lists extends BaseApi } } - $this->response->exit('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); + $this->response->addFormattedContent('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); } } diff --git a/src/Module/Api/Friendica/Photo/Update.php b/src/Module/Api/Friendica/Photo/Update.php index d9ff769aa9..208e3eb40e 100644 --- a/src/Module/Api/Friendica/Photo/Update.php +++ b/src/Module/Api/Friendica/Photo/Update.php @@ -128,7 +128,7 @@ class Update extends BaseApi $photo = Photo::upload($uid, $_FILES['media'], $album, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc, $photo_id); if (!empty($photo)) { $data = ['photo' => $this->friendicaPhoto->createFromId($photo['resource_id'], null, $uid, $type)]; - $this->response->exit('photo_update', $data, $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('photo_update', $data, $this->parameters['extension'] ?? null); return; } } @@ -137,12 +137,12 @@ class Update extends BaseApi if ($result) { Photo::clearAlbumCache($uid); $answer = ['result' => 'updated', 'message' => 'Image id `' . $photo_id . '` has been updated.']; - $this->response->exit('photo_update', ['$result' => $answer], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('photo_update', ['$result' => $answer], $this->parameters['extension'] ?? null); return; } else { if ($nothingtodo) { $answer = ['result' => 'cancelled', 'message' => 'Nothing to update for image id `' . $photo_id . '`.']; - $this->response->exit('photo_update', ['$result' => $answer], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('photo_update', ['$result' => $answer], $this->parameters['extension'] ?? null); return; } throw new HTTPException\InternalServerErrorException('unknown error - update photo entry in database failed'); diff --git a/src/Module/Api/Friendica/Photoalbum/Delete.php b/src/Module/Api/Friendica/Photoalbum/Delete.php index 1c77356e73..023d96797a 100644 --- a/src/Module/Api/Friendica/Photoalbum/Delete.php +++ b/src/Module/Api/Friendica/Photoalbum/Delete.php @@ -68,7 +68,7 @@ class Delete extends BaseApi if ($result) { Photo::clearAlbumCache($uid); $answer = ['result' => 'deleted', 'message' => 'album `' . $request['album'] . '` with all containing photos has been deleted.']; - $this->response->exit('photoalbum_delete', ['$result' => $answer], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('photoalbum_delete', ['$result' => $answer], $this->parameters['extension'] ?? null); } else { throw new InternalServerErrorException("unknown error - deleting from database failed"); } diff --git a/src/Module/Api/Friendica/Photoalbum/Index.php b/src/Module/Api/Friendica/Photoalbum/Index.php index acf0b864dd..af294585ed 100644 --- a/src/Module/Api/Friendica/Photoalbum/Index.php +++ b/src/Module/Api/Friendica/Photoalbum/Index.php @@ -47,6 +47,6 @@ class Index extends BaseApi ]; } - $this->response->exit('albums', ['albums' => $items], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('albums', ['albums' => $items], $this->parameters['extension'] ?? null); } } diff --git a/src/Module/Api/Friendica/Photoalbum/Show.php b/src/Module/Api/Friendica/Photoalbum/Show.php index e1ded1de81..0a7b5ee264 100644 --- a/src/Module/Api/Friendica/Photoalbum/Show.php +++ b/src/Module/Api/Friendica/Photoalbum/Show.php @@ -104,6 +104,6 @@ class Show extends BaseApi } } - $this->response->exit('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); + $this->response->addFormattedContent('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); } } diff --git a/src/Module/Api/Friendica/Photoalbum/Update.php b/src/Module/Api/Friendica/Photoalbum/Update.php index dfc2d2d431..cba99b436b 100644 --- a/src/Module/Api/Friendica/Photoalbum/Update.php +++ b/src/Module/Api/Friendica/Photoalbum/Update.php @@ -60,7 +60,7 @@ class Update extends BaseApi if ($result) { Photo::clearAlbumCache($uid); $answer = ['result' => 'updated', 'message' => 'album `' . $request['album'] . '` with all containing photos has been renamed to `' . $request['album_new'] . '`.']; - $this->response->exit('photoalbum_update', ['$result' => $answer], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('photoalbum_update', ['$result' => $answer], $this->parameters['extension'] ?? null); } else { throw new InternalServerErrorException("unknown error - updating in database failed"); } diff --git a/src/Module/Api/Friendica/Profile/Show.php b/src/Module/Api/Friendica/Profile/Show.php index b97fcdcab9..6aa2e8b66d 100644 --- a/src/Module/Api/Friendica/Profile/Show.php +++ b/src/Module/Api/Friendica/Profile/Show.php @@ -62,7 +62,7 @@ class Show extends BaseApi 'profiles' => $profiles ]; - $this->response->exit('friendica_profiles', ['$result' => $result], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('friendica_profiles', ['$result' => $result], $this->parameters['extension'] ?? null); } /** diff --git a/src/Module/Api/GNUSocial/GNUSocial/Config.php b/src/Module/Api/GNUSocial/GNUSocial/Config.php index 5a8f6aad30..041f521132 100644 --- a/src/Module/Api/GNUSocial/GNUSocial/Config.php +++ b/src/Module/Api/GNUSocial/GNUSocial/Config.php @@ -61,6 +61,6 @@ class Config extends BaseApi ], ]; - $this->response->exit('config', ['config' => $config], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('config', ['config' => $config], $this->parameters['extension'] ?? null); } } diff --git a/src/Module/Api/GNUSocial/GNUSocial/Version.php b/src/Module/Api/GNUSocial/GNUSocial/Version.php index 1f46500b3c..708910941c 100644 --- a/src/Module/Api/GNUSocial/GNUSocial/Version.php +++ b/src/Module/Api/GNUSocial/GNUSocial/Version.php @@ -31,6 +31,6 @@ class Version extends BaseApi { protected function rawContent(array $request = []) { - $this->response->exit('version', ['version' => '0.9.7'], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('version', ['version' => '0.9.7'], $this->parameters['extension'] ?? null); } } diff --git a/src/Module/Api/GNUSocial/Help/Test.php b/src/Module/Api/GNUSocial/Help/Test.php index d0b57d0a7e..ac47ea5a70 100644 --- a/src/Module/Api/GNUSocial/Help/Test.php +++ b/src/Module/Api/GNUSocial/Help/Test.php @@ -37,6 +37,6 @@ class Test extends BaseApi $ok = 'ok'; } - $this->response->exit('ok', ['ok' => $ok], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('ok', ['ok' => $ok], $this->parameters['extension'] ?? null); } } diff --git a/src/Module/Api/GNUSocial/Statusnet/Conversation.php b/src/Module/Api/GNUSocial/Statusnet/Conversation.php index df44098116..522b237b6c 100644 --- a/src/Module/Api/GNUSocial/Statusnet/Conversation.php +++ b/src/Module/Api/GNUSocial/Statusnet/Conversation.php @@ -90,6 +90,6 @@ class Conversation extends BaseApi } DBA::close($statuses); - $this->response->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); + $this->response->addFormattedContent('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); } } diff --git a/src/Module/Api/Mastodon/Accounts/UpdateCredentials.php b/src/Module/Api/Mastodon/Accounts/UpdateCredentials.php index 8518d4c95d..170861461a 100644 --- a/src/Module/Api/Mastodon/Accounts/UpdateCredentials.php +++ b/src/Module/Api/Mastodon/Accounts/UpdateCredentials.php @@ -105,6 +105,6 @@ class UpdateCredentials extends BaseApi } $account = DI::mstdnAccount()->createFromContactId($cdata['user'], $uid); - $this->response->exitWithJson($account->toArray()); + $this->response->addJsonContent($account->toArray()); } } diff --git a/src/Module/Api/Mastodon/Accounts/VerifyCredentials.php b/src/Module/Api/Mastodon/Accounts/VerifyCredentials.php index bdd6d76005..d59549ae8b 100644 --- a/src/Module/Api/Mastodon/Accounts/VerifyCredentials.php +++ b/src/Module/Api/Mastodon/Accounts/VerifyCredentials.php @@ -52,6 +52,6 @@ class VerifyCredentials extends BaseApi // @todo Support the source property, $account = DI::mstdnAccount()->createFromContactId($cdata['user'], $uid); - $this->response->exitWithJson($account->toArray()); + $this->response->addJsonContent($account->toArray()); } } diff --git a/src/Module/Api/Mastodon/PushSubscription.php b/src/Module/Api/Mastodon/PushSubscription.php index 077f0b1028..f43d995b61 100644 --- a/src/Module/Api/Mastodon/PushSubscription.php +++ b/src/Module/Api/Mastodon/PushSubscription.php @@ -81,7 +81,7 @@ class PushSubscription extends BaseApi $this->logger->info('Subscription stored', ['ret' => $ret, 'subscription' => $subscription]); $subscriptionObj = $this->subscriptionFac->createForApplicationIdAndUserId($application['id'], $uid); - $this->response->exitWithJson($subscriptionObj->toArray()); + $this->response->addJsonContent($subscriptionObj->toArray()); } public function put(array $request = []): void @@ -120,7 +120,7 @@ class PushSubscription extends BaseApi ]); $subscriptionObj = $this->subscriptionFac->createForApplicationIdAndUserId($application['id'], $uid); - $this->response->exitWithJson($subscriptionObj->toArray()); + $this->response->addJsonContent($subscriptionObj->toArray()); } protected function delete(array $request = []): void @@ -137,7 +137,7 @@ class PushSubscription extends BaseApi 'uid' => $uid, ]); - $this->response->exitWithJson([]); + $this->response->addJsonContent([]); } protected function rawContent(array $request = []): void @@ -154,6 +154,6 @@ class PushSubscription extends BaseApi $this->logger->info('Fetch subscription', ['application-id' => $application['id'], 'uid' => $uid]); $subscriptionObj = $this->subscriptionFac->createForApplicationIdAndUserId($application['id'], $uid); - $this->response->exitWithJson($subscriptionObj->toArray()); + $this->response->addJsonContent($subscriptionObj->toArray()); } } diff --git a/src/Module/Api/Twitter/Account/RateLimitStatus.php b/src/Module/Api/Twitter/Account/RateLimitStatus.php index e46318d616..a9954c60a0 100644 --- a/src/Module/Api/Twitter/Account/RateLimitStatus.php +++ b/src/Module/Api/Twitter/Account/RateLimitStatus.php @@ -51,6 +51,6 @@ class RateLimitStatus extends BaseApi ]; } - $this->response->exit('hash', ['hash' => $hash], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('hash', ['hash' => $hash], $this->parameters['extension'] ?? null); } } diff --git a/src/Module/Api/Twitter/Account/UpdateProfile.php b/src/Module/Api/Twitter/Account/UpdateProfile.php index 1bcb67cb9c..c58b8d24c8 100644 --- a/src/Module/Api/Twitter/Account/UpdateProfile.php +++ b/src/Module/Api/Twitter/Account/UpdateProfile.php @@ -66,6 +66,6 @@ class UpdateProfile extends BaseApi // "uid" is only needed for some internal stuff, so remove it from here unset($user_info['uid']); - $this->response->exit('user', ['user' => $user_info], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('user', ['user' => $user_info], $this->parameters['extension'] ?? null); } } diff --git a/src/Module/Api/Twitter/Account/UpdateProfileImage.php b/src/Module/Api/Twitter/Account/UpdateProfileImage.php index f21d7ba852..f6ac2d1984 100644 --- a/src/Module/Api/Twitter/Account/UpdateProfileImage.php +++ b/src/Module/Api/Twitter/Account/UpdateProfileImage.php @@ -67,6 +67,6 @@ class UpdateProfileImage extends BaseApi // "uid" is only needed for some internal stuff, so remove it from here unset($user_info['uid']); - $this->response->exit('user', ['user' => $user_info], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('user', ['user' => $user_info], $this->parameters['extension'] ?? null); } } diff --git a/src/Module/Api/Twitter/Account/VerifyCredentials.php b/src/Module/Api/Twitter/Account/VerifyCredentials.php index 4c98bcfa6c..738c08e5a2 100644 --- a/src/Module/Api/Twitter/Account/VerifyCredentials.php +++ b/src/Module/Api/Twitter/Account/VerifyCredentials.php @@ -47,6 +47,6 @@ class VerifyCredentials extends BaseApi // "uid" is only needed for some internal stuff, so remove it from here unset($user_info['uid']); - $this->response->exit('user', ['user' => $user_info], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('user', ['user' => $user_info], $this->parameters['extension'] ?? null); } } diff --git a/src/Module/Api/Twitter/Blocks/Lists.php b/src/Module/Api/Twitter/Blocks/Lists.php index b3583c853f..ec5d711200 100644 --- a/src/Module/Api/Twitter/Blocks/Lists.php +++ b/src/Module/Api/Twitter/Blocks/Lists.php @@ -84,6 +84,6 @@ class Lists extends ContactEndpoint self::setLinkHeader(); - $this->response->exit('lists', ['lists' => $return]); + $this->response->addFormattedContent('lists', ['lists' => $return]); } } diff --git a/src/Module/Api/Twitter/DirectMessages/Destroy.php b/src/Module/Api/Twitter/DirectMessages/Destroy.php index b4b08b05d3..1c07b4e474 100644 --- a/src/Module/Api/Twitter/DirectMessages/Destroy.php +++ b/src/Module/Api/Twitter/DirectMessages/Destroy.php @@ -61,7 +61,7 @@ class Destroy extends BaseApi // error if no id or parenturi specified (for clients posting parent-uri as well) if ($verbose && $id == 0 && $parenturi == "") { $answer = ['result' => 'error', 'message' => 'message id or parenturi not specified']; - $this->response->exit('direct_messages_delete', ['direct_messages_delete' => $answer], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('direct_messages_delete', ['direct_messages_delete' => $answer], $this->parameters['extension'] ?? null); return; } @@ -72,7 +72,7 @@ class Destroy extends BaseApi if (!$this->dba->exists('mail', ["`uid` = ? AND `id` = ? " . $sql_extra, $uid, $id])) { if ($verbose) { $answer = ['result' => 'error', 'message' => 'message id not in database']; - $this->response->exit('direct_messages_delete', ['direct_messages_delete' => $answer], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('direct_messages_delete', ['direct_messages_delete' => $answer], $this->parameters['extension'] ?? null); return; } throw new BadRequestException('message id not in database'); @@ -85,10 +85,10 @@ class Destroy extends BaseApi if ($result) { // return success $answer = ['result' => 'ok', 'message' => 'message deleted']; - $this->response->exit('direct_messages_delete', ['direct_messages_delete' => $answer], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('direct_messages_delete', ['direct_messages_delete' => $answer], $this->parameters['extension'] ?? null); } else { $answer = ['result' => 'error', 'message' => 'unknown error']; - $this->response->exit('direct_messages_delete', ['direct_messages_delete' => $answer], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('direct_messages_delete', ['direct_messages_delete' => $answer], $this->parameters['extension'] ?? null); } } } diff --git a/src/Module/Api/Twitter/DirectMessages/NewDM.php b/src/Module/Api/Twitter/DirectMessages/NewDM.php index 866660810c..30be41be6b 100644 --- a/src/Module/Api/Twitter/DirectMessages/NewDM.php +++ b/src/Module/Api/Twitter/DirectMessages/NewDM.php @@ -91,6 +91,6 @@ class NewDM extends BaseApi $ret = ['error' => $id]; } - $this->response->exit('direct-messages', ['direct_message' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); + $this->response->addFormattedContent('direct-messages', ['direct_message' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); } } diff --git a/src/Module/Api/Twitter/DirectMessagesEndpoint.php b/src/Module/Api/Twitter/DirectMessagesEndpoint.php index fd5b1c552e..6de21281d0 100644 --- a/src/Module/Api/Twitter/DirectMessagesEndpoint.php +++ b/src/Module/Api/Twitter/DirectMessagesEndpoint.php @@ -99,7 +99,7 @@ abstract class DirectMessagesEndpoint extends BaseApi $mails = $this->dba->selectToArray('mail', ['id'], $condition, $params); if ($verbose && !DBA::isResult($mails)) { $answer = ['result' => 'error', 'message' => 'no mails available']; - $this->response->exit('direct-messages', ['direct_message' => $answer], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('direct-messages', ['direct_message' => $answer], $this->parameters['extension'] ?? null); return; } @@ -116,6 +116,6 @@ abstract class DirectMessagesEndpoint extends BaseApi self::setLinkHeader(); - $this->response->exit('direct-messages', ['direct_message' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); + $this->response->addFormattedContent('direct-messages', ['direct_message' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); } } diff --git a/src/Module/Api/Twitter/Favorites.php b/src/Module/Api/Twitter/Favorites.php index 6e63cc63e8..771e0ef489 100644 --- a/src/Module/Api/Twitter/Favorites.php +++ b/src/Module/Api/Twitter/Favorites.php @@ -72,6 +72,6 @@ class Favorites extends BaseApi } DBA::close($statuses); - $this->response->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); + $this->response->addFormattedContent('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); } } diff --git a/src/Module/Api/Twitter/Favorites/Create.php b/src/Module/Api/Twitter/Favorites/Create.php index 96a5f06acb..86a3988046 100644 --- a/src/Module/Api/Twitter/Favorites/Create.php +++ b/src/Module/Api/Twitter/Favorites/Create.php @@ -52,6 +52,6 @@ class Create extends BaseApi $status_info = DI::twitterStatus()->createFromUriId($id, $uid)->toArray(); - $this->response->exit('status', ['status' => $status_info], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('status', ['status' => $status_info], $this->parameters['extension'] ?? null); } } diff --git a/src/Module/Api/Twitter/Favorites/Destroy.php b/src/Module/Api/Twitter/Favorites/Destroy.php index 51ffc7fc73..e481f8a9f2 100644 --- a/src/Module/Api/Twitter/Favorites/Destroy.php +++ b/src/Module/Api/Twitter/Favorites/Destroy.php @@ -52,6 +52,6 @@ class Destroy extends BaseApi $status_info = DI::twitterStatus()->createFromUriId($id, $uid)->toArray(); - $this->response->exit('status', ['status' => $status_info], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('status', ['status' => $status_info], $this->parameters['extension'] ?? null); } } diff --git a/src/Module/Api/Twitter/Followers/Lists.php b/src/Module/Api/Twitter/Followers/Lists.php index 4a141f1401..b4064fc27b 100644 --- a/src/Module/Api/Twitter/Followers/Lists.php +++ b/src/Module/Api/Twitter/Followers/Lists.php @@ -114,6 +114,6 @@ class Lists extends ContactEndpoint $this->response->setHeader(self::getLinkHeader()); - $this->response->exit('lists', ['lists' => $return]); + $this->response->addFormattedContent('lists', ['lists' => $return]); } } diff --git a/src/Module/Api/Twitter/Friends/Lists.php b/src/Module/Api/Twitter/Friends/Lists.php index 534a30aac1..617d70e4db 100644 --- a/src/Module/Api/Twitter/Friends/Lists.php +++ b/src/Module/Api/Twitter/Friends/Lists.php @@ -114,6 +114,6 @@ class Lists extends ContactEndpoint $this->response->setHeader(self::getLinkHeader()); - $this->response->exit('lists', ['lists' => $return]); + $this->response->addFormattedContent('lists', ['lists' => $return]); } } diff --git a/src/Module/Api/Twitter/Friendships/Destroy.php b/src/Module/Api/Twitter/Friendships/Destroy.php index bf769bace5..322d02502c 100644 --- a/src/Module/Api/Twitter/Friendships/Destroy.php +++ b/src/Module/Api/Twitter/Friendships/Destroy.php @@ -87,6 +87,6 @@ class Destroy extends ContactEndpoint throw new HTTPException\InternalServerErrorException('Unable to unfollow this contact, please contact your administrator'); } - $this->response->exit('friendships', ['user' => $user], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('friendships', ['user' => $user], $this->parameters['extension'] ?? null); } } diff --git a/src/Module/Api/Twitter/Friendships/Incoming.php b/src/Module/Api/Twitter/Friendships/Incoming.php index b8573d7ce2..62c372fa28 100644 --- a/src/Module/Api/Twitter/Friendships/Incoming.php +++ b/src/Module/Api/Twitter/Friendships/Incoming.php @@ -82,6 +82,6 @@ class Incoming extends ContactEndpoint $this->response->setHeader(self::getLinkHeader()); - $this->response->exit('incoming', ['incoming' => $return]); + $this->response->addFormattedContent('incoming', ['incoming' => $return]); } } diff --git a/src/Module/Api/Twitter/Friendships/Show.php b/src/Module/Api/Twitter/Friendships/Show.php index 5e9656a719..6dd1c1d200 100644 --- a/src/Module/Api/Twitter/Friendships/Show.php +++ b/src/Module/Api/Twitter/Friendships/Show.php @@ -112,6 +112,6 @@ class Show extends ContactEndpoint ] ]; - DI::apiResponse()->exit('relationship', ['relationship' => $relationship], $this->parameters['extension'] ?? null); + DI::apiResponse()->addFormattedContent('relationship', ['relationship' => $relationship], $this->parameters['extension'] ?? null); } } diff --git a/src/Module/Api/Twitter/Lists/Create.php b/src/Module/Api/Twitter/Lists/Create.php index 1f2f63882a..4943d861a1 100644 --- a/src/Module/Api/Twitter/Lists/Create.php +++ b/src/Module/Api/Twitter/Lists/Create.php @@ -80,6 +80,6 @@ class Create extends BaseApi $grp = $this->friendicaCircle->createFromId($gid); - $this->response->exit('statuses', ['lists' => ['lists' => $grp]], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); + $this->response->addFormattedContent('statuses', ['lists' => ['lists' => $grp]], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); } } diff --git a/src/Module/Api/Twitter/Lists/Destroy.php b/src/Module/Api/Twitter/Lists/Destroy.php index 0214e3ff6d..a249e4a81d 100644 --- a/src/Module/Api/Twitter/Lists/Destroy.php +++ b/src/Module/Api/Twitter/Lists/Destroy.php @@ -77,7 +77,7 @@ class Destroy extends BaseApi $list = $this->friendicaCircle->createFromId($gid); if (Circle::remove($gid)) { - $this->response->exit('statuses', ['lists' => ['lists' => $list]], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); + $this->response->addFormattedContent('statuses', ['lists' => ['lists' => $list]], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); } } } diff --git a/src/Module/Api/Twitter/Lists/Lists.php b/src/Module/Api/Twitter/Lists/Lists.php index 2953c1c973..8ebef3789f 100644 --- a/src/Module/Api/Twitter/Lists/Lists.php +++ b/src/Module/Api/Twitter/Lists/Lists.php @@ -38,6 +38,6 @@ class Lists extends BaseApi // This is a dummy endpoint $ret = []; - $this->response->exit('statuses', ["lists_list" => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); + $this->response->addFormattedContent('statuses', ["lists_list" => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); } } diff --git a/src/Module/Api/Twitter/Lists/Ownership.php b/src/Module/Api/Twitter/Lists/Ownership.php index 2a1ea5ac60..aad152c3ac 100644 --- a/src/Module/Api/Twitter/Lists/Ownership.php +++ b/src/Module/Api/Twitter/Lists/Ownership.php @@ -64,6 +64,6 @@ class Ownership extends BaseApi $lists[] = $this->friendicaCircle->createFromId($circle['id']); } - $this->response->exit('statuses', ['lists' => ['lists' => $lists]], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); + $this->response->addFormattedContent('statuses', ['lists' => ['lists' => $lists]], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); } } diff --git a/src/Module/Api/Twitter/Lists/Statuses.php b/src/Module/Api/Twitter/Lists/Statuses.php index 7d159c498b..154db631d6 100644 --- a/src/Module/Api/Twitter/Lists/Statuses.php +++ b/src/Module/Api/Twitter/Lists/Statuses.php @@ -103,6 +103,6 @@ class Statuses extends BaseApi } $this->dba->close($statuses); - $this->response->exit('statuses', ['status' => $items], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); + $this->response->addFormattedContent('statuses', ['status' => $items], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); } } diff --git a/src/Module/Api/Twitter/Lists/Update.php b/src/Module/Api/Twitter/Lists/Update.php index 6a925eeda5..be98f82654 100644 --- a/src/Module/Api/Twitter/Lists/Update.php +++ b/src/Module/Api/Twitter/Lists/Update.php @@ -78,7 +78,7 @@ class Update extends BaseApi if (Circle::update($gid, $name)) { $list = $this->friendicaCircle->createFromId($gid); - $this->response->exit('statuses', ['lists' => ['lists' => $list]], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); + $this->response->addFormattedContent('statuses', ['lists' => ['lists' => $list]], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); } } } diff --git a/src/Module/Api/Twitter/Media/Upload.php b/src/Module/Api/Twitter/Media/Upload.php index d10b328148..0ea93f87be 100644 --- a/src/Module/Api/Twitter/Media/Upload.php +++ b/src/Module/Api/Twitter/Media/Upload.php @@ -65,6 +65,6 @@ class Upload extends BaseApi Logger::info('Media uploaded', ['return' => $returndata]); - $this->response->exit('media', ['media' => $returndata], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('media', ['media' => $returndata], $this->parameters['extension'] ?? null); } } diff --git a/src/Module/Api/Twitter/SavedSearches.php b/src/Module/Api/Twitter/SavedSearches.php index 8901524ff2..8a6e5ced82 100644 --- a/src/Module/Api/Twitter/SavedSearches.php +++ b/src/Module/Api/Twitter/SavedSearches.php @@ -44,6 +44,6 @@ class SavedSearches extends BaseApi DBA::close($terms); - $this->response->exit('terms', ['terms' => $result], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('terms', ['terms' => $result], $this->parameters['extension'] ?? null); } } diff --git a/src/Module/Api/Twitter/Search/Tweets.php b/src/Module/Api/Twitter/Search/Tweets.php index 7be76cedcb..ec13f00dc0 100644 --- a/src/Module/Api/Twitter/Search/Tweets.php +++ b/src/Module/Api/Twitter/Search/Tweets.php @@ -72,7 +72,7 @@ class Tweets extends BaseApi DBA::close($tags); if (empty($uriids)) { - $this->response->exit('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); + $this->response->addFormattedContent('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); return; } @@ -116,6 +116,6 @@ class Tweets extends BaseApi } DBA::close($statuses); - $this->response->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); + $this->response->addFormattedContent('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); } } diff --git a/src/Module/Api/Twitter/Statuses/Destroy.php b/src/Module/Api/Twitter/Statuses/Destroy.php index 0b43e4509f..bde3ee678d 100644 --- a/src/Module/Api/Twitter/Statuses/Destroy.php +++ b/src/Module/Api/Twitter/Statuses/Destroy.php @@ -59,6 +59,6 @@ class Destroy extends BaseApi Item::deleteForUser(['id' => $post['id']], $uid); - $this->response->exit('status', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); + $this->response->addFormattedContent('status', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); } } diff --git a/src/Module/Api/Twitter/Statuses/HomeTimeline.php b/src/Module/Api/Twitter/Statuses/HomeTimeline.php index 52284e3c1a..d7caea65dd 100644 --- a/src/Module/Api/Twitter/Statuses/HomeTimeline.php +++ b/src/Module/Api/Twitter/Statuses/HomeTimeline.php @@ -87,6 +87,6 @@ class HomeTimeline extends BaseApi } } - $this->response->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); + $this->response->addFormattedContent('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); } } diff --git a/src/Module/Api/Twitter/Statuses/Mentions.php b/src/Module/Api/Twitter/Statuses/Mentions.php index 3c2e2ab804..18d56f1a17 100644 --- a/src/Module/Api/Twitter/Statuses/Mentions.php +++ b/src/Module/Api/Twitter/Statuses/Mentions.php @@ -80,6 +80,6 @@ class Mentions extends BaseApi } DBA::close($statuses); - $this->response->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); + $this->response->addFormattedContent('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); } } diff --git a/src/Module/Api/Twitter/Statuses/NetworkPublicTimeline.php b/src/Module/Api/Twitter/Statuses/NetworkPublicTimeline.php index 1c3d52816e..1f4cbc1b44 100644 --- a/src/Module/Api/Twitter/Statuses/NetworkPublicTimeline.php +++ b/src/Module/Api/Twitter/Statuses/NetworkPublicTimeline.php @@ -63,6 +63,6 @@ class NetworkPublicTimeline extends BaseApi } DBA::close($statuses); - $this->response->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); + $this->response->addFormattedContent('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); } } diff --git a/src/Module/Api/Twitter/Statuses/PublicTimeline.php b/src/Module/Api/Twitter/Statuses/PublicTimeline.php index a05fb5ace5..49b9c986f9 100644 --- a/src/Module/Api/Twitter/Statuses/PublicTimeline.php +++ b/src/Module/Api/Twitter/Statuses/PublicTimeline.php @@ -85,6 +85,6 @@ class PublicTimeline extends BaseApi } DBA::close($statuses); - $this->response->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); + $this->response->addFormattedContent('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); } } diff --git a/src/Module/Api/Twitter/Statuses/Retweet.php b/src/Module/Api/Twitter/Statuses/Retweet.php index 4a1051f0e3..6640f880c6 100644 --- a/src/Module/Api/Twitter/Statuses/Retweet.php +++ b/src/Module/Api/Twitter/Statuses/Retweet.php @@ -69,6 +69,6 @@ class Retweet extends BaseApi $status_info = DI::twitterStatus()->createFromItemId($item_id, $uid)->toArray(); - DI::apiResponse()->exit('statuses', ['status' => $status_info], $this->parameters['extension'] ?? null); + DI::apiResponse()->addFormattedContent('statuses', ['status' => $status_info], $this->parameters['extension'] ?? null); } } diff --git a/src/Module/Api/Twitter/Statuses/Show.php b/src/Module/Api/Twitter/Statuses/Show.php index a7537c3445..67a0b31af5 100644 --- a/src/Module/Api/Twitter/Statuses/Show.php +++ b/src/Module/Api/Twitter/Statuses/Show.php @@ -85,10 +85,10 @@ class Show extends BaseApi if ($conversation) { $data = ['status' => $ret]; - $this->response->exit('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); + $this->response->addFormattedContent('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); } else { $data = ['status' => $ret[0]]; - $this->response->exit('status', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); + $this->response->addFormattedContent('status', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); } } } diff --git a/src/Module/Api/Twitter/Statuses/Update.php b/src/Module/Api/Twitter/Statuses/Update.php index 2151dabd68..b3f0dd8a6f 100644 --- a/src/Module/Api/Twitter/Statuses/Update.php +++ b/src/Module/Api/Twitter/Statuses/Update.php @@ -184,7 +184,7 @@ class Update extends BaseApi if (!empty($item['uri-id'])) { // output the post that we just posted. $status_info = DI::twitterStatus()->createFromUriId($item['uri-id'], $uid, $request['include_entities'])->toArray(); - DI::apiResponse()->exit('status', ['status' => $status_info], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); + DI::apiResponse()->addFormattedContent('status', ['status' => $status_info], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); return; } } diff --git a/src/Module/Api/Twitter/Statuses/UserTimeline.php b/src/Module/Api/Twitter/Statuses/UserTimeline.php index 391ed16ce2..2c58fd6aff 100644 --- a/src/Module/Api/Twitter/Statuses/UserTimeline.php +++ b/src/Module/Api/Twitter/Statuses/UserTimeline.php @@ -80,6 +80,6 @@ class UserTimeline extends BaseApi } DBA::close($statuses); - $this->response->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); + $this->response->addFormattedContent('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); } } diff --git a/src/Module/Api/Twitter/Users/Lookup.php b/src/Module/Api/Twitter/Users/Lookup.php index 809845d501..960239f226 100644 --- a/src/Module/Api/Twitter/Users/Lookup.php +++ b/src/Module/Api/Twitter/Users/Lookup.php @@ -51,6 +51,6 @@ class Lookup extends BaseApi throw new NotFoundException(); } - $this->response->exit('users', ['user' => $users], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('users', ['user' => $users], $this->parameters['extension'] ?? null); } } diff --git a/src/Module/Api/Twitter/Users/Search.php b/src/Module/Api/Twitter/Users/Search.php index f82c003d84..2ca30afac7 100644 --- a/src/Module/Api/Twitter/Users/Search.php +++ b/src/Module/Api/Twitter/Users/Search.php @@ -69,6 +69,6 @@ class Search extends BaseApi throw new BadRequestException('No search term specified.'); } - $this->response->exit('users', $userlist, $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('users', $userlist, $this->parameters['extension'] ?? null); } } diff --git a/src/Module/Api/Twitter/Users/Show.php b/src/Module/Api/Twitter/Users/Show.php index cd321a94c4..158c3f18dc 100644 --- a/src/Module/Api/Twitter/Users/Show.php +++ b/src/Module/Api/Twitter/Users/Show.php @@ -48,6 +48,6 @@ class Show extends BaseApi // "uid" is only needed for some internal stuff, so remove it from here unset($user_info['uid']); - $this->response->exit('user', ['user' => $user_info], $this->parameters['extension'] ?? null); + $this->response->addFormattedContent('user', ['user' => $user_info], $this->parameters['extension'] ?? null); } } diff --git a/tests/src/Module/Api/ApiResponseTest.php b/tests/src/Module/Api/ApiResponseTest.php index 0c246e58a2..c92b9ae235 100644 --- a/tests/src/Module/Api/ApiResponseTest.php +++ b/tests/src/Module/Api/ApiResponseTest.php @@ -285,7 +285,7 @@ class ApiResponseTest extends MockedTest $twitterUser = \Mockery::mock(User::class); $response = new ApiResponse($l10n, $args, new NullLogger(), $baseUrl, $twitterUser); - $response->exitWithJson(['some_data']); + $response->addJsonContent(['some_data']); self::assertEquals('["some_data"]', $response->getContent()); } @@ -302,7 +302,7 @@ class ApiResponseTest extends MockedTest $twitterUser = \Mockery::mock(User::class); $response = new ApiResponse($l10n, $args, new NullLogger(), $baseUrl, $twitterUser, [], 'JsonPCallback'); - $response->exitWithJson(['some_data']); + $response->addJsonContent(['some_data']); self::assertEquals('JsonPCallback(["some_data"])', $response->getContent()); } -- 2.39.5