Introduce `Response` for Modules to create a testable way for module responses

This commit is contained in:
Philipp Holzer 2021-11-21 20:06:36 +01:00
parent ad5b0762b0
commit 561aba18e3
Signed by: nupplaPhil
GPG Key ID: 24A7501396EB5432
37 changed files with 309 additions and 113 deletions

View File

@ -47,7 +47,7 @@ function settings_init(App $a)
return;
}
BaseSettings::content();
BaseSettings::createAside();
}
function settings_post(App $a)
@ -408,7 +408,7 @@ function settings_content(App $a)
if (!empty($_SESSION['submanage'])) {
notice(DI::l10n()->t('Permission denied.'));
return;
return '';
}
if ((DI::args()->getArgc() > 1) && (DI::args()->getArgv()[1] === 'oauth')) {
@ -417,7 +417,7 @@ function settings_content(App $a)
DBA::delete('application-token', ['application-id' => DI::args()->getArgv()[3], 'uid' => local_user()]);
DI::baseUrl()->redirect('settings/oauth/', true);
return;
return '';
}
$applications = DBA::selectToArray('application-view', ['id', 'uid', 'name', 'website', 'scopes', 'created_at'], ['uid' => local_user()]);
@ -577,7 +577,7 @@ function settings_content(App $a)
$profile = DBA::selectFirst('profile', [], ['uid' => local_user()]);
if (!DBA::isResult($profile)) {
notice(DI::l10n()->t('Unable to find your profile. Please contact your admin.'));
return;
return '';
}
$user = User::getById($a->getLoggedInUserId());

View File

@ -701,8 +701,8 @@ class App
}
// Let the module run it's internal process (init, get, post, ...)
$content = $module->run($_POST, $_REQUEST);
$page->run($this, $this->baseURL, $this->args, $this->mode, $content, $this->l10n, $this->profiler, $this->config, $pconfig);
$response = $module->run($_POST, $_REQUEST);
$page->run($this, $this->baseURL, $this->args, $this->mode, $response, $this->l10n, $this->profiler, $this->config, $pconfig);
} catch (HTTPException $e) {
(new ModuleHTTPException())->rawContent($e);
}

View File

