Merge pull request #11044 from nupplaphil/feat/api-tests_2

Module Fixings&FollowUps
This commit is contained in:
Hypolite Petovan 2021-11-30 01:13:20 -05:00 committed by GitHub
commit 621b4216d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
151 changed files with 336 additions and 334 deletions

View file

@ -45,5 +45,6 @@ $a->runFrontend(
$dice->create(\Friendica\Core\PConfig\Capability\IManagePersonalConfigValues::class),
$dice->create(\Friendica\Security\Authentication::class),
$dice->create(\Friendica\App\Page::class),
new \Friendica\Util\HTTPInputData($_SERVER),
$start_time
);

View file

@ -40,10 +40,10 @@ use Friendica\Model\Profile;
use Friendica\Module\Special\HTTPException as ModuleHTTPException;
use Friendica\Network\HTTPException;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\HTTPInputData;
use Friendica\Util\HTTPSignature;
use Friendica\Util\Profiler;
use Friendica\Util\Strings;
use GuzzleHttp\Psr7\Response;
use Psr\Log\LoggerInterface;
/**
@ -562,13 +562,15 @@ class App
*
* @param App\Router $router
* @param IManagePersonalConfigValues $pconfig
* @param Authentication $auth The Authentication backend of the node
* @param App\Page $page The Friendica page printing container
* @param Authentication $auth The Authentication backend of the node
* @param App\Page $page The Friendica page printing container
* @param HTTPInputData $httpInput A library for processing PHP input streams
* @param float $start_time The start time of the overall script execution
*
* @throws HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
public function runFrontend(App\Router $router, IManagePersonalConfigValues $pconfig, Authentication $auth, App\Page $page, float $start_time)
public function runFrontend(App\Router $router, IManagePersonalConfigValues $pconfig, Authentication $auth, App\Page $page, HTTPInputData $httpInput, float $start_time)
{
$this->profiler->set($start_time, 'start');
$this->profiler->set(microtime(true), 'classinit');
@ -702,8 +704,12 @@ class App
$module = $router->getModule();
}
// Processes data from GET requests
$httpinput = $httpInput->process();
$input = array_merge($httpinput['variables'], $httpinput['files'], $request ?? $_REQUEST);
// Let the module run it's internal process (init, get, post, ...)
$response = $module->run($_POST, $_REQUEST);
$response = $module->run($input);
if ($response->getHeaderLine(ICanCreateResponses::X_HEADER) === ICanCreateResponses::TYPE_HTML) {
$page->run($this, $this->baseURL, $this->args, $this->mode, $response, $this->l10n, $this->profiler, $this->config, $pconfig);
} else {

View file

@ -128,8 +128,10 @@ abstract class BaseModule implements ICanHandleRequests
*
* Extend this method if the module is supposed to process DELETE requests.
* Doesn't display any content
*
* @param string[] $request The $_REQUEST content
*/
protected function delete()
protected function delete(array $request = [])
{
}
@ -138,8 +140,10 @@ abstract class BaseModule implements ICanHandleRequests
*
* Extend this method if the module is supposed to process PATCH requests.
* Doesn't display any content
*
* @param string[] $request The $_REQUEST content
*/
protected function patch()
protected function patch(array $request = [])
{
}
@ -150,10 +154,9 @@ abstract class BaseModule implements ICanHandleRequests
* Doesn't display any content
*
* @param string[] $request The $_REQUEST content
* @param string[] $post The $_POST content
*
*/
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
// $this->baseUrl->redirect('module');
}
@ -163,15 +166,17 @@ abstract class BaseModule implements ICanHandleRequests
*
* Extend this method if the module is supposed to process PUT requests.
* Doesn't display any content
*
* @param string[] $request The $_REQUEST content
*/
protected function put()
protected function put(array $request = [])
{
}
/**
* {@inheritDoc}
*/
public function run(array $post = [], array $request = []): ResponseInterface
public function run(array $request = []): ResponseInterface
{
// @see https://github.com/tootsuite/mastodon/blob/c3aef491d66aec743a3a53e934a494f653745b61/config/initializers/cors.rb
if (substr($request['pagename'] ?? '', 0, 12) == '.well-known/') {
@ -208,17 +213,17 @@ abstract class BaseModule implements ICanHandleRequests
switch ($this->server['REQUEST_METHOD'] ?? Router::GET) {
case Router::DELETE:
$this->delete();
$this->delete($request);
break;
case Router::PATCH:
$this->patch();
$this->patch($request);
break;
case Router::POST:
Core\Hook::callAll($this->args->getModuleName() . '_mod_post', $post);
$this->post($request, $post);
Core\Hook::callAll($this->args->getModuleName() . '_mod_post', $request);
$this->post($request);
break;
case Router::PUT:
$this->put();
$this->put($request);
break;
}
@ -231,7 +236,7 @@ abstract class BaseModule implements ICanHandleRequests
$arr = ['content' => ''];
Hook::callAll(static::class . '_mod_content', $arr);
$this->response->addContent($arr['content']);
$this->response->addContent($this->content($_REQUEST));
$this->response->addContent($this->content($request));
} catch (HTTPException $e) {
$this->response->addContent((new ModuleHTTPException())->content($e));
} finally {
@ -241,6 +246,48 @@ abstract class BaseModule implements ICanHandleRequests
return $this->response->generate();
}
/**
* Checks request inputs and sets default parameters
*
* @param array $defaults Associative array of expected request keys and their default typed value. A null
* value will remove the request key from the resulting value array.
* @param array $input Custom REQUEST array, superglobal instead
*
* @return array Request data
*/
protected function checkDefaults(array $defaults, array $input): array
{
$request = [];
foreach ($defaults as $parameter => $defaultvalue) {
if (is_string($defaultvalue)) {
$request[$parameter] = $input[$parameter] ?? $defaultvalue;
} elseif (is_int($defaultvalue)) {
$request[$parameter] = (int)($input[$parameter] ?? $defaultvalue);
} elseif (is_float($defaultvalue)) {
$request[$parameter] = (float)($input[$parameter] ?? $defaultvalue);
} elseif (is_array($defaultvalue)) {
$request[$parameter] = $input[$parameter] ?? [];
} elseif (is_bool($defaultvalue)) {
$request[$parameter] = in_array(strtolower($input[$parameter] ?? ''), ['true', '1']);
} else {
$this->logger->notice('Unhandled default value type', ['parameter' => $parameter, 'type' => gettype($defaultvalue)]);
}
}
foreach ($input ?? [] as $parameter => $value) {
if ($parameter == 'pagename') {
continue;
}
if (!in_array($parameter, array_keys($defaults))) {
$this->logger->notice('Unhandled request field', ['parameter' => $parameter, 'value' => $value, 'command' => $this->args->getCommand()]);
}
}
$this->logger->debug('Got request parameters', ['request' => $request, 'command' => $this->args->getCommand()]);
return $request;
}
/*
* Functions used to protect against Cross-Site Request Forgery
* The security token has to base on at least one value that an attacker can't know - here it's the session ID and the private key.

View file

@ -11,12 +11,11 @@ use Psr\Http\Message\ResponseInterface;
interface ICanHandleRequests
{
/**
* @param array $post The $_POST content (in case of POST)
* @param array $request The $_REQUEST content (in case of GET, POST)
* @param array $request The $_REQUEST content (including content from the PHP input stream)
*
* @return ResponseInterface responding to the request handling
*
* @throws HTTPException\InternalServerErrorException
*/
public function run(array $post = [], array $request = []): ResponseInterface;
public function run(array $request = []): ResponseInterface;
}

