X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FDI.php;h=c62b5e8d793d814a9ed170a9651a9342860744a0;hb=e659a0314086dd700dbe5e754e383ab758725805;hp=6fd0e3a7ada89ebd40bdfbf222e4c7887670458b;hpb=450dd433a31c1b85408f633d603f27203c105734;p=friendica.git diff --git a/src/DI.php b/src/DI.php index 6fd0e3a7ad..c62b5e8d79 100644 --- a/src/DI.php +++ b/src/DI.php @@ -22,6 +22,8 @@ namespace Friendica; use Dice\Dice; +use Friendica\Core\Logger\Capabilities\ICheckLoggerSettings; +use Friendica\Core\Logger\Util\LoggerSettingsCheck; use Friendica\Core\Session\Capability\IHandleSessions; use Friendica\Core\Session\Capability\IHandleUserSessions; use Friendica\Navigation\SystemMessages; @@ -37,14 +39,39 @@ abstract class DI /** @var Dice */ private static $dice; - public static function init(Dice $dice) + /** + * Initialize the singleton DI container with the Dice instance + * + * @param Dice $dice The Dice instance + * @param bool $disableDepByHand If true, the database dependencies aren't set, thus any occurrence of logging or + * profiling in database methods would lead to an error. This flag is for testing only. + * + * @return void + */ + public static function init(Dice $dice, bool $disableDepByHand = false) { self::$dice = $dice; + + if (!$disableDepByHand) { + self::setCompositeRootDependencyByHand(); + } + } + + /** + * I HATE this method, but everything else needs refactoring at the database itself + * Set the database dependencies manually, because of current, circular dependencies between the database and the config table + * + * @todo Instead of this madness, split the database in a core driver-dependent (mysql, mariadb, postgresql, ..) part without any other dependency unlike credentials and in the full-featured, driver-independent database class with all dependencies + */ + public static function setCompositeRootDependencyByHand() + { + $database = static::dba(); + $database->setDependency(static::config(), static::profiler(), static::logger()); } /** * Returns a clone of the current dice instance - * This usefull for overloading the current instance with mocked methods during tests + * This useful for overloading the current instance with mocked methods during tests * * @return Dice */ @@ -101,10 +128,7 @@ abstract class DI return self::$dice->create(App\Arguments::class); } - /** - * @return App\BaseURL - */ - public static function baseUrl() + public static function baseUrl(): App\BaseURL { return self::$dice->create(App\BaseURL::class); } @@ -273,6 +297,11 @@ abstract class DI static::init($flushDice); } + public static function loggCheck(): ICheckLoggerSettings + { + return self::$dice->create(LoggerSettingsCheck::class); + } + /** * @return LoggerInterface */ @@ -357,14 +386,6 @@ abstract class DI return self::$dice->create(Factory\Api\Mastodon\Error::class); } - /** - * @return Factory\Api\Mastodon\FollowRequest - */ - public static function mstdnFollowRequest() - { - return self::$dice->create(Factory\Api\Mastodon\FollowRequest::class); - } - /** * @return Factory\Api\Mastodon\Poll */ @@ -678,14 +699,6 @@ abstract class DI return self::$dice->create(Util\DateTimeFormat::class); } - /** - * @return Util\FileSystem - */ - public static function fs() - { - return self::$dice->create(Util\FileSystem::class); - } - /** * @return Util\Profiler */