From 856f8fb908332a2d3842e752bbf68c3db9b5f49b Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 23 Dec 2024 15:22:27 +0000 Subject: [PATCH 1/4] Move adding Dice rules into App --- index.php | 8 -------- src/App.php | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/index.php b/index.php index f936cd1a3a..8ba10df263 100644 --- a/index.php +++ b/index.php @@ -18,14 +18,6 @@ require __DIR__ . '/vendor/autoload.php'; $request = \GuzzleHttp\Psr7\ServerRequest::fromGlobals(); $dice = (new Dice())->addRules(include __DIR__ . '/static/dependencies.config.php'); -/** @var \Friendica\Core\Addon\Capability\ICanLoadAddons $addonLoader */ -$addonLoader = $dice->create(\Friendica\Core\Addon\Capability\ICanLoadAddons::class); -$dice = $dice->addRules($addonLoader->getActiveAddonConfig('dependencies')); -$dice = $dice->addRule(Friendica\App\Mode::class, ['call' => [['determineRunMode', [false, $request->getServerParams()], Dice::CHAIN_CALL]]]); - -\Friendica\DI::init($dice); - -\Friendica\Core\Logger\Handler\ErrorHandler::register($dice->create(\Psr\Log\LoggerInterface::class)); $a = \Friendica\App::fromDice($dice); diff --git a/src/App.php b/src/App.php index bc3efde176..e3a9ac0936 100644 --- a/src/App.php +++ b/src/App.php @@ -121,6 +121,8 @@ class App public function processRequest(ServerRequestInterface $request, float $start_time): void { + $this->setupContainerForRunningFrontend($request); + $this->requestId = $this->container->create(Request::class)->getRequestId(); $this->auth = $this->container->create(Authentication::class); $this->config = $this->container->create(IManageConfigValues::class); @@ -152,6 +154,18 @@ class App ); } + private function setupContainerForRunningFrontend(ServerRequestInterface $request): void + { + /** @var \Friendica\Core\Addon\Capability\ICanLoadAddons $addonLoader */ + $addonLoader = $this->container->create(\Friendica\Core\Addon\Capability\ICanLoadAddons::class); + $this->container = $this->container->addRules($addonLoader->getActiveAddonConfig('dependencies')); + $this->container = $this->container->addRule(\Friendica\App\Mode::class, ['call' => [['determineRunMode', [false, $request->getServerParams()], Dice::CHAIN_CALL]]]); + + \Friendica\DI::init($this->container); + + \Friendica\Core\Logger\Handler\ErrorHandler::register($this->container->create(\Psr\Log\LoggerInterface::class)); + } + /** * Load the whole app instance */ From 66822c6a81b25d0200291fc94317fd5b78446e48 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 23 Dec 2024 15:26:35 +0000 Subject: [PATCH 2/4] Rename App variable --- index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.php b/index.php index 8ba10df263..9ea262c5e7 100644 --- a/index.php +++ b/index.php @@ -19,6 +19,6 @@ $request = \GuzzleHttp\Psr7\ServerRequest::fromGlobals(); $dice = (new Dice())->addRules(include __DIR__ . '/static/dependencies.config.php'); -$a = \Friendica\App::fromDice($dice); +$app = \Friendica\App::fromDice($dice); -$a->processRequest($request, $start_time); +$app->processRequest($request, $start_time); From 3c4da64348d781f17ac9fb2e7135b4cb422d4147 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 23 Dec 2024 15:28:57 +0000 Subject: [PATCH 3/4] Refactor App::setupContainerForRunningFrontend() --- src/App.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/App.php b/src/App.php index e3a9ac0936..d8f28b89ba 100644 --- a/src/App.php +++ b/src/App.php @@ -158,12 +158,17 @@ class App { /** @var \Friendica\Core\Addon\Capability\ICanLoadAddons $addonLoader */ $addonLoader = $this->container->create(\Friendica\Core\Addon\Capability\ICanLoadAddons::class); + $this->container = $this->container->addRules($addonLoader->getActiveAddonConfig('dependencies')); - $this->container = $this->container->addRule(\Friendica\App\Mode::class, ['call' => [['determineRunMode', [false, $request->getServerParams()], Dice::CHAIN_CALL]]]); + $this->container = $this->container->addRule(Mode::class, [ + 'call' => [ + ['determineRunMode', [false, $request->getServerParams()], Dice::CHAIN_CALL], + ], + ]); \Friendica\DI::init($this->container); - \Friendica\Core\Logger\Handler\ErrorHandler::register($this->container->create(\Psr\Log\LoggerInterface::class)); + \Friendica\Core\Logger\Handler\ErrorHandler::register($this->container->create(LoggerInterface::class)); } /** From 7d10d047686dad9f184d452fac45d86b6fee88ad Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 23 Dec 2024 15:30:42 +0000 Subject: [PATCH 4/4] Extract register error handler into separate method --- src/App.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/App.php b/src/App.php index d8f28b89ba..2c236390d1 100644 --- a/src/App.php +++ b/src/App.php @@ -123,6 +123,8 @@ class App { $this->setupContainerForRunningFrontend($request); + $this->registerErrorHandler(); + $this->requestId = $this->container->create(Request::class)->getRequestId(); $this->auth = $this->container->create(Authentication::class); $this->config = $this->container->create(IManageConfigValues::class); @@ -167,7 +169,10 @@ class App ]); \Friendica\DI::init($this->container); + } + private function registerErrorHandler(): void + { \Friendica\Core\Logger\Handler\ErrorHandler::register($this->container->create(LoggerInterface::class)); }