View file

@ -109,7 +109,7 @@ class Introduction extends BaseRepository
{
try {
$BaseCollection = parent::_selectByBoundaries(
['`uid = ?` AND NOT `ignore`',$uid],
['`uid` = ? AND NOT `ignore`',$uid],
['order' => ['id' => 'DESC']],
$min_id, $max_id, $limit);
} catch (\Exception $e) {

View file

@ -73,9 +73,9 @@ class LegacyModule extends BaseModule
return $this->runModuleFunction('content');
}
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
parent::post($post);
parent::post($request);
$this->runModuleFunction('post');
}

View file

@ -30,7 +30,7 @@ use Friendica\Util\Strings;
class Details extends BaseAdmin
{
public function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAdminAccess();

View file

@ -32,7 +32,7 @@ use Friendica\Util\Network;
class Contact extends BaseAdmin
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAdminAccess();

View file

@ -32,7 +32,7 @@ use GuzzleHttp\Psr7\Uri;
class Add extends BaseAdmin
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAdminAccess();

View file

@ -27,7 +27,7 @@ use Friendica\Module\BaseAdmin;
class Index extends BaseAdmin
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAdminAccess();

View file

@ -28,7 +28,7 @@ use Friendica\Module\BaseAdmin;
class Features extends BaseAdmin
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAdminAccess();

View file

@ -25,11 +25,10 @@ use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Module\BaseAdmin;
use Friendica\Util\Strings;
class Delete extends BaseAdmin
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAdminAccess();

View file

@ -24,12 +24,11 @@ namespace Friendica\Module\Admin\Logs;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Module\BaseAdmin;
use Friendica\Util\Strings;
use Psr\Log\LogLevel;
class Settings extends BaseAdmin
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAdminAccess();

View file

@ -43,7 +43,7 @@ require_once __DIR__ . '/../../../boot.php';
class Site extends BaseAdmin
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAdminAccess();

View file

@ -31,7 +31,7 @@ use Friendica\Util\Strings;
class Storage extends BaseAdmin
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAdminAccess();

View file

@ -50,7 +50,7 @@ class Embed extends BaseAdmin
}
}
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAdminAccess();

