From 5bfcc8b91c149391f6b8be75ea87f1f4add5bb6c Mon Sep 17 00:00:00 2001 From: Philipp Date: Fri, 12 Nov 2021 20:07:05 +0100 Subject: [PATCH] Transform ApiResponse::unspported() into dynamic method --- src/Module/Api/ApiResponse.php | 9 ++++----- .../Api/Mastodon/Accounts/UpdateCredentials.php | 4 ++-- src/Module/Api/Mastodon/Filters.php | 4 ++-- src/Module/Api/Mastodon/Lists/Accounts.php | 4 ++-- src/Module/Api/Mastodon/Markers.php | 4 ++-- src/Module/Api/Mastodon/ScheduledStatuses.php | 2 +- src/Module/Api/Mastodon/Unimplemented.php | 12 ++++++------ 7 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/Module/Api/ApiResponse.php b/src/Module/Api/ApiResponse.php index d09cfe3bc..5f7e4e51f 100644 --- a/src/Module/Api/ApiResponse.php +++ b/src/Module/Api/ApiResponse.php @@ -6,7 +6,6 @@ use Friendica\App\Arguments; use Friendica\Core\L10n; use Friendica\Core\Logger; use Friendica\Core\System; -use Friendica\DI; use Friendica\Object\Api\Mastodon\Error; use Friendica\Util\Arrays; use Friendica\Util\HTTPInputData; @@ -199,9 +198,9 @@ class ApiResponse * @return void * @throws \Exception */ - public static function unsupported(string $method = 'all') + public function unsupported(string $method = 'all') { - $path = DI::args()->getQueryString(); + $path = $this->args->getQueryString(); Logger::info('Unimplemented API call', [ 'method' => $method, @@ -209,8 +208,8 @@ class ApiResponse 'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '', 'request' => HTTPInputData::process() ]); - $error = DI::l10n()->t('API endpoint %s %s is not implemented', strtoupper($method), $path); - $error_description = DI::l10n()->t('The API endpoint is currently not implemented but might be in the future.'); + $error = $this->l10n->t('API endpoint %s %s is not implemented', strtoupper($method), $path); + $error_description = $this->l10n->t('The API endpoint is currently not implemented but might be in the future.'); $errorobj = new Error($error, $error_description); System::jsonError(501, $errorobj->toArray()); } diff --git a/src/Module/Api/Mastodon/Accounts/UpdateCredentials.php b/src/Module/Api/Mastodon/Accounts/UpdateCredentials.php index ccd2e903c..449e26fb9 100644 --- a/src/Module/Api/Mastodon/Accounts/UpdateCredentials.php +++ b/src/Module/Api/Mastodon/Accounts/UpdateCredentials.php @@ -23,7 +23,7 @@ namespace Friendica\Module\Api\Mastodon\Accounts; use Friendica\App\Router; use Friendica\Core\Logger; -use Friendica\Module\Api\ApiResponse; +use Friendica\DI; use Friendica\Module\BaseApi; use Friendica\Util\HTTPInputData; @@ -41,6 +41,6 @@ class UpdateCredentials extends BaseApi Logger::info('Patch data', ['data' => $data]); - ApiResponse::unsupported(Router::PATCH); + DI::apiResponse()->unsupported(Router::PATCH); } } diff --git a/src/Module/Api/Mastodon/Filters.php b/src/Module/Api/Mastodon/Filters.php index 8a9cd810b..f14b74a0b 100644 --- a/src/Module/Api/Mastodon/Filters.php +++ b/src/Module/Api/Mastodon/Filters.php @@ -23,7 +23,7 @@ namespace Friendica\Module\Api\Mastodon; use Friendica\App\Router; use Friendica\Core\System; -use Friendica\Module\Api\ApiResponse; +use Friendica\DI; use Friendica\Module\BaseApi; /** @@ -35,7 +35,7 @@ class Filters extends BaseApi { self::checkAllowedScope(self::SCOPE_WRITE); - ApiResponse::unsupported(Router::POST); + DI::apiResponse()->unsupported(Router::POST); } /** diff --git a/src/Module/Api/Mastodon/Lists/Accounts.php b/src/Module/Api/Mastodon/Lists/Accounts.php index e1de45b64..b83f4903a 100644 --- a/src/Module/Api/Mastodon/Lists/Accounts.php +++ b/src/Module/Api/Mastodon/Lists/Accounts.php @@ -37,12 +37,12 @@ class Accounts extends BaseApi { public static function delete(array $parameters = []) { - ApiResponse::unsupported(Router::DELETE); + DI::apiResponse()->unsupported(Router::DELETE); } public static function post(array $parameters = []) { - ApiResponse::unsupported(Router::POST); + DI::apiResponse()->unsupported(Router::POST); } /** diff --git a/src/Module/Api/Mastodon/Markers.php b/src/Module/Api/Mastodon/Markers.php index a45611c2d..394d508d7 100644 --- a/src/Module/Api/Mastodon/Markers.php +++ b/src/Module/Api/Mastodon/Markers.php @@ -23,7 +23,7 @@ namespace Friendica\Module\Api\Mastodon; use Friendica\App\Router; use Friendica\Core\System; -use Friendica\Module\Api\ApiResponse; +use Friendica\DI; use Friendica\Module\BaseApi; /** @@ -35,7 +35,7 @@ class Markers extends BaseApi { self::checkAllowedScope(self::SCOPE_WRITE); - ApiResponse::unsupported(Router::POST); + DI::apiResponse()->unsupported(Router::POST); } /** diff --git a/src/Module/Api/Mastodon/ScheduledStatuses.php b/src/Module/Api/Mastodon/ScheduledStatuses.php index 9f3e53c04..82be0d6e7 100644 --- a/src/Module/Api/Mastodon/ScheduledStatuses.php +++ b/src/Module/Api/Mastodon/ScheduledStatuses.php @@ -39,7 +39,7 @@ class ScheduledStatuses extends BaseApi self::checkAllowedScope(self::SCOPE_WRITE); $uid = self::getCurrentUserID(); - ApiResponse::unsupported(Router::PUT); + DI::apiResponse()->unsupported(Router::PUT); } public static function delete(array $parameters = []) diff --git a/src/Module/Api/Mastodon/Unimplemented.php b/src/Module/Api/Mastodon/Unimplemented.php index d0b32b997..6a0a100c3 100644 --- a/src/Module/Api/Mastodon/Unimplemented.php +++ b/src/Module/Api/Mastodon/Unimplemented.php @@ -22,7 +22,7 @@ namespace Friendica\Module\Api\Mastodon; use Friendica\App\Router; -use Friendica\Module\Api\ApiResponse; +use Friendica\DI; use Friendica\Module\BaseApi; /** @@ -36,7 +36,7 @@ class Unimplemented extends BaseApi */ public static function delete(array $parameters = []) { - ApiResponse::unsupported(Router::DELETE); + DI::apiResponse()->unsupported(Router::DELETE); } /** @@ -45,7 +45,7 @@ class Unimplemented extends BaseApi */ public static function patch(array $parameters = []) { - ApiResponse::unsupported(Router::PATCH); + DI::apiResponse()->unsupported(Router::PATCH); } /** @@ -54,7 +54,7 @@ class Unimplemented extends BaseApi */ public static function post(array $parameters = []) { - ApiResponse::unsupported(Router::POST); + DI::apiResponse()->unsupported(Router::POST); } /** @@ -63,7 +63,7 @@ class Unimplemented extends BaseApi */ public static function put(array $parameters = []) { - ApiResponse::unsupported(Router::PUT); + DI::apiResponse()->unsupported(Router::PUT); } /** @@ -72,6 +72,6 @@ class Unimplemented extends BaseApi */ public static function rawContent(array $parameters = []) { - ApiResponse::unsupported(Router::GET); + DI::apiResponse()->unsupported(Router::GET); } }