diff --git a/bin/auth_ejabberd.php b/bin/auth_ejabberd.php index bc976e61a4..595ccf204a 100755 --- a/bin/auth_ejabberd.php +++ b/bin/auth_ejabberd.php @@ -52,4 +52,4 @@ $container = \Friendica\Core\DiceContainer::fromBasePath(dirname(__DIR__)); $app = \Friendica\App::fromContainer($container); -$app->processEjabberd(); +$app->processEjabberd($_SERVER); diff --git a/bin/console.php b/bin/console.php index ad612f4363..a20f3f7e02 100755 --- a/bin/console.php +++ b/bin/console.php @@ -19,4 +19,4 @@ $container = \Friendica\Core\DiceContainer::fromBasePath(dirname(__DIR__)); $app = \Friendica\App::fromContainer($container); -$app->processConsole($_SERVER['argv'] ?? []); +$app->processConsole($_SERVER); diff --git a/bin/daemon.php b/bin/daemon.php index 546f207e08..25f902eacd 100755 --- a/bin/daemon.php +++ b/bin/daemon.php @@ -24,11 +24,13 @@ chdir(dirname(__DIR__)); require dirname(__DIR__) . '/vendor/autoload.php'; +// BC: Add console command as second argument $argv = $_SERVER['argv'] ?? []; array_splice($argv, 1, 0, "daemon"); +$_SERVER['argv'] = $argv; $container = \Friendica\Core\DiceContainer::fromBasePath(dirname(__DIR__)); $app = \Friendica\App::fromContainer($container); -$app->processConsole($argv); +$app->processConsole($_SERVER); diff --git a/bin/jetstream.php b/bin/jetstream.php index 156f961856..b96dfa0e51 100755 --- a/bin/jetstream.php +++ b/bin/jetstream.php @@ -19,11 +19,13 @@ chdir(dirname(__DIR__)); require dirname(__DIR__) . '/vendor/autoload.php'; +// BC: Add console command as second argument $argv = $_SERVER['argv'] ?? []; array_splice($argv, 1, 0, "jetstream"); +$_SERVER['argv'] = $argv; $container = \Friendica\Core\DiceContainer::fromBasePath(dirname(__DIR__)); $app = \Friendica\App::fromContainer($container); -$app->processConsole($argv); +$app->processConsole($_SERVER); diff --git a/bin/worker.php b/bin/worker.php index a79d8836a7..b72a8e2514 100755 --- a/bin/worker.php +++ b/bin/worker.php @@ -21,11 +21,13 @@ chdir(dirname(__DIR__)); require dirname(__DIR__) . '/vendor/autoload.php'; +// BC: Add console command as second argument $argv = $_SERVER['argv'] ?? []; array_splice($argv, 1, 0, "worker"); +$_SERVER['argv'] = $argv; $container = \Friendica\Core\DiceContainer::fromBasePath(dirname(__DIR__)); $app = \Friendica\App::fromContainer($container); -$app->processConsole($argv); +$app->processConsole($_SERVER); diff --git a/src/App.php b/src/App.php index 73f2913b1a..564da764f9 100644 --- a/src/App.php +++ b/src/App.php @@ -158,16 +158,18 @@ class App $this->session = $this->container->create(IHandleUserSessions::class); $this->appHelper = $this->container->create(AppHelper::class); - $this->loadSetupForFrontend( - $request, + $this->load( + $request->getServerParams(), $this->container->create(DbaDefinition::class), $this->container->create(ViewDefinition::class), + $this->mode, + $this->config, + $this->profiler, + $this->appHelper, ); $this->registerTemplateEngine(); - $this->mode->setExecutor(Mode::INDEX); - $this->runFrontend( $this->container->create(IManagePersonalConfigValues::class), $this->container->create(Page::class), @@ -178,8 +180,11 @@ class App ); } - public function processConsole(array $argv): void + + public function processConsole(array $serverParams): void { + $argv = $serverParams['argv'] ?? []; + $this->setupContainerForAddons(); $this->setupLogChannel($this->determineLogChannel($argv)); @@ -188,12 +193,22 @@ class App $this->registerErrorHandler(); + $this->load( + $serverParams, + $this->container->create(DbaDefinition::class), + $this->container->create(ViewDefinition::class), + $this->container->create(Mode::class), + $this->container->create(IManageConfigValues::class), + $this->container->create(Profiler::class), + $this->container->create(AppHelper::class), + ); + $this->registerTemplateEngine(); (\Friendica\Core\Console::create($this->container, $argv))->execute(); } - public function processEjabberd(): void + public function processEjabberd(array $serverParams): void { $this->setupContainerForAddons(); @@ -203,6 +218,16 @@ class App $this->registerErrorHandler(); + $this->load( + $serverParams, + $this->container->create(DbaDefinition::class), + $this->container->create(ViewDefinition::class), + $this->container->create(Mode::class), + $this->container->create(IManageConfigValues::class), + $this->container->create(Profiler::class), + $this->container->create(AppHelper::class), + ); + /** @var BasePath */ $basePath = $this->container->create(BasePath::class); @@ -272,14 +297,21 @@ class App /** * Load the whole app instance */ - 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')); + private function load( + array $serverParams, + DbaDefinition $dbaDefinition, + ViewDefinition $viewDefinition, + Mode $mode, + IManageConfigValues $config, + Profiler $profiler, + AppHelper $appHelper + ): void { + if ($config->get('system', 'ini_max_execution_time') !== false) { + set_time_limit((int) $config->get('system', 'ini_max_execution_time')); } - if ($this->config->get('system', 'ini_pcre_backtrack_limit') !== false) { - ini_set('pcre.backtrack_limit', (int)$this->config->get('system', 'ini_pcre_backtrack_limit')); + if ($config->get('system', 'ini_pcre_backtrack_limit') !== false) { + ini_set('pcre.backtrack_limit', (int) $config->get('system', 'ini_pcre_backtrack_limit')); } // Normally this constant is defined - but not if "pcntl" isn't installed @@ -290,11 +322,11 @@ class App // Ensure that all "strtotime" operations do run timezone independent date_default_timezone_set('UTC'); - $this->profiler->reset(); + $profiler->reset(); - if ($this->mode->has(Mode::DBAVAILABLE)) { + if ($mode->has(Mode::DBAVAILABLE)) { Core\Hook::loadHooks(); - $loader = (new Config())->createConfigFileManager($this->appHelper->getBasePath(), $request->getServerParams()); + $loader = (new Config())->createConfigFileManager($appHelper->getBasePath(), $serverParams); Core\Hook::callAll('load_config', $loader); // Hooks are now working, reload the whole definitions with hook enabled @@ -302,7 +334,7 @@ class App $viewDefinition->load(true); } - $this->loadDefaultTimezone(); + $this->loadDefaultTimezone($config, $appHelper); } /** @@ -312,16 +344,16 @@ class App * * @global string $default_timezone */ - private function loadDefaultTimezone() + private function loadDefaultTimezone(IManageConfigValues $config, AppHelper $appHelper) { - if ($this->config->get('system', 'default_timezone')) { - $timezone = $this->config->get('system', 'default_timezone', 'UTC'); + if ($config->get('system', 'default_timezone')) { + $timezone = $config->get('system', 'default_timezone', 'UTC'); } else { global $default_timezone; $timezone = $default_timezone ?? '' ?: 'UTC'; } - $this->appHelper->setTimeZone($timezone); + $appHelper->setTimeZone($timezone); } /** @@ -348,6 +380,8 @@ class App float $start_time, ServerRequestInterface $request ) { + $this->mode->setExecutor(Mode::INDEX); + $httpInput = new HTTPInputData($request->getServerParams()); $serverVars = $request->getServerParams(); $queryVars = $request->getQueryParams();