From 1c7446bf9a72b51abab64475656418e260431cad Mon Sep 17 00:00:00 2001 From: Art4 Date: Wed, 18 Dec 2024 22:16:34 +0000 Subject: [PATCH] Create App::fromDice() factory method --- index.php | 2 +- src/App.php | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index 09620ab4c1..d3483cb7cd 100644 --- a/index.php +++ b/index.php @@ -25,7 +25,7 @@ $dice = $dice->addRule(Friendica\App\Mode::class, ['call' => [['determineRunMode \Friendica\Core\Logger\Handler\ErrorHandler::register($dice->create(\Psr\Log\LoggerInterface::class)); -$a = \Friendica\DI::app(); +$a = \Friendica\App::fromDice($dice); \Friendica\DI::mode()->setExecutor(\Friendica\App\Mode::INDEX); diff --git a/src/App.php b/src/App.php index d3ff15bada..2fedaa24e8 100644 --- a/src/App.php +++ b/src/App.php @@ -7,6 +7,7 @@ namespace Friendica; +use Dice\Dice; use Friendica\App\Arguments; use Friendica\App\BaseURL; use Friendica\App\Mode; @@ -51,6 +52,25 @@ class App const CODENAME = 'Yellow Archangel'; const VERSION = '2024.12-dev'; + public static function fromDice(Dice $dice): self + { + return new self( + $dice->create(Request::class), + $dice->create(Authentication::class), + $dice->create(IManageConfigValues::class), + $dice->create(Mode::class), + $dice->create(BaseURL::class), + $dice->create(LoggerInterface::class), + $dice->create(Profiler::class), + $dice->create(L10n::class), + $dice->create(Arguments::class), + $dice->create(IHandleUserSessions::class), + $dice->create(DbaDefinition::class), + $dice->create(ViewDefinition::class), + $dice->create(AppHelper::class) + ); + } + /** * @var Mode The Mode of the Application */ @@ -114,7 +134,8 @@ class App Arguments $args, IHandleUserSessions $session, DbaDefinition $dbaDefinition, - ViewDefinition $viewDefinition + ViewDefinition $viewDefinition, + AppHelper $appHelper = null, ) { $this->requestId = $request->getRequestId(); $this->auth = $auth; @@ -126,7 +147,7 @@ class App $this->l10n = $l10n; $this->args = $args; $this->session = $session; - $this->appHelper = DI::appHelper(); + $this->appHelper = $appHelper ?? DI::appHelper(); $this->load($dbaDefinition, $viewDefinition); }