Make BaseModule a real entity

- Add all dependencies, necessary to run the content (baseUrl, Arguments)
- Encapsulate all POST/GET/DELETE/PATCH/PUT methods as protected methods inside the BaseModule
- Return Module content ONLY per `BaseModule::run()` (including the Hook logic there as well)
This commit is contained in:
Philipp 2021-11-20 15:38:03 +01:00
parent 238613fd01
commit 8bdd90066f
No known key found for this signature in database
GPG key ID: 24A7501396EB5432
252 changed files with 615 additions and 623 deletions

View file

@ -21,6 +21,7 @@
namespace Friendica\Module\Notifications;
use Friendica\App;
use Friendica\App\Arguments;
use Friendica\App\Mode;
use Friendica\Content\ContactSelector;
@ -33,6 +34,8 @@ use Friendica\Model\User;
use Friendica\Module\BaseNotifications;
use Friendica\Navigation\Notifications\Factory\Introduction as IntroductionFactory;
use Friendica\Navigation\Notifications\ValueObject\Introduction;
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
/**
* Prints notifications about introduction
@ -44,9 +47,9 @@ class Introductions extends BaseNotifications
/** @var Mode */
protected $mode;
public function __construct(Mode $mode, IntroductionFactory $notificationIntro, Arguments $args, L10n $l10n, array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Mode $mode, IntroductionFactory $notificationIntro, array $server, array $parameters = [])
{
parent::__construct($args, $l10n, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
$this->notificationIntro = $notificationIntro;
$this->mode = $mode;
@ -71,7 +74,7 @@ class Introductions extends BaseNotifications
];
}
public function content(): string
protected function content(array $request = []): string
{
Nav::setSelected('introductions');

View file

@ -42,7 +42,7 @@ class Notification extends BaseModule
* @throws \ImagickException
* @throws \Exception
*/
public function post()
protected function post(array $request = [], array $post = [])
{
if (!local_user()) {
throw new HTTPException\UnauthorizedException(DI::l10n()->t('Permission denied.'));
@ -73,7 +73,7 @@ class Notification extends BaseModule
*
* @throws HTTPException\UnauthorizedException
*/
public function rawContent()
protected function rawContent(array $request = [])
{
if (!local_user()) {
throw new HTTPException\UnauthorizedException(DI::l10n()->t('Permission denied.'));
@ -101,7 +101,7 @@ class Notification extends BaseModule
* @throws HTTPException\InternalServerErrorException
* @throws \Exception
*/
public function content(): string
protected function content(array $request = []): string
{
if (!local_user()) {
notice(DI::l10n()->t('You must be logged in to show this page.'));

View file

@ -21,13 +21,15 @@
namespace Friendica\Module\Notifications;
use Friendica\App;
use Friendica\App\Arguments;
use Friendica\App\BaseURL;
use Friendica\Content\Nav;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Module\BaseNotifications;
use Friendica\Navigation\Notifications\ValueObject\FormattedNotification;
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
/**
* Prints all notification types except introduction:
@ -41,15 +43,11 @@ class Notifications extends BaseNotifications
/** @var \Friendica\Navigation\Notifications\Factory\FormattedNotification */
protected $formattedNotificationFactory;
/** @var BaseURL */
protected $baseUrl;
public function __construct(BaseURL $baseUrl, \Friendica\Navigation\Notifications\Factory\FormattedNotification $formattedNotificationFactory, Arguments $args, L10n $l10n, array $parameters = [])
public function __construct(L10n $l10n, App\BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, \Friendica\Navigation\Notifications\Factory\FormattedNotification $formattedNotificationFactory, array $server, array $parameters = [])
{
parent::__construct($args, $l10n, $parameters);
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
$this->formattedNotificationFactory = $formattedNotificationFactory;
$this->baseUrl = $baseUrl;
}
/**
@ -96,7 +94,7 @@ class Notifications extends BaseNotifications
];
}
public function content(): string
protected function content(array $request = []): string
{
Nav::setSelected('notifications');