Make Storage testable & add tests
[friendica.git/.git] / src / DI.php
1 <?php
2
3 namespace Friendica;
4
5 use Dice\Dice;
6 use Psr\Log\LoggerInterface;
7
8 /**
9  * This class is capable of getting all dynamic created classes
10  *
11  * There has to be a "method" phpDoc for each new class, containing result class for a proper matching
12  *
13  * @method static App app()
14  * @method static App\Authentication auth()
15  * @method static App\Arguments args()
16  * @method static App\BaseURL baseUrl()
17  * @method static App\Mode mode()
18  * @method static App\Module module()
19  * @method static App\Page page()
20  * @method static App\Router router()
21  * @method static Content\Item contentItem()
22  * @method static Content\Text\BBCode\Video bbCodeVideo()
23  * @method static Core\Cache\ICache cache()
24  * @method static Core\Config\IConfiguration config()
25  * @method static Core\Config\IPConfiguration pConfig()
26  * @method static Core\Lock\ILock lock()
27  * @method static Core\L10n\L10n l10n()
28  * @method static Core\Process process()
29  * @method static Core\Session\ISession session()
30  * @method static Core\StorageManager facStorage()
31  * @method static Database\Database dba()
32  * @method static Factory\Mastodon\Account mstdnAccount()
33  * @method static Factory\Mastodon\FollowRequest mstdnFollowRequest()
34  * @method static Factory\Mastodon\Relationship mstdnRelationship()
35  * @method static Model\User\Cookie cookie()
36  * @method static Model\Notify notify()
37  * @method static Repository\Introduction intro()
38  * @method static Model\Storage\IStorage storage()
39  * @method static Protocol\Activity activity()
40  * @method static Util\ACLFormatter aclFormatter()
41  * @method static Util\DateTimeFormat dtFormat()
42  * @method static Util\FileSystem fs()
43  * @method static Util\Profiler profiler()
44  * @method static LoggerInterface logger()
45  * @method static LoggerInterface devLogger()
46  * @method static LoggerInterface workerLogger()
47  *
48  */
49 abstract class DI
50 {
51         const CLASS_MAPPING = [
52                 'app'          => App::class,
53                 'auth'         => App\Authentication::class,
54                 'args'         => App\Arguments::class,
55                 'baseUrl'      => App\BaseURL::class,
56                 'mode'         => App\Mode::class,
57                 'module'       => App\Module::class,
58                 'page'         => App\Page::class,
59                 'router'       => App\Router::class,
60                 'contentItem'  => Content\Item::class,
61                 'bbCodeVideo'  => Content\Text\BBCode\Video::class,
62                 'cache'        => Core\Cache\ICache::class,
63                 'config'       => Core\Config\IConfiguration::class,
64                 'pConfig'      => Core\Config\IPConfiguration::class,
65                 'l10n'         => Core\L10n\L10n::class,
66                 'lock'         => Core\Lock\ILock::class,
67                 'process'      => Core\Process::class,
68                 'session'      => Core\Session\ISession::class,
69                 'facStorage'   => Core\StorageManager::class,
70                 'dba'          => Database\Database::class,
71                 'mstdnAccount' => Factory\Mastodon\Account::class,
72                 'mstdnFollowRequest' => Factory\Mastodon\FollowRequest::class,
73                 'mstdnRelationship'  => Factory\Mastodon\Relationship::class,
74                 'cookie'       => Model\User\Cookie::class,
75                 'notify'       => Model\Notify::class,
76                 'storage'      => Model\Storage\IStorage::class,
77                 'intro'        => Repository\Introduction::class,
78                 'activity'     => Protocol\Activity::class,
79                 'aclFormatter' => Util\ACLFormatter::class,
80                 'dtFormat'     => Util\DateTimeFormat::class,
81                 'fs'           => Util\FileSystem::class,
82                 'workerLogger' => Util\Logger\WorkerLogger::class,
83                 'profiler'     => Util\Profiler::class,
84                 'logger'       => LoggerInterface::class,
85                 'devLogger'    => '$devLogger',
86         ];
87
88         /** @var Dice */
89         private static $dice;
90
91         public static function init(Dice $dice)
92         {
93                 self::$dice = $dice;
94         }
95
96         public static function __callStatic($name, $arguments)
97         {
98                 return self::$dice->create(self::CLASS_MAPPING[$name], $arguments);
99         }
100 }