View file

@ -45,7 +45,7 @@ class Tos extends BaseAdmin
$this->config = $config;
}
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAdminAccess();

View file

@ -30,7 +30,7 @@ use Friendica\Module\Admin\BaseUsers;
class Active extends BaseUsers
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAdminAccess();

View file

@ -31,7 +31,7 @@ use Friendica\Util\Temporal;
class Blocked extends BaseUsers
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAdminAccess();

View file

@ -28,7 +28,7 @@ use Friendica\Module\Admin\BaseUsers;
class Create extends BaseUsers
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAdminAccess();

View file

@ -33,7 +33,7 @@ use Friendica\Util\Temporal;
class Deleted extends BaseUsers
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAdminAccess();

View file

@ -30,7 +30,7 @@ use Friendica\Module\Admin\BaseUsers;
class Index extends BaseUsers
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAdminAccess();

View file

@ -33,7 +33,7 @@ use Friendica\Util\Temporal;
class Pending extends BaseUsers
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAdminAccess();

View file

@ -8,7 +8,6 @@ use Friendica\Core\L10n;
use Friendica\Module\Response;
use Friendica\Util\Arrays;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\HTTPInputData;
use Friendica\Util\XML;
use Psr\Log\LoggerInterface;
use Friendica\Factory\Api\Twitter\User as TwitterUser;
@ -226,11 +225,12 @@ class ApiResponse extends Response
* Quit execution with the message that the endpoint isn't implemented
*
* @param string $method
* @param array $request (optional) The request content of the current call for later analysis
*
* @return void
* @throws \Exception
*/
public function unsupported(string $method = 'all')
public function unsupported(string $method = 'all', array $request = [])
{
$path = $this->args->getQueryString();
$this->logger->info('Unimplemented API call',
@ -238,7 +238,7 @@ class ApiResponse extends Response
'method' => $method,
'path' => $path,
'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '',
'request' => HTTPInputData::process()
'request' => $request,
]);
$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.');

View file