@ -25,6 +25,7 @@ use ArrayAccess;
use DOMDocument;
use DOMXPath;
use Friendica\App;
use Friendica\Capabilities\IRespondToRequests;
use Friendica\Content\Nav;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
@ -336,19 +337,19 @@ class Page implements ArrayAccess
* - module content
* - hooks for content
*
* @param string $content The content to print
* @param IRespondToRequests $response The Module response class
* @param Mode $mode The Friendica execution mode
*
* @throws HTTPException\InternalServerErrorException
*/
private function initContent(string $content, Mode $mode)
private function initContent(IRespondToRequests $response, Mode $mode)
{
// initialise content region
if ($mode->isNormal()) {
Hook::callAll('page_content_top', $this->page['content']);
}
$this->page['content'] .= $content;
$this->page['content'] .= $response->getContent();
}
/**
@ -377,14 +378,14 @@ class Page implements ArrayAccess
* @param BaseURL $baseURL The Friendica Base URL
* @param Arguments $args The Friendica App arguments
* @param Mode $mode The current node mode
* @param string $content The content to print on frontend
* @param IRespondToRequests $response The Response of the module class, including type, content & headers
* @param L10n $l10n The l10n language class
* @param IManageConfigValues $config The Configuration of this node
* @param IManagePersonalConfigValues $pconfig The personal/user configuration
*
* @throws HTTPException\InternalServerErrorException|HTTPException\ServiceUnavailableException
*/
public function run(App $app, BaseURL $baseURL, Arguments $args, Mode $mode, string $content, L10n $l10n, Profiler $profiler, IManageConfigValues $config, IManagePersonalConfigValues $pconfig)
public function run(App $app, BaseURL $baseURL, Arguments $args, Mode $mode, IRespondToRequests $response, L10n $l10n, Profiler $profiler, IManageConfigValues $config, IManagePersonalConfigValues $pconfig)
{
$moduleName = $args->getModuleName();
@ -394,7 +395,7 @@ class Page implements ArrayAccess
* Sets the $Page->page['content'] variable
*/
$timestamp = microtime(true);
$this->initContent($content, $mode);
$this->initContent($response, $mode);
$profiler->set(microtime(true) - $timestamp, 'content');
// Load current theme info after module has been initialized as theme could have been set in module
@ -433,6 +434,16 @@ class Page implements ArrayAccess
$this->page['nav'] = Nav::build($app);
}
foreach ($response->getHeaders() as $key => $values) {
if (is_array($values)) {
foreach ($values as $value) {
header($key, $value);
}
} else {
header($key, $values);
}
}
// Build the page - now that we have all the components
if (isset($_GET["mode"]) && (($_GET["mode"] == "raw") || ($_GET["mode"] == "minimal"))) {
$doc = new DOMDocument();

View File

@ -23,10 +23,13 @@ namespace Friendica;
use Friendica\App\Router;
use Friendica\Capabilities\ICanHandleRequests;
use Friendica\Capabilities\ICanReadAndWriteToResponds;
use Friendica\Capabilities\IRespondToRequests;
use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\Logger;
use Friendica\Model\User;
use Friendica\Module\Response;
use Friendica\Module\Special\HTTPException as ModuleHTTPException;
use Friendica\Network\HTTPException;
use Friendica\Util\Profiler;
@ -57,8 +60,10 @@ abstract class BaseModule implements ICanHandleRequests
protected $profiler;
/** @var array */
protected $server;
/** @var ICanReadAndWriteToResponds */
protected $response;
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, array $server, array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
{
$this->parameters = $parameters;
$this->l10n = $l10n;
@ -67,6 +72,7 @@ abstract class BaseModule implements ICanHandleRequests
$this->logger = $logger;
$this->profiler = $profiler;
$this->server = $server;
$this->response = $response;
}
/**
@ -171,7 +177,7 @@ abstract class BaseModule implements ICanHandleRequests
/**
* {@inheritDoc}
*/
public function run(array $post = [], array $request = []): string
public function run(array $post = [], array $request = []): IRespondToRequests
{
// @see https://github.com/tootsuite/mastodon/blob/c3aef491d66aec743a3a53e934a494f653745b61/config/initializers/cors.rb
if (substr($request['pagename'] ?? '', 0, 12) == '.well-known/') {
@ -205,24 +211,27 @@ abstract class BaseModule implements ICanHandleRequests
Core\Hook::callAll($this->args->getModuleName() . '_mod_init', $placeholder);
$this->profiler->set(microtime(true) - $timestamp, 'init');
$this->response->setType(IRespondToRequests::TYPE_CONTENT);
if ($this->server['REQUEST_METHOD'] === Router::DELETE) {
switch ($this->server['REQUEST_METHOD']) {
case Router::DELETE:
$this->response->setType(IRespondToRequests::TYPE_DELETE);
$this->delete();
}
if ($this->server['REQUEST_METHOD'] === Router::PATCH) {
break;
case Router::PATCH:
$this->response->setType(IRespondToRequests::TYPE_PATCH);
$this->patch();
}
if ($this->server['REQUEST_METHOD'] === Router::POST) {
break;
case Router::POST:
Core\Hook::callAll($this->args->getModuleName() . '_mod_post', $post);
$this->response->setType(IRespondToRequests::TYPE_POST);
$this->post($request, $post);
}
if ($this->server['REQUEST_METHOD'] === Router::PUT) {
break;
case Router::PUT:
$this->response->setType(IRespondToRequests::TYPE_PUT);
$this->put();
}
break;
default:
// "rawContent" is especially meant for technical endpoints.
// This endpoint doesn't need any theme initialization or other comparable stuff.
$this->rawContent($request);
@ -230,11 +239,15 @@ abstract class BaseModule implements ICanHandleRequests
try {
$arr = ['content' => ''];
Hook::callAll(static::class . '_mod_content', $arr);
$content = $arr['content'];
return $content . $this->content($_REQUEST);
$this->response->addContent($arr['content']);
$this->response->addContent($this->content($_REQUEST));
} catch (HTTPException $e) {
return (new ModuleHTTPException())->content($e);
$this->response->addContent((new ModuleHTTPException())->content($e));
}
break;
}
return $this->response;
}
/*

View File

@ -13,9 +13,9 @@ interface ICanHandleRequests
* @param array $post The $_POST content (in case of POST)
* @param array $request The $_REQUEST content (in case of GET, POST)
*
* @return string Returns the content of the module as string
* @return IRespondToRequests responding to the request handling
*
* @throws HTTPException\InternalServerErrorException
*/
public function run(array $post = [], array $request = []): string;
public function run(array $post = [], array $request = []): IRespondToRequests;
}

View File

@ -0,0 +1,32 @@
<?php
namespace Friendica\Capabilities;
use Friendica\Network\HTTPException\InternalServerErrorException;
interface ICanReadAndWriteToResponds extends IRespondToRequests
{
/**
* Adds a header entry to the module response
*
* @param string $key
* @param string $value
*/
public function addHeader(string $key, string $value);
/**
* Adds output content to the module response
*
* @param string $content
*/
public function addContent(string $content);
/**
* Sets the response type of the current request
*
* @param string $type
*
* @throws InternalServerErrorException
*/
public function setType(string $type);
}

View File

@ -0,0 +1,43 @@
<?php
namespace Friendica\Capabilities;
interface IRespondToRequests
{
const TYPE_CONTENT = 'content';
const TYPE_RAW_CONTENT = 'rawContent';
const TYPE_POST = 'post';
const TYPE_PUT = 'put';
const TYPE_DELETE = 'delete';
const TYPE_PATCH = 'patch';
const ALLOWED_TYPES = [
self::TYPE_CONTENT,
self::TYPE_RAW_CONTENT,
self::TYPE_POST,
self::TYPE_PUT,
self::TYPE_DELETE,
self::TYPE_PATCH,
];
/**
* Returns all set headers during the module execution
*
* @return string[][]
*/
public function getHeaders(): array;
/**
* Returns the output of the module
*
* @return string
*/
public function getContent(): string;
/**
* Returns the response type of the current request
*
* @return string
*/
public function getTyp(): string;
}

View File

@ -22,6 +22,7 @@
namespace Friendica;
use Friendica\Core\L10n;
use Friendica\Module\Response;
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
@ -41,9 +42,9 @@ class LegacyModule extends BaseModule
*/
private $moduleName = '';
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, array $server, string $file_path = '', array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, string $file_path = '', array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->setModuleFile($file_path);

View File

@ -25,6 +25,7 @@ use Friendica\App;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Module\BaseAdmin;
use Friendica\Module\Response;
use Friendica\Util\Profiler;
use Friendica\Util\Strings;
use Psr\Log\LoggerInterface;
@ -36,9 +37,9 @@ class Embed extends BaseAdmin
/** @var App\Mode */
protected $mode;
public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, App\Mode $mode, array $server, array $parameters = [])
public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, App\Mode $mode, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->app = $app;
$this->mode = $mode;

