Move setupLegacyServiceLocator() into App class

This commit is contained in:
Art4 2025-01-09 13:34:10 +00:00
parent 2f3ef5359f
commit f1dba9f89e
2 changed files with 23 additions and 7 deletions

View file

@ -27,6 +27,7 @@ use Friendica\Database\Definition\ViewDefinition;
use Friendica\Module\Maintenance; use Friendica\Module\Maintenance;
use Friendica\Security\Authentication; use Friendica\Security\Authentication;
use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\DiceContainer;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\Logger\Capability\LogChannel; use Friendica\Core\Logger\Capability\LogChannel;
use Friendica\Core\Logger\Handler\ErrorHandler; use Friendica\Core\Logger\Handler\ErrorHandler;
@ -140,7 +141,7 @@ class App
$this->setupContainerForLogger(LogChannel::APP); $this->setupContainerForLogger(LogChannel::APP);
$this->container->setup(); $this->setupLegacyServiceLocator();
$this->registerErrorHandler(); $this->registerErrorHandler();
@ -182,7 +183,7 @@ class App
$this->setupContainerForLogger($this->determineLogChannel($argv)); $this->setupContainerForLogger($this->determineLogChannel($argv));
$this->container->setup(); $this->setupLegacyServiceLocator();
$this->registerErrorHandler(); $this->registerErrorHandler();
@ -197,7 +198,7 @@ class App
$this->setupContainerForLogger(LogChannel::AUTH_JABBERED); $this->setupContainerForLogger(LogChannel::AUTH_JABBERED);
$this->container->setup(); $this->setupLegacyServiceLocator();
$this->registerErrorHandler(); $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 private function registerErrorHandler(): void
{ {
ErrorHandler::register($this->container->create(LoggerInterface::class)); ErrorHandler::register($this->container->create(LoggerInterface::class));

View file

@ -10,7 +10,6 @@ declare(strict_types=1);
namespace Friendica\Core; namespace Friendica\Core;
use Dice\Dice; use Dice\Dice;
use Friendica\DI;
/** /**
* Wrapper for the Dice class to make some basic setups * Wrapper for the Dice class to make some basic setups
@ -42,7 +41,7 @@ final class DiceContainer implements Container
*/ */
public function setup(): void 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); $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;
} }
} }