IT translations 100% THX Sylke Vicious
[friendica.git/.git] / src / DI.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica;
23
24 use Dice\Dice;
25 use Psr\Log\LoggerInterface;
26
27 /**
28  * This class is capable of getting all dynamic created classes
29  *
30  * @see https://designpatternsphp.readthedocs.io/en/latest/Structural/Registry/README.html
31  */
32 abstract class DI
33 {
34         /** @var Dice */
35         private static $dice;
36
37         public static function init(Dice $dice)
38         {
39                 self::$dice = $dice;
40         }
41
42         //
43         // common instances
44         //
45
46         /**
47          * @return App
48          */
49         public static function app()
50         {
51                 return self::$dice->create(App::class);
52         }
53
54         /**
55          * @return Database\Database
56          */
57         public static function dba()
58         {
59                 return self::$dice->create(Database\Database::class);
60         }
61
62         //
63         // "App" namespace instances
64         //
65
66         /**
67          * @return App\Arguments
68          */
69         public static function args()
70         {
71                 return self::$dice->create(App\Arguments::class);
72         }
73
74         /**
75          * @return App\BaseURL
76          */
77         public static function baseUrl()
78         {
79                 return self::$dice->create(App\BaseURL::class);
80         }
81
82         /**
83          * @return App\Mode
84          */
85         public static function mode()
86         {
87                 return self::$dice->create(App\Mode::class);
88         }
89
90         /**
91          * @return App\Module
92          */
93         public static function module()
94         {
95                 return self::$dice->create(App\Module::class);
96         }
97
98         /**
99          * @return App\Page
100          */
101         public static function page()
102         {
103                 return self::$dice->create(App\Page::class);
104         }
105
106         /**
107          * @return App\Router
108          */
109         public static function router()
110         {
111                 return self::$dice->create(App\Router::class);
112         }
113
114         //
115         // "Content" namespace instances
116         //
117
118         /**
119          * @return Content\Item
120          */
121         public static function contentItem()
122         {
123                 return self::$dice->create(Content\Item::class);
124         }
125
126         /**
127          * @return Content\Text\BBCode\Video
128          */
129         public static function bbCodeVideo()
130         {
131                 return self::$dice->create(Content\Text\BBCode\Video::class);
132         }
133
134         //
135         // "Core" namespace instances
136         //
137
138         /**
139          * @return Core\Cache\ICache
140          */
141         public static function cache()
142         {
143                 return self::$dice->create(Core\Cache\ICache::class);
144         }
145
146         /**
147          * @return Core\Config\IConfig
148          */
149         public static function config()
150         {
151                 return self::$dice->create(Core\Config\IConfig::class);
152         }
153
154         /**
155          * @return Core\PConfig\IPConfig
156          */
157         public static function pConfig()
158         {
159                 return self::$dice->create(Core\PConfig\IPConfig::class);
160         }
161
162         /**
163          * @return Core\Lock\ILock
164          */
165         public static function lock()
166         {
167                 return self::$dice->create(Core\Lock\ILock::class);
168         }
169
170         /**
171          * @return Core\L10n
172          */
173         public static function l10n()
174         {
175                 return self::$dice->create(Core\L10n::class);
176         }
177
178         /**
179          * @return Core\Process
180          */
181         public static function process()
182         {
183                 return self::$dice->create(Core\Process::class);
184         }
185
186         /**
187          * @return Core\Session\ISession
188          */
189         public static function session()
190         {
191                 return self::$dice->create(Core\Session\ISession::class);
192         }
193
194         /**
195          * @return Core\StorageManager
196          */
197         public static function storageManager()
198         {
199                 return self::$dice->create(Core\StorageManager::class);
200         }
201
202         //
203         // "LoggerInterface" instances
204         //
205
206         /**
207          * @return LoggerInterface
208          */
209         public static function logger()
210         {
211                 return self::$dice->create(LoggerInterface::class);
212         }
213
214         /**
215          * @return LoggerInterface
216          */
217         public static function devLogger()
218         {
219                 return self::$dice->create('$devLogger');
220         }
221
222         /**
223          * @return LoggerInterface
224          */
225         public static function workerLogger()
226         {
227                 return self::$dice->create(Util\Logger\WorkerLogger::class);
228         }
229
230         //
231         // "Factory" namespace instances
232         //
233
234         /**
235          * @return Factory\Api\Mastodon\Account
236          */
237         public static function mstdnAccount()
238         {
239                 return self::$dice->create(Factory\Api\Mastodon\Account::class);
240         }
241
242         /**
243          * @return Factory\Api\Mastodon\Emoji
244          */
245         public static function mstdnEmoji()
246         {
247                 return self::$dice->create(Factory\Api\Mastodon\Emoji::class);
248         }
249
250         /**
251          * @return Factory\Api\Mastodon\Field
252          */
253         public static function mstdnField()
254         {
255                 return self::$dice->create(Factory\Api\Mastodon\Field::class);
256         }
257
258         /**
259          * @return Factory\Api\Mastodon\FollowRequest
260          */
261         public static function mstdnFollowRequest()
262         {
263                 return self::$dice->create(Factory\Api\Mastodon\FollowRequest::class);
264         }
265
266         /**
267          * @return Factory\Api\Mastodon\Relationship
268          */
269         public static function mstdnRelationship()
270         {
271                 return self::$dice->create(Factory\Api\Mastodon\Relationship::class);
272         }
273
274         /**
275          * @return Factory\Api\Mastodon\Status
276          */
277         public static function mstdnStatus()
278         {
279                 return self::$dice->create(Factory\Api\Mastodon\Status::class);
280         }
281
282         /**
283          * @return Factory\Api\Twitter\User
284          */
285         public static function twitterUser()
286         {
287                 return self::$dice->create(Factory\Api\Twitter\User::class);
288         }
289
290         /**
291          * @return Factory\Notification\Notification
292          */
293         public static function notification()
294         {
295                 return self::$dice->create(Factory\Notification\Notification::class);
296         }
297
298         /**
299          * @return Factory\Notification\Introduction
300          */
301         public static function notificationIntro()
302         {
303                 return self::$dice->create(Factory\Notification\Introduction::class);
304         }
305
306         //
307         // "Model" namespace instances
308         //
309         /**
310          * @return Model\Process
311          */
312         public static function modelProcess()
313         {
314                 return self::$dice->create(Model\Process::class);
315         }
316
317         /**
318          * @return Model\User\Cookie
319          */
320         public static function cookie()
321         {
322                 return self::$dice->create(Model\User\Cookie::class);
323         }
324
325         /**
326          * @return Model\Storage\IStorage
327          */
328         public static function storage()
329         {
330                 return self::$dice->create(Model\Storage\IStorage::class);
331         }
332
333         //
334         // "Network" namespace
335         //
336
337         /**
338          * @return Network\IHTTPRequest
339          */
340         public static function httpRequest()
341         {
342                 return self::$dice->create(Network\IHTTPRequest::class);
343         }
344
345         //
346         // "Repository" namespace
347         //
348
349         /**
350          * @return Repository\FSuggest;
351          */
352         public static function fsuggest()
353         {
354                 return self::$dice->create(Repository\FSuggest::class);
355         }
356
357         /**
358          * @return Repository\Introduction
359          */
360         public static function intro()
361         {
362                 return self::$dice->create(Repository\Introduction::class);
363         }
364
365         /**
366          * @return Repository\PermissionSet
367          */
368         public static function permissionSet()
369         {
370                 return self::$dice->create(Repository\PermissionSet::class);
371         }
372
373         /**
374          * @return Repository\ProfileField
375          */
376         public static function profileField()
377         {
378                 return self::$dice->create(Repository\ProfileField::class);
379         }
380
381         /**
382          * @return Repository\Notify
383          */
384         public static function notify()
385         {
386                 return self::$dice->create(Repository\Notify::class);
387         }
388
389         //
390         // "Protocol" namespace instances
391         //
392
393         /**
394          * @return Protocol\Activity
395          */
396         public static function activity()
397         {
398                 return self::$dice->create(Protocol\Activity::class);
399         }
400
401         //
402         // "Security" namespace instances
403         //
404
405         /**
406          * @return \Friendica\Security\Authentication
407          */
408         public static function auth()
409         {
410                 return self::$dice->create(Security\Authentication::class);
411         }
412
413         //
414         // "Util" namespace instances
415         //
416
417         /**
418          * @return Util\ACLFormatter
419          */
420         public static function aclFormatter()
421         {
422                 return self::$dice->create(Util\ACLFormatter::class);
423         }
424
425         /**
426          * @return string
427          */
428         public static function basePath()
429         {
430                 return self::$dice->create('$basepath');
431         }
432
433         /**
434          * @return Util\DateTimeFormat
435          */
436         public static function dtFormat()
437         {
438                 return self::$dice->create(Util\DateTimeFormat::class);
439         }
440
441         /**
442          * @return Util\FileSystem
443          */
444         public static function fs()
445         {
446                 return self::$dice->create(Util\FileSystem::class);
447         }
448
449         /**
450          * @return Util\Profiler
451          */
452         public static function profiler()
453         {
454                 return self::$dice->create(Util\Profiler::class);
455         }
456
457         /**
458          * @return Util\Emailer
459          */
460         public static function emailer()
461         {
462                 return self::$dice->create(Util\Emailer::class);
463         }
464 }