Merge pull request #8156 from MrPetovan/task/7817-custom-fields-part-2
[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  * @see https://designpatternsphp.readthedocs.io/en/latest/Structural/Registry/README.html
12  */
13 abstract class DI
14 {
15         /** @var Dice */
16         private static $dice;
17
18         public static function init(Dice $dice)
19         {
20                 self::$dice = $dice;
21         }
22
23         //
24         // common instances
25         //
26
27         /**
28          * @return App
29          */
30         public static function app()
31         {
32                 return self::$dice->create(App::class);
33         }
34
35         /**
36          * @return Database\Database
37          */
38         public static function dba()
39         {
40                 return self::$dice->create(Database\Database::class);
41         }
42
43         //
44         // "App" namespace instances
45         //
46
47         /**
48          * @return App\Authentication
49          */
50         public static function auth()
51         {
52                 return self::$dice->create(App\Authentication::class);
53         }
54
55         /**
56          * @return App\Arguments
57          */
58         public static function args()
59         {
60                 return self::$dice->create(App\Arguments::class);
61         }
62
63         /**
64          * @return App\BaseURL
65          */
66         public static function baseUrl()
67         {
68                 return self::$dice->create(App\BaseURL::class);
69         }
70
71         /**
72          * @return App\Mode
73          */
74         public static function mode()
75         {
76                 return self::$dice->create(App\Mode::class);
77         }
78
79         /**
80          * @return App\Module
81          */
82         public static function module()
83         {
84                 return self::$dice->create(App\Module::class);
85         }
86
87         /**
88          * @return App\Page
89          */
90         public static function page()
91         {
92                 return self::$dice->create(App\Page::class);
93         }
94
95         /**
96          * @return App\Router
97          */
98         public static function router()
99         {
100                 return self::$dice->create(App\Router::class);
101         }
102
103         //
104         // "Content" namespace instances
105         //
106
107         /**
108          * @return Content\Item
109          */
110         public static function contentItem()
111         {
112                 return self::$dice->create(Content\Item::class);
113         }
114
115         /**
116          * @return Content\Text\BBCode\Video
117          */
118         public static function bbCodeVideo()
119         {
120                 return self::$dice->create(Content\Text\BBCode\Video::class);
121         }
122
123         //
124         // "Core" namespace instances
125         //
126
127         /**
128          * @return Core\Cache\ICache
129          */
130         public static function cache()
131         {
132                 return self::$dice->create(Core\Cache\ICache::class);
133         }
134
135         /**
136          * @return Core\Config\IConfig
137          */
138         public static function config()
139         {
140                 return self::$dice->create(Core\Config\IConfig::class);
141         }
142
143         /**
144          * @return \Friendica\Core\PConfig\IPConfig
145          */
146         public static function pConfig()
147         {
148                 return self::$dice->create(Core\PConfig\IPConfig::class);
149         }
150
151         /**
152          * @return Core\Lock\ILock
153          */
154         public static function lock()
155         {
156                 return self::$dice->create(Core\Lock\ILock::class);
157         }
158
159         /**
160          * @return Core\L10n
161          */
162         public static function l10n()
163         {
164                 return self::$dice->create(Core\L10n::class);
165         }
166
167         /**
168          * @return Core\Process
169          */
170         public static function process()
171         {
172                 return self::$dice->create(Core\Process::class);
173         }
174
175         /**
176          * @return Core\Session\ISession
177          */
178         public static function session()
179         {
180                 return self::$dice->create(Core\Session\ISession::class);
181         }
182
183         /**
184          * @return Core\StorageManager
185          */
186         public static function storageManager()
187         {
188                 return self::$dice->create(Core\StorageManager::class);
189         }
190
191         //
192         // "LoggerInterface" instances
193         //
194
195         /**
196          * @return LoggerInterface
197          */
198         public static function logger()
199         {
200                 return self::$dice->create(LoggerInterface::class);
201         }
202
203         /**
204          * @return LoggerInterface
205          */
206         public static function devLogger()
207         {
208                 return self::$dice->create('$devLogger');
209         }
210
211         /**
212          * @return LoggerInterface
213          */
214         public static function workerLogger()
215         {
216                 return self::$dice->create(Util\Logger\WorkerLogger::class);
217         }
218
219         //
220         // "Factory" namespace instances
221         //
222
223         /**
224          * @return Factory\Mastodon\Account
225          */
226         public static function mstdnAccount()
227         {
228                 return self::$dice->create(Factory\Mastodon\Account::class);
229         }
230
231         /**
232          * @return Factory\Mastodon\FollowRequest
233          */
234         public static function mstdnFollowRequest()
235         {
236                 return self::$dice->create(Factory\Mastodon\FollowRequest::class);
237         }
238
239         /**
240          * @return Factory\Mastodon\Relationship
241          */
242         public static function mstdnRelationship()
243         {
244                 return self::$dice->create(Factory\Mastodon\Relationship::class);
245         }
246
247         //
248         // "Model" namespace instances
249         //
250
251         /**
252          * @return Model\User\Cookie
253          */
254         public static function cookie()
255         {
256                 return self::$dice->create(Model\User\Cookie::class);
257         }
258
259         /**
260          * @return Model\Notification
261          */
262         public static function notification()
263         {
264                 return self::$dice->create(Model\Notification::class);
265         }
266
267         /**
268          * @return Model\Storage\IStorage
269          */
270         public static function storage()
271         {
272                 return self::$dice->create(Model\Storage\IStorage::class);
273         }
274
275         //
276         // "Repository" namespace
277         //
278
279         /**
280          * @return Repository\Introduction
281          */
282         public static function intro()
283         {
284                 return self::$dice->create(Repository\Introduction::class);
285         }
286
287         /**
288          * @return Repository\PermissionSet
289          */
290         public static function permissionSet()
291         {
292                 return self::$dice->create(Repository\PermissionSet::class);
293         }
294
295         /**
296          * @return Repository\ProfileField
297          */
298         public static function profileField()
299         {
300                 return self::$dice->create(Repository\ProfileField::class);
301         }
302
303         //
304         // "Protocol" namespace instances
305         //
306
307         /**
308          * @return Protocol\Activity
309          */
310         public static function activity()
311         {
312                 return self::$dice->create(Protocol\Activity::class);
313         }
314
315         //
316         // "Util" namespace instances
317         //
318
319         /**
320          * @return Util\ACLFormatter
321          */
322         public static function aclFormatter()
323         {
324                 return self::$dice->create(Util\ACLFormatter::class);
325         }
326
327         /**
328          * @return Util\DateTimeFormat
329          */
330         public static function dtFormat()
331         {
332                 return self::$dice->create(Util\DateTimeFormat::class);
333         }
334
335         /**
336          * @return Util\FileSystem
337          */
338         public static function fs()
339         {
340                 return self::$dice->create(Util\FileSystem::class);
341         }
342
343         /**
344          * @return Util\Profiler
345          */
346         public static function profiler()
347         {
348                 return self::$dice->create(Util\Profiler::class);
349         }
350 }