From c99958c32790e36fb28b78b44f308278cbdbc4c0 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 26 Dec 2024 07:26:04 +0000 Subject: [PATCH 01/11] require dependencies.config.php file in index.php entry point --- index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.php b/index.php index 9ea262c5e7..5cdb309363 100644 --- a/index.php +++ b/index.php @@ -17,7 +17,7 @@ require __DIR__ . '/vendor/autoload.php'; $request = \GuzzleHttp\Psr7\ServerRequest::fromGlobals(); -$dice = (new Dice())->addRules(include __DIR__ . '/static/dependencies.config.php'); +$dice = (new Dice())->addRules(require(__DIR__ . '/static/dependencies.config.php')); $app = \Friendica\App::fromDice($dice); From 486a6ba8c6d553d0096590bf67b4cda656156e6a Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 26 Dec 2024 07:29:39 +0000 Subject: [PATCH 02/11] require dependencies.config.php file in console.php entry point --- bin/console.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/console.php b/bin/console.php index a5aeb3d83e..ee681a0fbf 100755 --- a/bin/console.php +++ b/bin/console.php @@ -20,7 +20,8 @@ use Psr\Log\LoggerInterface; require dirname(__DIR__) . '/vendor/autoload.php'; -$dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php'); +$dice = (new Dice())->addRules(require(dirname(__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')); From 907e07a4c402bba065ed30972dedada185f02db0 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 26 Dec 2024 07:39:43 +0000 Subject: [PATCH 03/11] Replace global $argv with $_SERVER --- bin/console.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/console.php b/bin/console.php index ee681a0fbf..250131982f 100755 --- a/bin/console.php +++ b/bin/console.php @@ -31,4 +31,4 @@ $dice = $dice->addRule(LoggerInterface::class, ['constructParams' => [LogChannel DI::init($dice); \Friendica\Core\Logger\Handler\ErrorHandler::register($dice->create(\Psr\Log\LoggerInterface::class)); -(new Friendica\Core\Console($dice, $argv))->execute(); +(new Friendica\Core\Console($dice, $_SERVER['argv'] ?? []))->execute(); From f40b428ac222bbb00e3f96fee9c8a7054cb68083 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 26 Dec 2024 07:44:19 +0000 Subject: [PATCH 04/11] Move code from console.php into App::processConsole() --- bin/console.php | 14 ++------------ src/App.php | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/bin/console.php b/bin/console.php index 250131982f..1c502cc673 100755 --- a/bin/console.php +++ b/bin/console.php @@ -14,21 +14,11 @@ if (php_sapi_name() !== 'cli') { } use Dice\Dice; -use Friendica\Core\Logger\Capability\LogChannel; -use Friendica\DI; -use Psr\Log\LoggerInterface; require dirname(__DIR__) . '/vendor/autoload.php'; $dice = (new Dice())->addRules(require(dirname(__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(LoggerInterface::class, ['constructParams' => [LogChannel::CONSOLE]]); +$app = \Friendica\App::fromDice($dice); -/// @fixme Necessary until Hooks inside the Logger can get loaded without the DI-class -DI::init($dice); -\Friendica\Core\Logger\Handler\ErrorHandler::register($dice->create(\Psr\Log\LoggerInterface::class)); - -(new Friendica\Core\Console($dice, $_SERVER['argv'] ?? []))->execute(); +$app->processConsole($_SERVER['argv'] ?? []); diff --git a/src/App.php b/src/App.php index ecfaec370c..7aef7fe361 100644 --- a/src/App.php +++ b/src/App.php @@ -190,6 +190,20 @@ class App } } + public function processConsole(array $argv): 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(LoggerInterface::class, ['constructParams' => [LogChannel::CONSOLE]]); + + /// @fixme Necessary until Hooks inside the Logger can get loaded without the DI-class + DI::init($this->container); + \Friendica\Core\Logger\Handler\ErrorHandler::register($this->container->create(\Psr\Log\LoggerInterface::class)); + + (new \Friendica\Core\Console($this->container, $argv))->execute(); + } + private function setupContainerForAddons(): void { /** @var \Friendica\Core\Addon\Capability\ICanLoadAddons $addonLoader */ From cf8ce380b70c0c96e64098309721d972581502e3 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 26 Dec 2024 08:01:30 +0000 Subject: [PATCH 05/11] Refactor App::processConsole() --- src/App.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/App.php b/src/App.php index 7aef7fe361..ae9a6334e3 100644 --- a/src/App.php +++ b/src/App.php @@ -192,14 +192,15 @@ class App public function processConsole(array $argv): 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(LoggerInterface::class, ['constructParams' => [LogChannel::CONSOLE]]); + $this->setupContainerForAddons(); - /// @fixme Necessary until Hooks inside the Logger can get loaded without the DI-class - DI::init($this->container); - \Friendica\Core\Logger\Handler\ErrorHandler::register($this->container->create(\Psr\Log\LoggerInterface::class)); + $this->container = $this->container->addRule(LoggerInterface::class, [ + 'constructParams' => [LogChannel::CONSOLE], + ]); + + $this->setupLegacyServerLocator(); + + $this->registerErrorHandler(); (new \Friendica\Core\Console($this->container, $argv))->execute(); } From 0afa5aba633b593233b4a006ed4dae250aa229ba Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 26 Dec 2024 08:10:06 +0000 Subject: [PATCH 06/11] Setup container with explicit LogChannel --- src/App.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/App.php b/src/App.php index ae9a6334e3..b5711589a0 100644 --- a/src/App.php +++ b/src/App.php @@ -125,6 +125,8 @@ class App { $this->setupContainerForAddons(); + $this->setupContainerForLogger(LogChannel::DEFAULT); + $this->container = $this->container->addRule(Mode::class, [ 'call' => [ ['determineRunMode', [false, $request->getServerParams()], Dice::CHAIN_CALL], @@ -170,9 +172,7 @@ class App { $this->setupContainerForAddons(); - $this->container = $this->container->addRule(LoggerInterface::class,[ - 'constructParams' => [LogChannel::AUTH_JABBERED], - ]); + $this->setupContainerForLogger(LogChannel::AUTH_JABBERED); $this->setupLegacyServerLocator(); @@ -194,9 +194,7 @@ class App { $this->setupContainerForAddons(); - $this->container = $this->container->addRule(LoggerInterface::class, [ - 'constructParams' => [LogChannel::CONSOLE], - ]); + $this->setupContainerForLogger(LogChannel::CONSOLE); $this->setupLegacyServerLocator(); @@ -213,6 +211,13 @@ class App $this->container = $this->container->addRules($addonLoader->getActiveAddonConfig('dependencies')); } + private function setupContainerForLogger(string $logChannel): void + { + $this->container = $this->container->addRule(LoggerInterface::class, [ + 'constructParams' => [$logChannel], + ]); + } + private function setupLegacyServerLocator(): void { \Friendica\DI::init($this->container); From ffbc7d0ea14c5f63d9e2b08e987bfc0760614f0e Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 26 Dec 2024 08:15:20 +0000 Subject: [PATCH 07/11] Remove multiple calls of DI::init() --- src/Core/Console.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Core/Console.php b/src/Core/Console.php index d675a0ddc8..760b2542cd 100644 --- a/src/Core/Console.php +++ b/src/Core/Console.php @@ -166,8 +166,6 @@ HELP; $className = $this->subConsoles[$command]; - Friendica\DI::init($this->dice); - Renderer::registerTemplateEngine('Friendica\Render\FriendicaSmartyEngine'); /** @var Console $subconsole */ From e9b92aea7bf7875dd02cde668b3134d0edea3f5b Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 26 Dec 2024 08:24:19 +0000 Subject: [PATCH 08/11] Move call of register the template engine into App --- src/App.php | 2 ++ src/Core/Console.php | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/App.php b/src/App.php index b5711589a0..03300a8a11 100644 --- a/src/App.php +++ b/src/App.php @@ -200,6 +200,8 @@ class App $this->registerErrorHandler(); + Core\Renderer::registerTemplateEngine('Friendica\Render\FriendicaSmartyEngine'); + (new \Friendica\Core\Console($this->container, $argv))->execute(); } diff --git a/src/Core/Console.php b/src/Core/Console.php index 760b2542cd..e957e9c1a1 100644 --- a/src/Core/Console.php +++ b/src/Core/Console.php @@ -166,8 +166,6 @@ HELP; $className = $this->subConsoles[$command]; - Renderer::registerTemplateEngine('Friendica\Render\FriendicaSmartyEngine'); - /** @var Console $subconsole */ $subconsole = $this->dice->create($className, [$subargs]); From a6385bed7118eb1ee7c39dd13a2722994861e573 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 26 Dec 2024 08:27:02 +0000 Subject: [PATCH 09/11] Refactor registering template engine --- src/App.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/App.php b/src/App.php index 03300a8a11..2c4eacc300 100644 --- a/src/App.php +++ b/src/App.php @@ -17,6 +17,7 @@ use Friendica\App\Router; use Friendica\Capabilities\ICanCreateResponses; use Friendica\Content\Nav; use Friendica\Core\Config\Factory\Config; +use Friendica\Core\Renderer; use Friendica\Core\Session\Capability\IHandleUserSessions; use Friendica\Database\Definition\DbaDefinition; use Friendica\Database\Definition\ViewDefinition; @@ -200,7 +201,7 @@ class App $this->registerErrorHandler(); - Core\Renderer::registerTemplateEngine('Friendica\Render\FriendicaSmartyEngine'); + $this->registerTemplateEngine(); (new \Friendica\Core\Console($this->container, $argv))->execute(); } @@ -230,6 +231,11 @@ class App \Friendica\Core\Logger\Handler\ErrorHandler::register($this->container->create(LoggerInterface::class)); } + private function registerTemplateEngine(): void + { + Renderer::registerTemplateEngine('Friendica\Render\FriendicaSmartyEngine'); + } + /** * Load the whole app instance */ @@ -264,8 +270,8 @@ class App } $this->loadDefaultTimezone(); - // Register template engines - Core\Renderer::registerTemplateEngine('Friendica\Render\FriendicaSmartyEngine'); + + $this->registerTemplateEngine(); } /** From ba6bde9b09f411e33d010617ba9c455ef7f9f9c1 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 26 Dec 2024 08:29:11 +0000 Subject: [PATCH 10/11] move up registerTemplateEngine call --- src/App.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/App.php b/src/App.php index 2c4eacc300..90d90869fd 100644 --- a/src/App.php +++ b/src/App.php @@ -155,6 +155,8 @@ class App $this->container->create(ViewDefinition::class), ); + $this->registerTemplateEngine(); + $this->mode->setExecutor(Mode::INDEX); $this->runFrontend( @@ -270,8 +272,6 @@ class App } $this->loadDefaultTimezone(); - - $this->registerTemplateEngine(); } /** From 38ad97f24f31c77c12b994e630fe1e6597cbd9ed Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 26 Dec 2024 08:45:57 +0000 Subject: [PATCH 11/11] Refactor App::load() method --- src/App.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/App.php b/src/App.php index 90d90869fd..0fcebd464a 100644 --- a/src/App.php +++ b/src/App.php @@ -150,7 +150,8 @@ class App $this->session = $this->container->create(IHandleUserSessions::class); $this->appHelper = $this->container->create(AppHelper::class); - $this->load( + $this->loadSetupForFrontend( + $request, $this->container->create(DbaDefinition::class), $this->container->create(ViewDefinition::class), ); @@ -241,7 +242,7 @@ class App /** * Load the whole app instance */ - private function load(DbaDefinition $dbaDefinition, ViewDefinition $viewDefinition) + private function loadSetupForFrontend(ServerRequestInterface $request, DbaDefinition $dbaDefinition, ViewDefinition $viewDefinition) { if ($this->config->get('system', 'ini_max_execution_time') !== false) { set_time_limit((int)$this->config->get('system', 'ini_max_execution_time')); @@ -263,7 +264,7 @@ class App if ($this->mode->has(Mode::DBAVAILABLE)) { Core\Hook::loadHooks(); - $loader = (new Config())->createConfigFileManager($this->appHelper->getBasePath(), $_SERVER); + $loader = (new Config())->createConfigFileManager($this->appHelper->getBasePath(), $request->getServerParams()); Core\Hook::callAll('load_config', $loader); // Hooks are now working, reload the whole definitions with hook enabled