@ -45,7 +45,7 @@ class Activity extends BaseApi
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
$request = self::getRequest([
$request = $this->getRequest([
'id' => 0, // Id of the post
], $request);

View file

@ -35,7 +35,7 @@ class Setseen extends BaseApi
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
$request = self::getRequest([
$request = $this->getRequest([
'id' => 0, // Id of the direct message
], $request);

View file

@ -38,7 +38,7 @@ class Index extends BaseApi
self::checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$request = self::getRequest([
$request = $this->getRequest([
'since_id' => 0,
'count' => 0,
], $request);

View file

@ -37,7 +37,7 @@ class Delete extends BaseApi
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
$request = self::getRequest([
$request = $this->getRequest([
'gid' => 0,
'name' => ''
], $request);

View file

@ -22,7 +22,6 @@
namespace Friendica\Module\Api\Friendica\Group;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Group;
use Friendica\Module\BaseApi;
@ -84,6 +83,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];
DI::apiResponse()->exit('group_update', ['$result' => $success], $this->parameters['extension'] ?? null);
$this->response->exit('group_update', ['$result' => $success], $this->parameters['extension'] ?? null);
}
}

View file

@ -32,12 +32,12 @@ require_once __DIR__ . '/../../../../include/api.php';
*/
class Index extends BaseApi
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
}
protected function delete()
protected function delete(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
}

View file

@ -70,12 +70,12 @@ 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];
DI::apiResponse()->exit('statuses', $data, $this->parameters['extension'] ?? null);
$this->response->exit('statuses', $data, $this->parameters['extension'] ?? null);
}
// the item can't be found, but we set the notification as seen, so we count this as a success
}
DI::apiResponse()->exit('statuses', ['result' => 'success'], $this->parameters['extension'] ?? null);
$this->response->exit('statuses', ['result' => 'success'], $this->parameters['extension'] ?? null);
} catch (NotFoundException $e) {
throw new BadRequestException('Invalid argument', $e);
} catch (Exception $e) {

View file

@ -36,7 +36,7 @@ class Delete extends BaseApi
{
$uid = self::getCurrentUserID();
$request = self::getRequest([
$request = $this->getRequest([
'photo_id' => '', // Photo id
], $request);

View file

@ -39,7 +39,7 @@ class Delete extends BaseApi
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
$request = self::getRequest([
$request = $this->getRequest([
'album' => '', // Album name
], $request);

View file

@ -37,7 +37,7 @@ class Update extends BaseApi
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
$request = self::getRequest([
$request = $this->getRequest([
'album' => '', // Current album name
'album_new' => '', // New album name
], $request);

View file

@ -90,6 +90,6 @@ class Conversation extends BaseApi
}
DBA::close($statuses);
DI::apiResponse()->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
$this->response->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
}
}

View file

@ -32,7 +32,7 @@ use Friendica\Module\BaseApi;
*/
class Block extends BaseApi
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_FOLLOW);
$uid = self::getCurrentUserID();

View file

@ -31,7 +31,7 @@ use Friendica\Module\BaseApi;
*/
class Follow extends BaseApi
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_FOLLOW);
$uid = self::getCurrentUserID();

View file

@ -48,7 +48,7 @@ class Followers extends BaseApi
DI::mstdnError()->RecordNotFound();
}
$request = self::getRequest([
$request = $this->getRequest([
'max_id' => 0, // Return results older than this id
'since_id' => 0, // Return results newer than this id
'min_id' => 0, // Return results immediately newer than id

View file

@ -48,7 +48,7 @@ class Following extends BaseApi
DI::mstdnError()->RecordNotFound();
}
$request = self::getRequest([
$request = $this->getRequest([
'max_id' => 0, // Return results older than this id
'since_id' => 0, // Return results newer than this id
'min_id' => 0, // Return results immediately newer than id

View file

@ -31,7 +31,7 @@ use Friendica\Module\BaseApi;
*/
class Mute extends BaseApi
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_FOLLOW);
$uid = self::getCurrentUserID();

View file

@ -32,7 +32,7 @@ use Friendica\Module\BaseApi;
*/
class Note extends BaseApi
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
@ -41,7 +41,7 @@ class Note extends BaseApi
DI::mstdnError()->UnprocessableEntity();
}
$request = self::getRequest([
$request = $this->getRequest([
'comment' => '',
], $request);

View file

@ -39,7 +39,7 @@ class Relationships extends BaseApi
self::checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$request = self::getRequest([
$request = $this->getRequest([
'id' => [],
], $request);

View file

@ -42,7 +42,7 @@ class Search extends BaseApi
self::checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$request = self::getRequest([
$request = $this->getRequest([
'q' => '', // What to search for
'limit' => 40, // Maximum number of results. Defaults to 40.
'resolve' => false, // Attempt WebFinger lookup. Defaults to false. Use this when q is an exact address.

View file

@ -52,7 +52,7 @@ class Statuses extends BaseApi
DI::mstdnError()->RecordNotFound();
}
$request = self::getRequest([
$request = $this->getRequest([
'only_media' => false, // Show only statuses with media attached? Defaults to false.
'max_id' => 0, // Return results older than this id
'since_id' => 0, // Return results newer than this id

View file

@ -31,7 +31,7 @@ use Friendica\Module\BaseApi;
*/
class Unblock extends BaseApi
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_FOLLOW);
$uid = self::getCurrentUserID();

View file

@ -31,7 +31,7 @@ use Friendica\Module\BaseApi;
*/
class Unfollow extends BaseApi
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_FOLLOW);
$uid = self::getCurrentUserID();

View file

@ -31,7 +31,7 @@ use Friendica\Module\BaseApi;
*/
class Unmute extends BaseApi
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_FOLLOW);
$uid = self::getCurrentUserID();

View file

@ -24,22 +24,19 @@ namespace Friendica\Module\Api\Mastodon\Accounts;
use Friendica\App\Router;
use Friendica\Core\Logger;
use Friendica\Module\BaseApi;
use Friendica\Util\HTTPInputData;
/**
* @see https://docs.joinmastodon.org/methods/accounts/
*/
class UpdateCredentials extends BaseApi
{
protected function patch()
protected function patch(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
$data = HTTPInputData::process();
Logger::info('Patch data', ['data' => $request]);
Logger::info('Patch data', ['data' => $data]);
$this->response->unsupported(Router::PATCH);
$this->response->unsupported(Router::PATCH, $request);
}
}

View file

@ -35,9 +35,9 @@ class Apps extends BaseApi
/**
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
$request = self::getRequest([
$request = $this->getRequest([
'client_name' => '',
'redirect_uris' => '',
'scopes' => 'read',

View file

@ -48,7 +48,7 @@ class Blocks extends BaseApi
DI::mstdnError()->RecordNotFound();
}
$request = self::getRequest([
$request = $this->getRequest([
'max_id' => 0, // Return results older than this id
'since_id' => 0, // Return results newer than this id
'min_id' => 0, // Return results immediately newer than id

View file

@ -41,7 +41,7 @@ class Bookmarks extends BaseApi
self::checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$request = self::getRequest([
$request = $this->getRequest([
'limit' => 20, // Maximum number of results to return. Defaults to 20.
'max_id' => 0, // Return results older than id
'since_id' => 0, // Return results newer than id

View file

@ -31,7 +31,7 @@ use Friendica\Module\BaseApi;
*/
class Conversations extends BaseApi
{
protected function delete()
protected function delete(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
@ -54,7 +54,7 @@ class Conversations extends BaseApi
self::checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$request = self::getRequest([
$request = $this->getRequest([
'limit' => 20, // Maximum number of results. Defaults to 20. Max 40.
'max_id' => 0, // Return results older than this ID. Use HTTP Link header to paginate.
'since_id' => 0, // Return results newer than this ID. Use HTTP Link header to paginate.

View file

@ -31,7 +31,7 @@ use Friendica\Module\BaseApi;
*/
class Read extends BaseApi
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();

View file

@ -41,7 +41,7 @@ class Directory extends BaseApi
*/
protected function rawContent(array $request = [])
{
$request = self::getRequest([
$request = $this->getRequest([
'offset' => 0, // How many accounts to skip before returning results. Default 0.
'limit' => 40, // How many accounts to load. Default 40.
'order' => 'active', // active to sort by most recently posted statuses (default) or new to sort by most recently created profiles.

View file

@ -42,7 +42,7 @@ class Favourited extends BaseApi
self::checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$request = self::getRequest([
$request = $this->getRequest([
'limit' => 20, // Maximum number of results to return. Defaults to 20.
'min_id' => 0, // Return results immediately newer than id
'max_id' => 0, // Return results older than id

View file

@ -31,11 +31,11 @@ use Friendica\Module\BaseApi;
*/
class Filters extends BaseApi
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->response->unsupported(Router::POST);
$this->response->unsupported(Router::POST, $request);
}
/**

View file

@ -42,7 +42,7 @@ class FollowRequests extends BaseApi
* @see https://docs.joinmastodon.org/methods/accounts/follow_requests#accept-follow
* @see https://docs.joinmastodon.org/methods/accounts/follow_requests#reject-follow
*/
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_FOLLOW);
$uid = self::getCurrentUserID();
@ -87,7 +87,7 @@ class FollowRequests extends BaseApi
self::checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$request = self::getRequest([
$request = $this->getRequest([
'min_id' => 0,
'max_id' => 0,
'limit' => 40, // Maximum number of results to return. Defaults to 40. Paginate using the HTTP Link header.

View file

@ -31,7 +31,7 @@ use Friendica\Model\Group;
*/
class Lists extends BaseApi
{
protected function delete()
protected function delete(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
@ -51,12 +51,12 @@ class Lists extends BaseApi
System::jsonExit([]);
}
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
$request = self::getRequest([
$request = $this->getRequest([
'title' => '',
], $request);
@ -74,9 +74,9 @@ class Lists extends BaseApi
System::jsonExit(DI::mstdnList()->createFromGroupId($id));
}
public function put()
public function put(array $request = [])
{
$request = self::getRequest([
$request = $this->getRequest([
'title' => '', // The title of the list to be updated.
'replies_policy' => '', // One of: "followed", "list", or "none".
]);

View file

@ -34,14 +34,14 @@ use Friendica\Module\BaseApi;
*/
class Accounts extends BaseApi
{
protected function delete()
protected function delete(array $request = [])
{
$this->response->unsupported(Router::DELETE);
$this->response->unsupported(Router::DELETE, $request);
}
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
$this->response->unsupported(Router::POST);
$this->response->unsupported(Router::POST, $request);
}
/**
@ -61,7 +61,7 @@ class Accounts extends BaseApi
DI::mstdnError()->RecordNotFound();
}
$request = self::getRequest([
$request = $this->getRequest([
'max_id' => 0, // Return results older than this id
'since_id' => 0, // Return results newer than this id
'min_id' => 0, // Return results immediately newer than id

View file

@ -31,11 +31,11 @@ use Friendica\Module\BaseApi;
*/
class Markers extends BaseApi
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$this->response->unsupported(Router::POST);
$this->response->unsupported(Router::POST, $request);
}
/**

View file

@ -32,7 +32,7 @@ use Friendica\Module\BaseApi;
*/
class Media extends BaseApi
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
@ -53,12 +53,12 @@ class Media extends BaseApi
System::jsonExit(DI::mstdnAttachment()->createFromPhoto($media['id']));
}
public function put()
public function put(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
$request = self::getRequest([
$request = $this->getRequest([
'file' => [], // The file to be attached, using multipart form data.
'thumbnail' => [], // The custom thumbnail of the media to be attached, using multipart form data.
'description' => '', // A plain-text description of the media, for accessibility purposes.

View file

@ -48,7 +48,7 @@ class Mutes extends BaseApi
DI::mstdnError()->RecordNotFound();
}
$request = self::getRequest([
$request = $this->getRequest([
'max_id' => 0, // Return results older than this id
'since_id' => 0, // Return results newer than this id
'min_id' => 0, // Return results immediately newer than id

View file

@ -55,7 +55,7 @@ class Notifications extends BaseApi
}
}
$request = self::getRequest([
$request = $this->getRequest([
'max_id' => 0, // Return results older than this ID
'since_id' => 0, // Return results newer than this ID
'min_id' => 0, // Return results immediately newer than this ID

View file

@ -30,7 +30,7 @@ use Friendica\Module\BaseApi;
*/
class Clear extends BaseApi
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();

View file

@ -32,7 +32,7 @@ use Friendica\Network\HTTPException\ForbiddenException;
*/
class Dismiss extends BaseApi
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();

View file

@ -33,13 +33,13 @@ use Friendica\Object\Api\Mastodon\Notification;
*/
class PushSubscription extends BaseApi
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_PUSH);
$uid = self::getCurrentUserID();
$application = self::getCurrentApplication();
$request = self::getRequest([
$request = $this->getRequest([
'subscription' => [],
'data' => [],
], $request);
@ -66,13 +66,13 @@ class PushSubscription extends BaseApi
return DI::mstdnSubscription()->createForApplicationIdAndUserId($application['id'], $uid)->toArray();
}
public function put()
public function put(array $request = [])
{
self::checkAllowedScope(self::SCOPE_PUSH);
$uid = self::getCurrentUserID();
$application = self::getCurrentApplication();
$request = self::getRequest([
$request = $this->getRequest([
'data' => [],
]);
@ -99,7 +99,7 @@ class PushSubscription extends BaseApi
return DI::mstdnSubscription()->createForApplicationIdAndUserId($application['id'], $uid)->toArray();
}
protected function delete()
protected function delete(array $request = [])
{
self::checkAllowedScope(self::SCOPE_PUSH);
$uid = self::getCurrentUserID();

View file

@ -33,15 +33,15 @@ use Friendica\Module\BaseApi;
*/
class ScheduledStatuses extends BaseApi
{
public function put()
public function put(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
$this->response->unsupported(Router::PUT);
$this->response->unsupported(Router::PUT, $request);
}
protected function delete()
protected function delete(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
@ -71,7 +71,7 @@ class ScheduledStatuses extends BaseApi
System::jsonExit(DI::mstdnScheduledStatus()->createFromDelayedPostId($this->parameters['id'], $uid)->toArray());
}
$request = self::getRequest([
$request = $this->getRequest([
'limit' => 20, // Max number of results to return. Defaults to 20.
'max_id' => 0, // Return results older than ID
'since_id' => 0, // Return results newer than ID

View file

@ -45,7 +45,7 @@ class Search extends BaseApi
self::checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$request = self::getRequest([
$request = $this->getRequest([
'account_id' => 0, // If provided, statuses returned will be authored only by this account
'max_id' => 0, // Return results older than this id
'min_id' => 0, // Return results immediately newer than this id

View file

@ -41,12 +41,12 @@ use Friendica\Util\Images;
*/
class Statuses extends BaseApi
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
$request = self::getRequest([
$request = $this->getRequest([
'status' => '', // Text content of the status. If media_ids is provided, this becomes optional. Attaching a poll is optional while status is provided.
'media_ids' => [], // Array of Attachment ids to be attached as media. If provided, status becomes optional, and poll cannot be used.
'poll' => [], // Poll data. If provided, media_ids cannot be used, and poll[expires_in] must be provided.
@ -207,7 +207,7 @@ class Statuses extends BaseApi
DI::mstdnError()->InternalError();
}
protected function delete()
protected function delete(array $request = [])
{
self::checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();

View file

@ -33,7 +33,7 @@ use Friendica\Module\BaseApi;
*/
class Bookmark extends BaseApi
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();

View file

@ -43,7 +43,7 @@ class Context extends BaseApi
DI::mstdnError()->UnprocessableEntity();
}
$request = self::getRequest([
$request = $this->getRequest([
'limit' => 40, // Maximum number of results to return. Defaults to 40.
], $request);

View file

@ -33,7 +33,7 @@ use Friendica\Module\BaseApi;
*/
class Favourite extends BaseApi
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();

View file

@ -32,7 +32,7 @@ use Friendica\Module\BaseApi;
*/
class Mute extends BaseApi
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();

View file

@ -32,7 +32,7 @@ use Friendica\Module\BaseApi;
*/
class Pin extends BaseApi
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();

View file

@ -35,7 +35,7 @@ use Friendica\Module\BaseApi;
*/
class Reblog extends BaseApi
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();

View file

@ -33,7 +33,7 @@ use Friendica\Module\BaseApi;
*/
class Unbookmark extends BaseApi
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();

View file

@ -33,7 +33,7 @@ use Friendica\Module\BaseApi;
*/
class Unfavourite extends BaseApi
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();

View file

@ -32,7 +32,7 @@ use Friendica\Module\BaseApi;
*/
class Unmute extends BaseApi
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();

View file

@ -32,7 +32,7 @@ use Friendica\Module\BaseApi;
*/
class Unpin extends BaseApi
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();

View file

@ -35,7 +35,7 @@ use Friendica\Module\BaseApi;
*/
class Unreblog extends BaseApi
{
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();

View file

@ -39,7 +39,7 @@ class Suggestions extends BaseApi
self::checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$request = self::getRequest([
$request = $this->getRequest([
'limit' => 40, // Maximum number of results to return. Defaults to 40.
], $request);

View file

@ -40,7 +40,7 @@ class Direct extends BaseApi
self::checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$request = self::getRequest([
$request = $this->getRequest([
'max_id' => 0, // Return results older than id
'since_id' => 0, // Return results newer than id
'min_id' => 0, // Return results immediately newer than id

View file

@ -41,7 +41,7 @@ class Home extends BaseApi
self::checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$request = self::getRequest([
$request = $this->getRequest([
'max_id' => 0, // Return results older than id
'since_id' => 0, // Return results newer than id
'min_id' => 0, // Return results immediately newer than id

View file

@ -45,7 +45,7 @@ class ListTimeline extends BaseApi
DI::mstdnError()->UnprocessableEntity();
}
$request = self::getRequest([
$request = $this->getRequest([
'max_id' => 0, // Return results older than id
'since_id' => 0, // Return results newer than id
'min_id' => 0, // Return results immediately newer than id

View file

@ -43,7 +43,7 @@ class PublicTimeline extends BaseApi
{
$uid = self::getCurrentUserID();
$request = self::getRequest([
$request = $this->getRequest([
'local' => false, // Show only local statuses? Defaults to false.
'remote' => false, // Show only remote statuses? Defaults to false.
'only_media' => false, // Show only statuses with media attached? Defaults to false.

View file

@ -53,7 +53,7 @@ class Tag extends BaseApi
* There seem to be the parameters "any", "all", and "none".
*/
$request = self::getRequest([
$request = $this->getRequest([
'local' => false, // If true, return only local statuses. Defaults to false.
'remote' => false, // Show only remote statuses? Defaults to false.
'only_media' => false, // If true, return only statuses with media attachments. Defaults to false.

View file

@ -36,7 +36,7 @@ class Trends extends BaseApi
*/
protected function rawContent(array $request = [])
{
$request = self::getRequest([
$request = $this->getRequest([
'limit' => 20, // Maximum number of results to return. Defaults to 10.
], $request);

View file

@ -32,33 +32,33 @@ class Unimplemented extends BaseApi
/**
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
protected function delete()
protected function delete(array $request = [])
{
$this->response->unsupported(Router::DELETE);
$this->response->unsupported(Router::DELETE, $request);
}
/**
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
protected function patch()
protected function patch(array $request = [])
{
$this->response->unsupported(Router::PATCH);
$this->response->unsupported(Router::PATCH, $request);
}
/**
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
protected function post(array $request = [], array $post = [])
protected function post(array $request = [])
{
$this->response->unsupported(Router::POST);
$this->response->unsupported(Router::POST, $request);
}
/**
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function put()
public function put(array $request = [])
{
$this->response->unsupported(Router::PUT);
$this->response->unsupported(Router::PUT, $request);
}
/**
@ -66,6 +66,6 @@ class Unimplemented extends BaseApi
*/
protected function rawContent(array $request = [])
{
$this->response->unsupported(Router::GET);
$this->response->unsupported(Router::GET, $request);
}
}

View file

@ -64,6 +64,6 @@ class UpdateProfile extends BaseApi
// "uid" is only needed for some internal stuff, so remove it from here
unset($user_info['uid']);
DI::apiResponse()->exit('user', ['user' => $user_info], $this->parameters['extension'] ?? null);
$this->response->exit('user', ['user' => $user_info], $this->parameters['extension'] ?? null);
}
}

View file

@ -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']);
DI::apiResponse()->exit('user', ['user' => $user_info], $this->parameters['extension'] ?? null);
$this->response->exit('user', ['user' => $user_info], $this->parameters['extension'] ?? null);
}
}

View file

@ -72,6 +72,6 @@ class Favorites extends BaseApi
}
DBA::close($statuses);
DI::apiResponse()->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
$this->response->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
}
}

View file

@ -46,6 +46,6 @@ class Create extends BaseApi
$status_info = DI::twitterStatus()->createFromItemId($id, $uid)->toArray();
DI::apiResponse()->exit('status', ['status' => $status_info], $this->parameters['extension'] ?? null);
$this->response->exit('status', ['status' => $status_info], $this->parameters['extension'] ?? null);
}
}

View file

@ -46,6 +46,6 @@ class Destroy extends BaseApi
$status_info = DI::twitterStatus()->createFromItemId($id, $uid)->toArray();
DI::apiResponse()->exit('status', ['status' => $status_info], $this->parameters['extension'] ?? null);
$this->response->exit('status', ['status' => $status_info], $this->parameters['extension'] ?? null);
}
}

View file

@ -81,6 +81,6 @@ class Destroy extends ContactEndpoint
throw new HTTPException\InternalServerErrorException('Unable to unfollow this contact, please contact your administrator');
}
DI::apiResponse()->exit('friendships', ['user' => $user], $this->parameters['extension'] ?? null);
$this->response->exit('friendships', ['user' => $user], $this->parameters['extension'] ?? null);
}
}

View file

@ -83,6 +83,6 @@ class Statuses extends BaseApi
}
DBA::close($statuses);
DI::apiResponse()->exit('statuses', ['status' => $items], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
$this->response->exit('statuses', ['status' => $items], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
}
}

View file

@ -65,6 +65,6 @@ class Upload extends BaseApi
Logger::info('Media uploaded', ['return' => $returndata]);
DI::apiResponse()->exit('media', ['media' => $returndata], $this->parameters['extension'] ?? null);
$this->response->exit('media', ['media' => $returndata], $this->parameters['extension'] ?? null);
}
}

View file

@ -77,7 +77,8 @@ class Tweets extends BaseApi
DBA::close($tags);
if (empty($uriids)) {
DI::apiResponse()->exit('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
$this->response->exit('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
return;
}
$condition = ['uri-id' => $uriids];
@ -122,6 +123,6 @@ class Tweets extends BaseApi
}
DBA::close($statuses);
DI::apiResponse()->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
$this->response->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
}
}

View file

@ -53,6 +53,6 @@ class Destroy extends BaseApi
Item::deleteForUser(['id' => $id], $uid);
DI::apiResponse()->exit('status', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
$this->response->exit('status', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
}
}

View file

@ -88,6 +88,6 @@ class HomeTimeline extends BaseApi
}
}
DI::apiResponse()->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
$this->response->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
}
}

View file

@ -80,6 +80,6 @@ class Mentions extends BaseApi
}
DBA::close($statuses);
DI::apiResponse()->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
$this->response->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
}
}

Some files were not shown because too many files have changed in this diff Show more