return;
}
- BaseSettings::content();
+ BaseSettings::createAside();
}
function settings_post(App $a)
if (!empty($_SESSION['submanage'])) {
notice(DI::l10n()->t('Permission denied.'));
- return;
+ return '';
}
if ((DI::args()->getArgc() > 1) && (DI::args()->getArgv()[1] === 'oauth')) {
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()]);
$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());
}
// 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);
}
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;
* - module content
* - hooks for content
*
- * @param string $content The content to print
- * @param Mode $mode The Friendica execution mode
+ * @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();
}
/**
/**
* Executes the creation of the current page and prints it to the screen
*
- * @param App $app The Friendica App
- * @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 L10n $l10n The l10n language class
- * @param IManageConfigValues $config The Configuration of this node
- * @param IManagePersonalConfigValues $pconfig The personal/user configuration
+ * @param App $app The Friendica App
+ * @param BaseURL $baseURL The Friendica Base URL
+ * @param Arguments $args The Friendica App arguments
+ * @param Mode $mode The current node mode
+ * @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();
* 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
$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();
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;
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;
$this->logger = $logger;
$this->profiler = $profiler;
$this->server = $server;
+ $this->response = $response;
}
/**
/**
* {@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/') {
Core\Hook::callAll($this->args->getModuleName() . '_mod_init', $placeholder);
$this->profiler->set(microtime(true) - $timestamp, 'init');
-
- if ($this->server['REQUEST_METHOD'] === Router::DELETE) {
- $this->delete();
- }
-
- if ($this->server['REQUEST_METHOD'] === Router::PATCH) {
- $this->patch();
- }
-
- if ($this->server['REQUEST_METHOD'] === Router::POST) {
- Core\Hook::callAll($this->args->getModuleName() . '_mod_post', $post);
- $this->post($request, $post);
+ $this->response->setType(IRespondToRequests::TYPE_CONTENT);
+
+ switch ($this->server['REQUEST_METHOD']) {
+ case Router::DELETE:
+ $this->response->setType(IRespondToRequests::TYPE_DELETE);
+ $this->delete();
+ break;
+ case Router::PATCH:
+ $this->response->setType(IRespondToRequests::TYPE_PATCH);
+ $this->patch();
+ break;
+ case Router::POST:
+ Core\Hook::callAll($this->args->getModuleName() . '_mod_post', $post);
+ $this->response->setType(IRespondToRequests::TYPE_POST);
+ $this->post($request, $post);
+ 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);
+
+ try {
+ $arr = ['content' => ''];
+ Hook::callAll(static::class . '_mod_content', $arr);
+ $this->response->addContent($arr['content']);
+ $this->response->addContent($this->content($_REQUEST));
+ } catch (HTTPException $e) {
+ $this->response->addContent((new ModuleHTTPException())->content($e));
+ }
+ break;
}
- if ($this->server['REQUEST_METHOD'] === Router::PUT) {
- $this->put();
- }
-
- // "rawContent" is especially meant for technical endpoints.
- // This endpoint doesn't need any theme initialization or other comparable stuff.
- $this->rawContent($request);
-
- try {
- $arr = ['content' => ''];
- Hook::callAll(static::class . '_mod_content', $arr);
- $content = $arr['content'];
- return $content . $this->content($_REQUEST);
- } catch (HTTPException $e) {
- return (new ModuleHTTPException())->content($e);
- }
+ return $this->response;
}
/*
*/
public static function getFormSecurityToken($typename = '')
{
- $user = User::getById(DI::app()->getLoggedInUserId(), ['guid', 'prvkey']);
+ $user = User::getById(DI::app()->getLoggedInUserId(), ['guid', 'prvkey']);
$timestamp = time();
- $sec_hash = hash('whirlpool', ($user['guid'] ?? '') . ($user['prvkey'] ?? '') . session_id() . $timestamp . $typename);
+ $sec_hash = hash('whirlpool', ($user['guid'] ?? '') . ($user['prvkey'] ?? '') . session_id() . $timestamp . $typename);
return $timestamp . '.' . $sec_hash;
}
* @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;
}
--- /dev/null
+<?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);
+}
--- /dev/null
+<?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;
+}
namespace Friendica;
use Friendica\Core\L10n;
+use Friendica\Module\Response;
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
*/
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);
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;
/** @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;
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;
/** @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;
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;
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);
}
*/
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()) {
*/
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.'));
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')
'$class' => 'settings-widget',
'$items' => $tabs,
]);
+ }
+
+ protected function content(array $request = []): string
+ {
+ $a = DI::app();
+
+ static::createAside();
return '';
}
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;
/** @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;
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;
/** @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;
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;
/** @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;
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;
/** @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;
}
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;
*/
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'));
/** @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.'));
/** @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;
/** @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;
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;
/** @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;
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;
/** @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;
}
{
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();
}
}
/** @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;
}
/** @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) {
--- /dev/null
+<?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;
+ }
+}
use Friendica\Core\L10n;
use Friendica\Core\Search;
use Friendica\Database\Database;
+use Friendica\Module\Response;
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
/** @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;
}
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;
/** @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;
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;
/** @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;
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;
/** @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;
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;
/** @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;
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;
/** @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;
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;
/** @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;
/** @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;
* 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;