From 561aba18e3a230c0912ad9483c6df43cc40e09d6 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 21 Nov 2021 20:06:36 +0100 Subject: [PATCH] Introduce `Response` for Modules to create a testable way for module responses --- mod/settings.php | 8 +- src/App.php | 4 +- src/App/Page.php | 39 ++++++---- src/BaseModule.php | 75 +++++++++++-------- src/Capabilities/ICanHandleRequests.php | 4 +- .../ICanReadAndWriteToResponds.php | 32 ++++++++ src/Capabilities/IRespondToRequests.php | 43 +++++++++++ src/LegacyModule.php | 5 +- src/Module/Admin/Themes/Embed.php | 5 +- src/Module/Admin/Tos.php | 6 +- src/Module/Api/Twitter/ContactEndpoint.php | 5 +- src/Module/Apps.php | 4 +- src/Module/BaseNotifications.php | 4 +- src/Module/BaseSettings.php | 11 ++- src/Module/Contact/Advanced.php | 5 +- src/Module/Contact/Revoke.php | 5 +- src/Module/Debug/Feed.php | 5 +- src/Module/Diaspora/Receive.php | 5 +- src/Module/Filer/SaveTag.php | 5 +- src/Module/FriendSuggest.php | 4 +- src/Module/Install.php | 4 +- src/Module/Magic.php | 4 +- src/Module/Notifications/Introductions.php | 5 +- src/Module/Notifications/Notifications.php | 5 +- src/Module/Profile/Index.php | 4 +- src/Module/Register.php | 4 +- src/Module/RemoteFollow.php | 4 +- src/Module/Response.php | 75 +++++++++++++++++++ src/Module/Search/Saved.php | 5 +- src/Module/Security/Logout.php | 5 +- src/Module/Security/TwoFactor/Recovery.php | 5 +- src/Module/Settings/TwoFactor/AppSpecific.php | 5 +- src/Module/Settings/TwoFactor/Recovery.php | 5 +- src/Module/Settings/TwoFactor/Trusted.php | 5 +- src/Module/Settings/TwoFactor/Verify.php | 5 +- src/Module/Statistics.php | 4 +- src/Module/Tos.php | 4 +- 37 files changed, 309 insertions(+), 113 deletions(-) create mode 100644 src/Capabilities/ICanReadAndWriteToResponds.php create mode 100644 src/Capabilities/IRespondToRequests.php create mode 100644 src/Module/Response.php diff --git a/mod/settings.php b/mod/settings.php index 080bcdeb9..1643b19fc 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -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()); diff --git a/src/App.php b/src/App.php index 14980896e..f3f7429db 100644 --- a/src/App.php +++ b/src/App.php @@ -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); } diff --git a/src/App/Page.php b/src/App/Page.php index d302ef6c2..7996dca94 100644 --- a/src/App/Page.php +++ b/src/App/Page.php @@ -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 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(); } /** @@ -373,18 +374,18 @@ class Page implements ArrayAccess /** * 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(); @@ -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(); diff --git a/src/BaseModule.php b/src/BaseModule.php index 65fc8f307..c68af875d 100644 --- a/src/BaseModule.php +++ b/src/BaseModule.php @@ -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,36 +211,43 @@ 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) { - $this->delete(); + 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::PATCH) { - $this->patch(); - } - - if ($this->server['REQUEST_METHOD'] === Router::POST) { - Core\Hook::callAll($this->args->getModuleName() . '_mod_post', $post); - $this->post($request, $post); - } - - 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; } /* @@ -250,9 +263,9 @@ abstract class BaseModule implements ICanHandleRequests */ 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; } diff --git a/src/Capabilities/ICanHandleRequests.php b/src/Capabilities/ICanHandleRequests.php index 6c4ae5138..ceb580875 100644 --- a/src/Capabilities/ICanHandleRequests.php +++ b/src/Capabilities/ICanHandleRequests.php @@ -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; } diff --git a/src/Capabilities/ICanReadAndWriteToResponds.php b/src/Capabilities/ICanReadAndWriteToResponds.php new file mode 100644 index 000000000..6b8ed5ad3 --- /dev/null +++ b/src/Capabilities/ICanReadAndWriteToResponds.php @@ -0,0 +1,32 @@ +setModuleFile($file_path); diff --git a/src/Module/Admin/Themes/Embed.php b/src/Module/Admin/Themes/Embed.php index 17a573a1d..1eb3018d5 100644 --- a/src/Module/Admin/Themes/Embed.php +++ b/src/Module/Admin/Themes/Embed.php @@ -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; diff --git a/src/Module/Admin/Tos.php b/src/Module/Admin/Tos.php index c8fc6703c..ecf2cdc5b 100644 --- a/src/Module/Admin/Tos.php +++ b/src/Module/Admin/Tos.php @@ -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; diff --git a/src/Module/Api/Twitter/ContactEndpoint.php b/src/Module/Api/Twitter/ContactEndpoint.php index a0e5ab11e..2b2936820 100644 --- a/src/Module/Api/Twitter/ContactEndpoint.php +++ b/src/Module/Api/Twitter/ContactEndpoint.php @@ -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); } diff --git a/src/Module/Apps.php b/src/Module/Apps.php index bb3b64aec..6b8d18b94 100644 --- a/src/Module/Apps.php +++ b/src/Module/Apps.php @@ -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()) { diff --git a/src/Module/BaseNotifications.php b/src/Module/BaseNotifications.php index bea0147dd..bd19fb477 100644 --- a/src/Module/BaseNotifications.php +++ b/src/Module/BaseNotifications.php @@ -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.')); diff --git a/src/Module/BaseSettings.php b/src/Module/BaseSettings.php index d0a7d0b6c..ff8d2c3af 100644 --- a/src/Module/BaseSettings.php +++ b/src/Module/BaseSettings.php @@ -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 ''; } diff --git a/src/Module/Contact/Advanced.php b/src/Module/Contact/Advanced.php index e34d6321b..2d99abf72 100644 --- a/src/Module/Contact/Advanced.php +++ b/src/Module/Contact/Advanced.php @@ -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; diff --git a/src/Module/Contact/Revoke.php b/src/Module/Contact/Revoke.php index edb3e6586..4c3a6dade 100644 --- a/src/Module/Contact/Revoke.php +++ b/src/Module/Contact/Revoke.php @@ -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; diff --git a/src/Module/Debug/Feed.php b/src/Module/Debug/Feed.php index d85a85819..5d6d03658 100644 --- a/src/Module/Debug/Feed.php +++ b/src/Module/Debug/Feed.php @@ -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; diff --git a/src/Module/Diaspora/Receive.php b/src/Module/Diaspora/Receive.php index 60a9716f4..242b774b3 100644 --- a/src/Module/Diaspora/Receive.php +++ b/src/Module/Diaspora/Receive.php @@ -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; } diff --git a/src/Module/Filer/SaveTag.php b/src/Module/Filer/SaveTag.php index 26801d3e9..3adf4f1fb 100644 --- a/src/Module/Filer/SaveTag.php +++ b/src/Module/Filer/SaveTag.php @@ -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')); diff --git a/src/Module/FriendSuggest.php b/src/Module/FriendSuggest.php index 79d5fd813..153f86d60 100644 --- a/src/Module/FriendSuggest.php +++ b/src/Module/FriendSuggest.php @@ -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.')); diff --git a/src/Module/Install.php b/src/Module/Install.php index a65e699af..2b287d96b 100644 --- a/src/Module/Install.php +++ b/src/Module/Install.php @@ -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; diff --git a/src/Module/Magic.php b/src/Module/Magic.php index 10c30c57a..c861d3054 100644 --- a/src/Module/Magic.php +++ b/src/Module/Magic.php @@ -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; diff --git a/src/Module/Notifications/Introductions.php b/src/Module/Notifications/Introductions.php index 10d2bbb9f..f8eacb85e 100644 --- a/src/Module/Notifications/Introductions.php +++ b/src/Module/Notifications/Introductions.php @@ -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; diff --git a/src/Module/Notifications/Notifications.php b/src/Module/Notifications/Notifications.php index 6b9a9fa28..5ed8a0141 100644 --- a/src/Module/Notifications/Notifications.php +++ b/src/Module/Notifications/Notifications.php @@ -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; } diff --git a/src/Module/Profile/Index.php b/src/Module/Profile/Index.php index 3f7b3d3fd..6980380fc 100644 --- a/src/Module/Profile/Index.php +++ b/src/Module/Profile/Index.php @@ -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(); } } diff --git a/src/Module/Register.php b/src/Module/Register.php index 90c300781..baadef489 100644 --- a/src/Module/Register.php +++ b/src/Module/Register.php @@ -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; } diff --git a/src/Module/RemoteFollow.php b/src/Module/RemoteFollow.php index ee74078dd..ee2dcfe4d 100644 --- a/src/Module/RemoteFollow.php +++ b/src/Module/RemoteFollow.php @@ -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) { diff --git a/src/Module/Response.php b/src/Module/Response.php new file mode 100644 index 000000000..87fbbf07c --- /dev/null +++ b/src/Module/Response.php @@ -0,0 +1,75 @@ +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; + } +} diff --git a/src/Module/Search/Saved.php b/src/Module/Search/Saved.php index fd20352bf..9dd1ed019 100644 --- a/src/Module/Search/Saved.php +++ b/src/Module/Search/Saved.php @@ -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; } diff --git a/src/Module/Security/Logout.php b/src/Module/Security/Logout.php index b8bc0f022..f9c702d51 100644 --- a/src/Module/Security/Logout.php +++ b/src/Module/Security/Logout.php @@ -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; diff --git a/src/Module/Security/TwoFactor/Recovery.php b/src/Module/Security/TwoFactor/Recovery.php index 6b5c86e66..6556e07c2 100644 --- a/src/Module/Security/TwoFactor/Recovery.php +++ b/src/Module/Security/TwoFactor/Recovery.php @@ -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; diff --git a/src/Module/Settings/TwoFactor/AppSpecific.php b/src/Module/Settings/TwoFactor/AppSpecific.php index d87f27ecc..94dfc6d41 100644 --- a/src/Module/Settings/TwoFactor/AppSpecific.php +++ b/src/Module/Settings/TwoFactor/AppSpecific.php @@ -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; diff --git a/src/Module/Settings/TwoFactor/Recovery.php b/src/Module/Settings/TwoFactor/Recovery.php index 0d324aaca..fb13b8b60 100644 --- a/src/Module/Settings/TwoFactor/Recovery.php +++ b/src/Module/Settings/TwoFactor/Recovery.php @@ -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; diff --git a/src/Module/Settings/TwoFactor/Trusted.php b/src/Module/Settings/TwoFactor/Trusted.php index 4e6068e23..1507d5fc5 100644 --- a/src/Module/Settings/TwoFactor/Trusted.php +++ b/src/Module/Settings/TwoFactor/Trusted.php @@ -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; diff --git a/src/Module/Settings/TwoFactor/Verify.php b/src/Module/Settings/TwoFactor/Verify.php index 29569dae0..3c1853d7f 100644 --- a/src/Module/Settings/TwoFactor/Verify.php +++ b/src/Module/Settings/TwoFactor/Verify.php @@ -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; diff --git a/src/Module/Statistics.php b/src/Module/Statistics.php index 408999b57..823b399a5 100644 --- a/src/Module/Statistics.php +++ b/src/Module/Statistics.php @@ -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; diff --git a/src/Module/Tos.php b/src/Module/Tos.php index 53ef94920..78e4df69c 100644 --- a/src/Module/Tos.php +++ b/src/Module/Tos.php @@ -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;