Transform ApiResponse::unspported() into dynamic method

This commit is contained in:
Philipp Holzer 2021-11-12 20:07:05 +01:00
parent ebf56674f1
commit 5bfcc8b91c
Signed by: nupplaPhil
GPG key ID: 24A7501396EB5432
7 changed files with 19 additions and 20 deletions

View file

@ -6,7 +6,6 @@ use Friendica\App\Arguments;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\DI;
use Friendica\Object\Api\Mastodon\Error; use Friendica\Object\Api\Mastodon\Error;
use Friendica\Util\Arrays; use Friendica\Util\Arrays;
use Friendica\Util\HTTPInputData; use Friendica\Util\HTTPInputData;
@ -199,9 +198,9 @@ class ApiResponse
* @return void * @return void
* @throws \Exception * @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', Logger::info('Unimplemented API call',
[ [
'method' => $method, 'method' => $method,
@ -209,8 +208,8 @@ class ApiResponse
'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '', 'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '',
'request' => HTTPInputData::process() 'request' => HTTPInputData::process()
]); ]);
$error = DI::l10n()->t('API endpoint %s %s is not implemented', strtoupper($method), $path); $error = $this->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_description = $this->l10n->t('The API endpoint is currently not implemented but might be in the future.');
$errorobj = new Error($error, $error_description); $errorobj = new Error($error, $error_description);
System::jsonError(501, $errorobj->toArray()); System::jsonError(501, $errorobj->toArray());
} }

View file

@ -23,7 +23,7 @@ namespace Friendica\Module\Api\Mastodon\Accounts;
use Friendica\App\Router; use Friendica\App\Router;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Module\Api\ApiResponse; use Friendica\DI;
use Friendica\Module\BaseApi; use Friendica\Module\BaseApi;
use Friendica\Util\HTTPInputData; use Friendica\Util\HTTPInputData;
@ -41,6 +41,6 @@ class UpdateCredentials extends BaseApi
Logger::info('Patch data', ['data' => $data]); Logger::info('Patch data', ['data' => $data]);
ApiResponse::unsupported(Router::PATCH); DI::apiResponse()->unsupported(Router::PATCH);
} }
} }

View file

@ -23,7 +23,7 @@ namespace Friendica\Module\Api\Mastodon;
use Friendica\App\Router; use Friendica\App\Router;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Module\Api\ApiResponse; use Friendica\DI;
use Friendica\Module\BaseApi; use Friendica\Module\BaseApi;
/** /**
@ -35,7 +35,7 @@ class Filters extends BaseApi
{ {
self::checkAllowedScope(self::SCOPE_WRITE); self::checkAllowedScope(self::SCOPE_WRITE);
ApiResponse::unsupported(Router::POST); DI::apiResponse()->unsupported(Router::POST);
} }
/** /**

View file

@ -37,12 +37,12 @@ class Accounts extends BaseApi
{ {
public static function delete(array $parameters = []) public static function delete(array $parameters = [])
{ {
ApiResponse::unsupported(Router::DELETE); DI::apiResponse()->unsupported(Router::DELETE);
} }
public static function post(array $parameters = []) public static function post(array $parameters = [])
{ {
ApiResponse::unsupported(Router::POST); DI::apiResponse()->unsupported(Router::POST);
} }
/** /**

View file

@ -23,7 +23,7 @@ namespace Friendica\Module\Api\Mastodon;
use Friendica\App\Router; use Friendica\App\Router;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Module\Api\ApiResponse; use Friendica\DI;
use Friendica\Module\BaseApi; use Friendica\Module\BaseApi;
/** /**
@ -35,7 +35,7 @@ class Markers extends BaseApi
{ {
self::checkAllowedScope(self::SCOPE_WRITE); self::checkAllowedScope(self::SCOPE_WRITE);
ApiResponse::unsupported(Router::POST); DI::apiResponse()->unsupported(Router::POST);
} }
/** /**

View file

@ -39,7 +39,7 @@ class ScheduledStatuses extends BaseApi
self::checkAllowedScope(self::SCOPE_WRITE); self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID(); $uid = self::getCurrentUserID();
ApiResponse::unsupported(Router::PUT); DI::apiResponse()->unsupported(Router::PUT);
} }
public static function delete(array $parameters = []) public static function delete(array $parameters = [])

View file

@ -22,7 +22,7 @@
namespace Friendica\Module\Api\Mastodon; namespace Friendica\Module\Api\Mastodon;
use Friendica\App\Router; use Friendica\App\Router;
use Friendica\Module\Api\ApiResponse; use Friendica\DI;
use Friendica\Module\BaseApi; use Friendica\Module\BaseApi;
/** /**
@ -36,7 +36,7 @@ class Unimplemented extends BaseApi
*/ */
public static function delete(array $parameters = []) 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 = []) 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 = []) 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 = []) 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 = []) public static function rawContent(array $parameters = [])
{ {
ApiResponse::unsupported(Router::GET); DI::apiResponse()->unsupported(Router::GET);
} }
} }