mirror of
https://github.com/friendica/friendica
synced 2025-01-08 20:04:43 +00:00
Merge pull request #14625 from Art4/refactor-entrypoint-console.php
Refactor entrypoint `console.php`
This commit is contained in:
commit
02662ecd11
4 changed files with 41 additions and 25 deletions
|
@ -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'] ?? []);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
45
src/App.php
45
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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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]);
|
||||
|
||||
|
|
Loading…
Reference in a new issue