X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FDI.php;h=8d706ed374a1ab3eb80b34280b983dcf0805dfa5;hb=89b6c4c73f372bcff10fb121fbfdbd9255bb824d;hp=0ef18a1aa35ec3984ea3d1c62ba65cf9932efbd9;hpb=931ccde90d5b27d9fcc91504c0825fc70d0f1ffc;p=friendica.git diff --git a/src/DI.php b/src/DI.php index 0ef18a1aa3..8d706ed374 100644 --- a/src/DI.php +++ b/src/DI.php @@ -37,14 +37,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 +126,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); } @@ -181,6 +203,11 @@ abstract class DI return self::$dice->create(Core\Config\Capability\IManageConfigValues::class); } + public static function configFileManager(): Core\Config\Util\ConfigFileManager + { + return self::$dice->create(Core\Config\Util\ConfigFileManager::class); + } + public static function keyValue(): Core\KeyValueStorage\Capabilities\IManageKeyValuePairs { return self::$dice->create(Core\KeyValueStorage\Capabilities\IManageKeyValuePairs::class); @@ -352,14 +379,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 */