]> git.mxchange.org Git - friendica.git/blob - src/DI.php
Refactor IStorage
[friendica.git] / src / DI.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, the Friendica project
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\Application
244          */
245         public static function mstdnApplication()
246         {
247                 return self::$dice->create(Factory\Api\Mastodon\Application::class);
248         }
249
250         /**
251          * @return Factory\Api\Mastodon\Attachment
252          */
253         public static function mstdnAttachment()
254         {
255                 return self::$dice->create(Factory\Api\Mastodon\Attachment::class);
256         }
257
258         /**
259          * @return Factory\Api\Mastodon\Card
260          */
261         public static function mstdnCard()
262         {
263                 return self::$dice->create(Factory\Api\Mastodon\Card::class);
264         }
265
266         /**
267          * @return Factory\Api\Mastodon\Conversation
268          */
269         public static function mstdnConversation()
270         {
271                 return self::$dice->create(Factory\Api\Mastodon\Conversation::class);
272         }
273
274         /**
275          * @return Factory\Api\Mastodon\Emoji
276          */
277         public static function mstdnEmoji()
278         {
279                 return self::$dice->create(Factory\Api\Mastodon\Emoji::class);
280         }
281
282         /**
283          * @return Factory\Api\Mastodon\Error
284          */
285         public static function mstdnError()
286         {
287                 return self::$dice->create(Factory\Api\Mastodon\Error::class);
288         }
289
290         /**
291          * @return Factory\Api\Mastodon\FollowRequest
292          */
293         public static function mstdnFollowRequest()
294         {
295                 return self::$dice->create(Factory\Api\Mastodon\FollowRequest::class);
296         }
297
298         /**
299          * @return Factory\Api\Mastodon\Relationship
300          */
301         public static function mstdnRelationship()
302         {
303                 return self::$dice->create(Factory\Api\Mastodon\Relationship::class);
304         }
305
306         /**
307          * @return Factory\Api\Mastodon\Status
308          */
309         public static function mstdnStatus()
310         {
311                 return self::$dice->create(Factory\Api\Mastodon\Status::class);
312         }
313
314         /**
315          * @return Factory\Api\Mastodon\ScheduledStatus
316          */
317         public static function mstdnScheduledStatus()
318         {
319                 return self::$dice->create(Factory\Api\Mastodon\ScheduledStatus::class);
320         }
321
322         /**
323          * @return Factory\Api\Mastodon\Subscription
324          */
325         public static function mstdnSubscription()
326         {
327                 return self::$dice->create(Factory\Api\Mastodon\Subscription::class);
328         }
329
330         /**
331          * @return Factory\Api\Mastodon\ListEntity
332          */
333         public static function mstdnList()
334         {
335                 return self::$dice->create(Factory\Api\Mastodon\ListEntity::class);
336         }
337
338         /**
339          * @return Factory\Api\Mastodon\Notification
340          */
341         public static function mstdnNotification()
342         {
343                 return self::$dice->create(Factory\Api\Mastodon\Notification::class);
344         }
345
346         /**
347          * @return Factory\Api\Twitter\User
348          */
349         public static function twitterUser()
350         {
351                 return self::$dice->create(Factory\Api\Twitter\User::class);
352         }
353
354         /**
355          * @return Factory\Notification\Notification
356          */
357         public static function notification()
358         {
359                 return self::$dice->create(Factory\Notification\Notification::class);
360         }
361
362         /**
363          * @return Factory\Notification\Introduction
364          */
365         public static function notificationIntro()
366         {
367                 return self::$dice->create(Factory\Notification\Introduction::class);
368         }
369
370         //
371         // "Model" namespace instances
372         //
373         /**
374          * @return Model\Process
375          */
376         public static function modelProcess()
377         {
378                 return self::$dice->create(Model\Process::class);
379         }
380
381         /**
382          * @return Model\User\Cookie
383          */
384         public static function cookie()
385         {
386                 return self::$dice->create(Model\User\Cookie::class);
387         }
388
389         /**
390          * @return Model\Storage\ISelectableStorage
391          */
392         public static function storage()
393         {
394                 return self::$dice->create(Model\Storage\ISelectableStorage::class);
395         }
396
397         //
398         // "Network" namespace
399         //
400
401         /**
402          * @return Network\IHTTPRequest
403          */
404         public static function httpRequest()
405         {
406                 return self::$dice->create(Network\IHTTPRequest::class);
407         }
408
409         //
410         // "Repository" namespace
411         //
412
413         /**
414          * @return Repository\FSuggest;
415          */
416         public static function fsuggest()
417         {
418                 return self::$dice->create(Repository\FSuggest::class);
419         }
420
421         /**
422          * @return Repository\Introduction
423          */
424         public static function intro()
425         {
426                 return self::$dice->create(Repository\Introduction::class);
427         }
428
429         /**
430          * @return Repository\PermissionSet
431          */
432         public static function permissionSet()
433         {
434                 return self::$dice->create(Repository\PermissionSet::class);
435         }
436
437         /**
438          * @return Repository\ProfileField
439          */
440         public static function profileField()
441         {
442                 return self::$dice->create(Repository\ProfileField::class);
443         }
444
445         /**
446          * @return Repository\Notification
447          */
448         public static function notify()
449         {
450                 return self::$dice->create(Repository\Notification::class);
451         }
452
453         //
454         // "Protocol" namespace instances
455         //
456
457         /**
458          * @return Protocol\Activity
459          */
460         public static function activity()
461         {
462                 return self::$dice->create(Protocol\Activity::class);
463         }
464
465         //
466         // "Security" namespace instances
467         //
468
469         /**
470          * @return \Friendica\Security\Authentication
471          */
472         public static function auth()
473         {
474                 return self::$dice->create(Security\Authentication::class);
475         }
476
477         //
478         // "Util" namespace instances
479         //
480
481         /**
482          * @return Util\ACLFormatter
483          */
484         public static function aclFormatter()
485         {
486                 return self::$dice->create(Util\ACLFormatter::class);
487         }
488
489         /**
490          * @return string
491          */
492         public static function basePath()
493         {
494                 return self::$dice->create('$basepath');
495         }
496
497         /**
498          * @return Util\DateTimeFormat
499          */
500         public static function dtFormat()
501         {
502                 return self::$dice->create(Util\DateTimeFormat::class);
503         }
504
505         /**
506          * @return Util\FileSystem
507          */
508         public static function fs()
509         {
510                 return self::$dice->create(Util\FileSystem::class);
511         }
512
513         /**
514          * @return Util\Profiler
515          */
516         public static function profiler()
517         {
518                 return self::$dice->create(Util\Profiler::class);
519         }
520
521         /**
522          * @return Util\Emailer
523          */
524         public static function emailer()
525         {
526                 return self::$dice->create(Util\Emailer::class);
527         }
528 }