View File

@ -22,11 +22,11 @@
namespace Friendica\Module\Admin;
use Friendica\App;
use Friendica\App\BaseURL;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Module\BaseAdmin;
use Friendica\Module\Response;
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
@ -37,9 +37,9 @@ class Tos extends BaseAdmin
/** @var IManageConfigValues */
protected $config;
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, \Friendica\Module\Tos $tos, IManageConfigValues $config, array $server, array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, \Friendica\Module\Tos $tos, IManageConfigValues $config, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->tos = $tos;
$this->config = $config;

View File

@ -29,6 +29,7 @@ use Friendica\Model\Profile;
use Friendica\Model\User;
use Friendica\Module\BaseApi;
use Friendica\Model\Contact;
use Friendica\Module\Response;
use Friendica\Network\HTTPException;
use Friendica\Util\Profiler;
use Friendica\Util\Strings;
@ -39,9 +40,9 @@ abstract class ContactEndpoint extends BaseApi
const DEFAULT_COUNT = 20;
const MAX_COUNT = 200;
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, array $server, array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
self::checkAllowedScope(self::SCOPE_READ);
}

View File

@ -36,9 +36,9 @@ use Psr\Log\LoggerInterface;
*/
class Apps extends BaseModule
{
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, IManageConfigValues $config, array $server, array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IManageConfigValues $config, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$privateaddons = $config->get('config', 'private_addons');
if ($privateaddons === "1" && !local_user()) {

View File

@ -89,9 +89,9 @@ abstract class BaseNotifications extends BaseModule
*/
abstract public function getNotifications();
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, array $server, array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
if (!local_user()) {
throw new ForbiddenException($this->t('Permission denied.'));

View File

@ -28,10 +28,8 @@ use Friendica\DI;
class BaseSettings extends BaseModule
{
protected function content(array $request = []): string
public static function createAside()
{
$a = DI::app();
$tpl = Renderer::getMarkupTemplate('settings/head.tpl');
DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl, [
'$ispublic' => DI::l10n()->t('everybody')
@ -125,6 +123,13 @@ class BaseSettings extends BaseModule
'$class' => 'settings-widget',
'$items' => $tabs,
]);
}
protected function content(array $request = []): string
{
$a = DI::app();
static::createAside();
return '';
}

View File

@ -32,6 +32,7 @@ use Friendica\Core\Session;
use Friendica\Database\Database;
use Friendica\Model;
use Friendica\Module\Contact;
use Friendica\Module\Response;
use Friendica\Network\HTTPException\BadRequestException;
use Friendica\Network\HTTPException\ForbiddenException;
use Friendica\Util\Profiler;
@ -48,9 +49,9 @@ class Advanced extends BaseModule
/** @var Page */
protected $page;
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, App\Page $page, LoggerInterface $logger, Profiler $profiler, Database $dba, array $server, array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, App\Page $page, LoggerInterface $logger, Profiler $profiler, Response $response, Database $dba, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->dba = $dba;
$this->page = $page;

View File

@ -30,6 +30,7 @@ use Friendica\Core\Renderer;
use Friendica\Database\Database;
use Friendica\Model;
use Friendica\Module\Contact;
use Friendica\Module\Response;
use Friendica\Module\Security\Login;
use Friendica\Network\HTTPException;
use Friendica\Util\Profiler;
@ -43,9 +44,9 @@ class Revoke extends BaseModule
/** @var Database */
protected $dba;
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Database $dba, array $server, array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Database $dba, Response $response, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->dba = $dba;

View File

@ -26,6 +26,7 @@ use Friendica\BaseModule;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Model;
use Friendica\Module\Response;
use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests;
use Friendica\Protocol;
use Friendica\Util\Profiler;
@ -39,9 +40,9 @@ class Feed extends BaseModule
/** @var ICanSendHttpRequests */
protected $httpClient;
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ICanSendHttpRequests $httpClient, array $server, array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, ICanSendHttpRequests $httpClient, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->httpClient = $httpClient;

View File

@ -26,6 +26,7 @@ use Friendica\BaseModule;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\L10n;
use Friendica\Model\User;
use Friendica\Module\Response;
use Friendica\Network\HTTPException;
use Friendica\Protocol\Diaspora;
use Friendica\Util\Network;
@ -41,9 +42,9 @@ class Receive extends BaseModule
/** @var IManageConfigValues */
protected $config;
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, IManageConfigValues $config, array $server, array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IManageConfigValues $config, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->config = $config;
}

View File

@ -27,6 +27,7 @@ use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Database\DBA;
use Friendica\Model;
use Friendica\Module\Response;
use Friendica\Network\HTTPException;
use Friendica\Util\Profiler;
use Friendica\Util\XML;
@ -37,9 +38,9 @@ use Psr\Log\LoggerInterface;
*/
class SaveTag extends BaseModule
{
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, array $server, array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
if (!local_user()) {
notice($this->t('You must be logged in to use this module'));

View File

@ -48,9 +48,9 @@ class FriendSuggest extends BaseModule
/** @var \Friendica\Contact\FriendSuggest\Factory\FriendSuggest */
protected $friendSuggestFac;
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler,Database $dba, \Friendica\Contact\FriendSuggest\Repository\FriendSuggest $friendSuggestRepo, \Friendica\Contact\FriendSuggest\Factory\FriendSuggest $friendSuggestFac, array $server, array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, Database $dba, \Friendica\Contact\FriendSuggest\Repository\FriendSuggest $friendSuggestRepo, \Friendica\Contact\FriendSuggest\Factory\FriendSuggest $friendSuggestFac, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
if (!local_user()) {
throw new ForbiddenException($this->t('Permission denied.'));

View File

@ -73,9 +73,9 @@ class Install extends BaseModule
/** @var App\Mode */
protected $mode;
public function __construct(App $app, App\Mode $mode, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Core\Installer $installer, array $server, array $parameters = [])
public function __construct(App $app, App\Mode $mode, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, Core\Installer $installer, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->app = $app;
$this->mode = $mode;

View File

@ -49,9 +49,9 @@ class Magic extends BaseModule
/** @var ICanSendHttpRequests */
protected $httpClient;
public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Database $dba, ICanSendHttpRequests $httpClient, array $server, array $parameters = [])
public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, Database $dba, ICanSendHttpRequests $httpClient, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->app = $app;
$this->dba = $dba;

View File

@ -32,6 +32,7 @@ use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Model\User;
use Friendica\Module\BaseNotifications;
use Friendica\Module\Response;
use Friendica\Navigation\Notifications\Factory\Introduction as IntroductionFactory;
use Friendica\Navigation\Notifications\ValueObject\Introduction;
use Friendica\Util\Profiler;
@ -47,9 +48,9 @@ class Introductions extends BaseNotifications
/** @var Mode */
protected $mode;
public function __construct(L10n $l10n, App\BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Mode $mode, IntroductionFactory $notificationIntro, array $server, array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, Mode $mode, IntroductionFactory $notificationIntro, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->notificationIntro = $notificationIntro;
$this->mode = $mode;

View File

@ -27,6 +27,7 @@ use Friendica\Content\Nav;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Module\BaseNotifications;
use Friendica\Module\Response;
use Friendica\Navigation\Notifications\ValueObject\FormattedNotification;
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
@ -43,9 +44,9 @@ class Notifications extends BaseNotifications
/** @var \Friendica\Navigation\Notifications\Factory\FormattedNotification */
protected $formattedNotificationFactory;
public function __construct(L10n $l10n, App\BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, \Friendica\Navigation\Notifications\Factory\FormattedNotification $formattedNotificationFactory, array $server, array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, \Friendica\Navigation\Notifications\Factory\FormattedNotification $formattedNotificationFactory, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->formattedNotificationFactory = $formattedNotificationFactory;
}

View File

@ -37,11 +37,11 @@ class Index extends BaseModule
{
protected function rawContent(array $request = [])
{
(new Profile($this->l10n, $this->baseUrl, $this->args, $this->logger, $this->profiler, $this->server, $this->parameters))->rawContent();
(new Profile($this->l10n, $this->baseUrl, $this->args, $this->logger, $this->profiler, $this->response, $this->server, $this->parameters))->rawContent();
}
protected function content(array $request = []): string
{
return (new Status($this->l10n, $this->baseUrl, $this->args, $this->logger, $this->profiler, $this->server, $this->parameters))->content();
return (new Status($this->l10n, $this->baseUrl, $this->args, $this->logger, $this->profiler, $this->response, $this->server, $this->parameters))->content();
}
}

View File

@ -49,9 +49,9 @@ class Register extends BaseModule
/** @var Tos */
protected $tos;
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Tos $tos, array $server, array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, Tos $tos, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->tos = $tos;
}

View File

@ -49,9 +49,9 @@ class RemoteFollow extends BaseModule
/** @var Page */
protected $page;
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, App\Page $page, LoggerInterface $logger, Profiler $profiler, array $server, array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, App\Page $page, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->owner = User::getOwnerDataByNick($this->parameters['profile']);
if (!$this->owner) {

75
src/Module/Response.php Normal file
View File

@ -0,0 +1,75 @@
<?php
namespace Friendica\Module;
use Friendica\Capabilities\ICanReadAndWriteToResponds;
use Friendica\Capabilities\IRespondToRequests;
use Friendica\Network\HTTPException\InternalServerErrorException;
class Response implements ICanReadAndWriteToResponds
{
/**
* @var string[][]
*/
protected $headers = [];
/**
* @var string
*/
protected $content = '';
/**
* @var string
*/
protected $type = IRespondToRequests::TYPE_CONTENT;
/**
* {@inheritDoc}
*/
public function addHeader(string $key, string $value)
{
$this->headers[$key][] = $value;
}
/**
* {@inheritDoc}
*/
public function addContent(string $content)
{
$this->content .= $content;
}
/**
* {@inheritDoc}
*/
public function getHeaders(): array
{
return $this->headers;
}
/**
* {@inheritDoc}
*/
public function getContent(): string
{
return $this->content;
}
/**
* {@inheritDoc}
*/
public function setType(string $type)
{
if (!in_array($type, IRespondToRequests::ALLOWED_TYPES)) {
throw new InternalServerErrorException('wrong type');
}
$this->type = $type;
}
/**
* {@inheritDoc}
*/
public function getTyp(): string
{
return $this->type;
}
}

View File

@ -26,6 +26,7 @@ use Friendica\BaseModule;
use Friendica\Core\L10n;
use Friendica\Core\Search;
use Friendica\Database\Database;
use Friendica\Module\Response;
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
@ -34,9 +35,9 @@ class Saved extends BaseModule
/** @var Database */
protected $dba;
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Database $dba, array $server, array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, Database $dba, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->dba = $dba;
}

View File

@ -30,6 +30,7 @@ use Friendica\Core\Session\Capability\IHandleSessions;
use Friendica\Core\System;
use Friendica\Model\Profile;
use Friendica\Model\User\Cookie;
use Friendica\Module\Response;
use Friendica\Security\TwoFactor;
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
@ -48,9 +49,9 @@ class Logout extends BaseModule
/** @var TwoFactor\Repository\TrustedBrowser */
protected $trustedBrowserRepo;
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, TwoFactor\Repository\TrustedBrowser $trustedBrowserRepo, ICanCache $cache, Cookie $cookie, IHandleSessions $session, array $server, array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, TwoFactor\Repository\TrustedBrowser $trustedBrowserRepo, ICanCache $cache, Cookie $cookie, IHandleSessions $session, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->cache = $cache;
$this->cookie = $cookie;

View File

@ -27,6 +27,7 @@ use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Core\Session\Capability\IHandleSessions;
use Friendica\Model\User;
use Friendica\Module\Response;
use Friendica\Security\Authentication;
use Friendica\Security\TwoFactor\Model\RecoveryCode;
use Friendica\Util\Profiler;
@ -46,9 +47,9 @@ class Recovery extends BaseModule
/** @var Authentication */
protected $auth;
public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Authentication $auth, IHandleSessions $session, array $server, array $parameters = [])
public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, Authentication $auth, IHandleSessions $session, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->app = $app;
$this->auth = $auth;

View File

@ -25,6 +25,7 @@ use Friendica\App;
use Friendica\Core\L10n;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Renderer;
use Friendica\Module\Response;
use Friendica\Security\TwoFactor\Model\AppSpecificPassword;
use Friendica\Module\BaseSettings;
use Friendica\Module\Security\Login;
@ -43,9 +44,9 @@ class AppSpecific extends BaseSettings
/** @var IManagePersonalConfigValues */
protected $pConfig;
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, IManagePersonalConfigValues $pConfig, array $server, array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IManagePersonalConfigValues $pConfig, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->pConfig = $pConfig;

View File

@ -25,6 +25,7 @@ use Friendica\App;
use Friendica\Core\L10n;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Renderer;
use Friendica\Module\Response;
use Friendica\Security\TwoFactor\Model\RecoveryCode;
use Friendica\Module\BaseSettings;
use Friendica\Module\Security\Login;
@ -41,9 +42,9 @@ class Recovery extends BaseSettings
/** @var IManagePersonalConfigValues */
protected $pConfig;
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, IManagePersonalConfigValues $pConfig, array $server, array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IManagePersonalConfigValues $pConfig, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->pConfig = $pConfig;

View File

@ -7,6 +7,7 @@ use Friendica\Core\L10n;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Renderer;
use Friendica\Module\BaseSettings;
use Friendica\Module\Response;
use Friendica\Security\TwoFactor;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Profiler;
@ -24,9 +25,9 @@ class Trusted extends BaseSettings
/** @var TwoFactor\Repository\TrustedBrowser */
protected $trustedBrowserRepo;
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, IManagePersonalConfigValues $pConfig, TwoFactor\Repository\TrustedBrowser $trustedBrowserRepo, array $server, array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IManagePersonalConfigValues $pConfig, TwoFactor\Repository\TrustedBrowser $trustedBrowserRepo, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->pConfig = $pConfig;
$this->trustedBrowserRepo = $trustedBrowserRepo;

View File

@ -31,6 +31,7 @@ use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Module\BaseSettings;
use Friendica\Module\Response;
use Friendica\Module\Security\Login;
use Friendica\Util\Profiler;
use PragmaRX\Google2FA\Google2FA;
@ -46,9 +47,9 @@ class Verify extends BaseSettings
/** @var IManagePersonalConfigValues */
protected $pConfig;
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, IManagePersonalConfigValues $pConfig, array $server, array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IManagePersonalConfigValues $pConfig, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->pConfig = $pConfig;

View File

@ -35,9 +35,9 @@ class Statistics extends BaseModule
/** @var IManageConfigValues */
protected $config;
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, IManageConfigValues $config, array $server, array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, IManageConfigValues $config, Response $response, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->config = $config;

View File

@ -48,9 +48,9 @@ class Tos extends BaseModule
* be properties of the class, however cannot be set directly as the property
* cannot depend on a function result when declaring the variable.
**/
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, IManageConfigValues $config, array $server, array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IManageConfigValues $config, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->config = $config;