From b94697678e00578940abe0d89e1acfdd6317e3f8 Mon Sep 17 00:00:00 2001 From: Art4 Date: Wed, 25 Dec 2024 20:43:15 +0000 Subject: [PATCH 1/8] refactor chdir() call --- bin/auth_ejabberd.php | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/bin/auth_ejabberd.php b/bin/auth_ejabberd.php index 247635b33d..2bffc9ce0a 100755 --- a/bin/auth_ejabberd.php +++ b/bin/auth_ejabberd.php @@ -50,19 +50,7 @@ use Friendica\Core\Logger\Capability\LogChannel; use Friendica\Security\ExAuth; use Psr\Log\LoggerInterface; -if (sizeof($_SERVER["argv"]) == 0) { - die(); -} - -$directory = dirname($_SERVER["argv"][0]); - -if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) { - $directory = $_SERVER["PWD"] . DIRECTORY_SEPARATOR . $directory; -} - -$directory = realpath($directory . DIRECTORY_SEPARATOR . ".."); - -chdir($directory); +chdir(dirname(__FILE__, 2)); require dirname(__DIR__) . '/vendor/autoload.php'; From e0dadea0ff1559f2a5c0ea4fdb924b73565d173a Mon Sep 17 00:00:00 2001 From: Art4 Date: Wed, 25 Dec 2024 21:01:24 +0000 Subject: [PATCH 2/8] Refactor path to dice rules --- bin/auth_ejabberd.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/auth_ejabberd.php b/bin/auth_ejabberd.php index 2bffc9ce0a..c44cd65ff6 100755 --- a/bin/auth_ejabberd.php +++ b/bin/auth_ejabberd.php @@ -54,7 +54,7 @@ chdir(dirname(__FILE__, 2)); require dirname(__DIR__) . '/vendor/autoload.php'; -$dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php'); +$dice = (new Dice())->addRules(require(dirname(__FILE__, 2) . '/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 34b241942710c74fbf70843be05459634ae6bc1d Mon Sep 17 00:00:00 2001 From: Art4 Date: Wed, 25 Dec 2024 21:12:24 +0000 Subject: [PATCH 3/8] Move auth_ejabberd.php code into App::processEjabberd() --- bin/auth_ejabberd.php | 24 +++--------------------- src/App.php | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/bin/auth_ejabberd.php b/bin/auth_ejabberd.php index c44cd65ff6..30202bbd93 100755 --- a/bin/auth_ejabberd.php +++ b/bin/auth_ejabberd.php @@ -45,31 +45,13 @@ if (php_sapi_name() !== 'cli') { } use Dice\Dice; -use Friendica\App\Mode; -use Friendica\Core\Logger\Capability\LogChannel; -use Friendica\Security\ExAuth; -use Psr\Log\LoggerInterface; chdir(dirname(__FILE__, 2)); -require dirname(__DIR__) . '/vendor/autoload.php'; +require dirname(__FILE__, 2) . '/vendor/autoload.php'; $dice = (new Dice())->addRules(require(dirname(__FILE__, 2) . '/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::AUTH_JABBERED]]); -\Friendica\DI::init($dice); -\Friendica\Core\Logger\Handler\ErrorHandler::register($dice->create(\Psr\Log\LoggerInterface::class)); +$app = \Friendica\App::fromDice($dice); -// Check the database structure and possibly fixes it -\Friendica\Core\Update::check(\Friendica\DI::basePath(), true); - -$appMode = $dice->create(Mode::class); - -if ($appMode->isNormal()) { - /** @var ExAuth $oAuth */ - $oAuth = $dice->create(ExAuth::class); - $oAuth->readStdin(); -} +$app->processEjabberd(); diff --git a/src/App.php b/src/App.php index 2c236390d1..40d8cf092d 100644 --- a/src/App.php +++ b/src/App.php @@ -23,12 +23,14 @@ use Friendica\Database\Definition\ViewDefinition; use Friendica\Module\Maintenance; use Friendica\Security\Authentication; use Friendica\Core\Config\Capability\IManageConfigValues; +use Friendica\Core\Logger\Capability\LogChannel; use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues; use Friendica\Core\L10n; use Friendica\Core\System; use Friendica\Module\Special\HTTPException as ModuleHTTPException; use Friendica\Network\HTTPException; use Friendica\Protocol\ATProtocol\DID; +use Friendica\Security\ExAuth; use Friendica\Security\OpenWebAuth; use Friendica\Util\DateTimeFormat; use Friendica\Util\HTTPInputData; @@ -156,6 +158,30 @@ class App ); } + public function processEjabberd(): 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::AUTH_JABBERED], + ]); + + \Friendica\DI::init($this->container); + \Friendica\Core\Logger\Handler\ErrorHandler::register($this->container->create(LoggerInterface::class)); + + // Check the database structure and possibly fixes it + \Friendica\Core\Update::check(\Friendica\DI::basePath(), true); + + $appMode = $this->container->create(Mode::class); + + if ($appMode->isNormal()) { + /** @var ExAuth $oAuth */ + $oAuth = $this->container->create(ExAuth::class); + $oAuth->readStdin(); + } + } + private function setupContainerForRunningFrontend(ServerRequestInterface $request): void { /** @var \Friendica\Core\Addon\Capability\ICanLoadAddons $addonLoader */ From f7c661b5e9331224c802a03603c8aa6f408b690b Mon Sep 17 00:00:00 2001 From: Art4 Date: Wed, 25 Dec 2024 21:16:00 +0000 Subject: [PATCH 4/8] Extract call of AddonLoader into App::setupContainerForAddons() --- src/App.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/App.php b/src/App.php index 40d8cf092d..39a1414200 100644 --- a/src/App.php +++ b/src/App.php @@ -160,9 +160,8 @@ class App public function processEjabberd(): 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->setupContainerForAddons(); + $this->container = $this->container->addRule(LoggerInterface::class,[ 'constructParams' => [LogChannel::AUTH_JABBERED], ]); @@ -184,10 +183,8 @@ 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->setupContainerForAddons(); - $this->container = $this->container->addRules($addonLoader->getActiveAddonConfig('dependencies')); $this->container = $this->container->addRule(Mode::class, [ 'call' => [ ['determineRunMode', [false, $request->getServerParams()], Dice::CHAIN_CALL], @@ -197,6 +194,14 @@ class App \Friendica\DI::init($this->container); } + private function setupContainerForAddons(): 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')); + } + private function registerErrorHandler(): void { \Friendica\Core\Logger\Handler\ErrorHandler::register($this->container->create(LoggerInterface::class)); From d2f2d1d0b90962590575b565ac09ff6176710f75 Mon Sep 17 00:00:00 2001 From: Art4 Date: Wed, 25 Dec 2024 21:17:02 +0000 Subject: [PATCH 5/8] Use App::registerErrorHandler() --- src/App.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/App.php b/src/App.php index 39a1414200..415aeeabe0 100644 --- a/src/App.php +++ b/src/App.php @@ -167,7 +167,8 @@ class App ]); \Friendica\DI::init($this->container); - \Friendica\Core\Logger\Handler\ErrorHandler::register($this->container->create(LoggerInterface::class)); + + $this->registerErrorHandler(); // Check the database structure and possibly fixes it \Friendica\Core\Update::check(\Friendica\DI::basePath(), true); From ce7fd1b0e29252eaccff9c840860975ad1672a36 Mon Sep 17 00:00:00 2001 From: Art4 Date: Wed, 25 Dec 2024 21:20:08 +0000 Subject: [PATCH 6/8] extract setup of DI class --- src/App.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/App.php b/src/App.php index 415aeeabe0..691bab75eb 100644 --- a/src/App.php +++ b/src/App.php @@ -166,7 +166,7 @@ class App 'constructParams' => [LogChannel::AUTH_JABBERED], ]); - \Friendica\DI::init($this->container); + $this->setupLegacyServerLocator(); $this->registerErrorHandler(); @@ -192,7 +192,7 @@ class App ], ]); - \Friendica\DI::init($this->container); + $this->setupLegacyServerLocator(); } private function setupContainerForAddons(): void @@ -203,6 +203,11 @@ class App $this->container = $this->container->addRules($addonLoader->getActiveAddonConfig('dependencies')); } + private function setupLegacyServerLocator(): void + { + \Friendica\DI::init($this->container); + } + private function registerErrorHandler(): void { \Friendica\Core\Logger\Handler\ErrorHandler::register($this->container->create(LoggerInterface::class)); From 26f1c5f1dc3eb726a19fb995afff15e9608de431 Mon Sep 17 00:00:00 2001 From: Art4 Date: Wed, 25 Dec 2024 21:27:08 +0000 Subject: [PATCH 7/8] inline App::setupContainerForRunningFrontend() method --- src/App.php | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/App.php b/src/App.php index 691bab75eb..ecfaec370c 100644 --- a/src/App.php +++ b/src/App.php @@ -123,7 +123,15 @@ class App public function processRequest(ServerRequestInterface $request, float $start_time): void { - $this->setupContainerForRunningFrontend($request); + $this->setupContainerForAddons(); + + $this->container = $this->container->addRule(Mode::class, [ + 'call' => [ + ['determineRunMode', [false, $request->getServerParams()], Dice::CHAIN_CALL], + ], + ]); + + $this->setupLegacyServerLocator(); $this->registerErrorHandler(); @@ -182,19 +190,6 @@ class App } } - private function setupContainerForRunningFrontend(ServerRequestInterface $request): void - { - $this->setupContainerForAddons(); - - $this->container = $this->container->addRule(Mode::class, [ - 'call' => [ - ['determineRunMode', [false, $request->getServerParams()], Dice::CHAIN_CALL], - ], - ]); - - $this->setupLegacyServerLocator(); - } - private function setupContainerForAddons(): void { /** @var \Friendica\Core\Addon\Capability\ICanLoadAddons $addonLoader */ From 2ed1b969fb0e7706d429b3c3f36ddb7bb1448dd5 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 26 Dec 2024 16:59:15 +0000 Subject: [PATCH 8/8] rename App::setupLegacyServiceLocator() --- src/App.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/App.php b/src/App.php index ecfaec370c..98c12cd579 100644 --- a/src/App.php +++ b/src/App.php @@ -131,7 +131,7 @@ class App ], ]); - $this->setupLegacyServerLocator(); + $this->setupLegacyServiceLocator(); $this->registerErrorHandler(); @@ -174,7 +174,7 @@ class App 'constructParams' => [LogChannel::AUTH_JABBERED], ]); - $this->setupLegacyServerLocator(); + $this->setupLegacyServiceLocator(); $this->registerErrorHandler(); @@ -198,7 +198,7 @@ class App $this->container = $this->container->addRules($addonLoader->getActiveAddonConfig('dependencies')); } - private function setupLegacyServerLocator(): void + private function setupLegacyServiceLocator(): void { \Friendica\DI::init($this->container); }