diff --git a/bin/console.php b/bin/console.php index a5aeb3d83e..1c502cc673 100755 --- a/bin/console.php +++ b/bin/console.php @@ -14,20 +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(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(LoggerInterface::class, ['constructParams' => [LogChannel::CONSOLE]]); +$dice = (new Dice())->addRules(require(dirname(__DIR__) . '/static/dependencies.config.php')); -/// @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)); +$app = \Friendica\App::fromDice($dice); -(new Friendica\Core\Console($dice, $argv))->execute(); +$app->processConsole($_SERVER['argv'] ?? []); 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); diff --git a/src/App.php b/src/App.php index 98c12cd579..b5bd34f578 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; @@ -125,6 +126,8 @@ class App { $this->setupContainerForAddons(); + $this->setupContainerForLogger(LogChannel::DEFAULT); + $this->container = $this->container->addRule(Mode::class, [ 'call' => [ ['determineRunMode', [false, $request->getServerParams()], Dice::CHAIN_CALL], @@ -147,11 +150,14 @@ 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), ); + $this->registerTemplateEngine(); + $this->mode->setExecutor(Mode::INDEX); $this->runFrontend( @@ -170,9 +176,7 @@ class App { $this->setupContainerForAddons(); - $this->container = $this->container->addRule(LoggerInterface::class,[ - 'constructParams' => [LogChannel::AUTH_JABBERED], - ]); + $this->setupContainerForLogger(LogChannel::AUTH_JABBERED); $this->setupLegacyServiceLocator(); @@ -190,6 +194,21 @@ class App } } + public function processConsole(array $argv): void + { + $this->setupContainerForAddons(); + + $this->setupContainerForLogger(LogChannel::CONSOLE); + + $this->setupLegacyServiceLocator(); + + $this->registerErrorHandler(); + + $this->registerTemplateEngine(); + + (new \Friendica\Core\Console($this->container, $argv))->execute(); + } + private function setupContainerForAddons(): void { /** @var \Friendica\Core\Addon\Capability\ICanLoadAddons $addonLoader */ @@ -198,6 +217,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 setupLegacyServiceLocator(): void { \Friendica\DI::init($this->container); @@ -208,10 +234,15 @@ 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 */ - 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')); @@ -233,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 @@ -242,8 +273,6 @@ class App } $this->loadDefaultTimezone(); - // Register template engines - Core\Renderer::registerTemplateEngine('Friendica\Render\FriendicaSmartyEngine'); } /** diff --git a/src/Core/Console.php b/src/Core/Console.php index d675a0ddc8..e957e9c1a1 100644 --- a/src/Core/Console.php +++ b/src/Core/Console.php @@ -166,10 +166,6 @@ HELP; $className = $this->subConsoles[$command]; - Friendica\DI::init($this->dice); - - Renderer::registerTemplateEngine('Friendica\Render\FriendicaSmartyEngine'); - /** @var Console $subconsole */ $subconsole = $this->dice->create($className, [$subargs]);