diff --git a/src/App.php b/src/App.php index 17254bb966..c1ac8b2d43 100644 --- a/src/App.php +++ b/src/App.php @@ -27,6 +27,7 @@ use Friendica\Database\Definition\ViewDefinition; use Friendica\Module\Maintenance; use Friendica\Security\Authentication; use Friendica\Core\Config\Capability\IManageConfigValues; +use Friendica\Core\DiceContainer; use Friendica\Core\L10n; use Friendica\Core\Logger\Capability\LogChannel; use Friendica\Core\Logger\Handler\ErrorHandler; @@ -140,7 +141,7 @@ class App $this->setupContainerForLogger(LogChannel::APP); - $this->container->setup(); + $this->setupLegacyServiceLocator(); $this->registerErrorHandler(); @@ -182,7 +183,7 @@ class App $this->setupContainerForLogger($this->determineLogChannel($argv)); - $this->container->setup(); + $this->setupLegacyServiceLocator(); $this->registerErrorHandler(); @@ -197,7 +198,7 @@ class App $this->setupContainerForLogger(LogChannel::AUTH_JABBERED); - $this->container->setup(); + $this->setupLegacyServiceLocator(); $this->registerErrorHandler(); @@ -250,6 +251,13 @@ class App ]); } + private function setupLegacyServiceLocator(): void + { + if ($this->container instanceof DiceContainer) { + DI::init($this->container->getDice()); + } + } + private function registerErrorHandler(): void { ErrorHandler::register($this->container->create(LoggerInterface::class)); diff --git a/src/Core/DiceContainer.php b/src/Core/DiceContainer.php index 778192388b..acbb0862b9 100644 --- a/src/Core/DiceContainer.php +++ b/src/Core/DiceContainer.php @@ -10,7 +10,6 @@ declare(strict_types=1); namespace Friendica\Core; use Dice\Dice; -use Friendica\DI; /** * Wrapper for the Dice class to make some basic setups @@ -42,7 +41,7 @@ final class DiceContainer implements Container */ public function setup(): void { - $this->setupLegacyServiceLocator(); + // this method can be removed } /** @@ -71,8 +70,17 @@ final class DiceContainer implements Container $this->container = $this->container->addRule($name, $rule); } - private function setupLegacyServiceLocator(): void + /** + * Only used to inject Dice into DI class + * + * @see \Friendica\DI + * + * @internal + * + * @deprecated + */ + public function getDice(): Dice { - DI::init($this->container); + return $this->container; } }