]> git.mxchange.org Git - friendica.git/blob - src/DI.php
1ba46e23edf37ccfc8dd0f2b331a443f1702bb18
[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 Friendica\Security\PermissionSet\Depository\PermissionSet;
26 use Psr\Log\LoggerInterface;
27
28 /**
29  * This class is capable of getting all dynamic created classes
30  *
31  * @see https://designpatternsphp.readthedocs.io/en/latest/Structural/Registry/README.html
32  */
33 abstract class DI
34 {
35         /** @var Dice */
36         private static $dice;
37
38         public static function init(Dice $dice)
39         {
40                 self::$dice = $dice;
41         }
42
43         /**
44          * Returns a clone of the current dice instance
45          * This usefull for overloading the current instance with mocked methods during tests
46          *
47          * @return Dice
48          */
49         public static function getDice()
50         {
51                 return clone self::$dice;
52         }
53
54         //
55         // common instances
56         //
57
58         /**
59          * @return App
60          */
61         public static function app()
62         {
63                 return self::$dice->create(App::class);
64         }
65
66         /**
67          * @return Database\Database
68          */
69         public static function dba()
70         {
71                 return self::$dice->create(Database\Database::class);
72         }
73
74         //
75         // "App" namespace instances
76         //
77
78         /**
79          * @return App\Arguments
80          */
81         public static function args()
82         {
83                 return self::$dice->create(App\Arguments::class);
84         }
85
86         /**
87          * @return App\BaseURL
88          */
89         public static function baseUrl()
90         {
91                 return self::$dice->create(App\BaseURL::class);
92         }
93
94         /**
95          * @return App\Mode
96          */
97         public static function mode()
98         {
99                 return self::$dice->create(App\Mode::class);
100         }
101
102         /**
103          * @return App\Module
104          */
105         public static function module()
106         {
107                 return self::$dice->create(App\Module::class);
108         }
109
110         /**
111          * @return App\Page
112          */
113         public static function page()
114         {
115                 return self::$dice->create(App\Page::class);
116         }
117
118         /**
119          * @return App\Router
120          */
121         public static function router()
122         {
123                 return self::$dice->create(App\Router::class);
124         }
125
126         //
127         // "Content" namespace instances
128         //
129
130         /**
131          * @return Content\Item
132          */
133         public static function contentItem()
134         {
135                 return self::$dice->create(Content\Item::class);
136         }
137
138         /**
139          * @return Content\Conversation
140          */
141         public static function conversation()
142         {
143                 return self::$dice->create(Content\Conversation::class);
144         }
145
146         /**
147          * @return Content\Text\BBCode\Video
148          */
149         public static function bbCodeVideo()
150         {
151                 return self::$dice->create(Content\Text\BBCode\Video::class);
152         }
153
154         //
155         // "Core" namespace instances
156         //
157
158         /**
159          * @return Core\Cache\ICache
160          */
161         public static function cache()
162         {
163                 return self::$dice->create(Core\Cache\ICache::class);
164         }
165
166         /**
167          * @return Core\Config\IConfig
168          */
169         public static function config()
170         {
171                 return self::$dice->create(Core\Config\IConfig::class);
172         }
173
174         /**
175          * @return Core\PConfig\IPConfig
176          */
177         public static function pConfig()
178         {
179                 return self::$dice->create(Core\PConfig\IPConfig::class);
180         }
181
182         /**
183          * @return Core\Lock\ILock
184          */
185         public static function lock()
186         {
187                 return self::$dice->create(Core\Lock\ILock::class);
188         }
189
190         /**
191          * @return Core\L10n
192          */
193         public static function l10n()
194         {
195                 return self::$dice->create(Core\L10n::class);
196         }
197
198         /**
199          * @return Core\Process
200          */
201         public static function process()
202         {
203                 return self::$dice->create(Core\Process::class);
204         }
205
206         /**
207          * @return Core\Session\ISession
208          */
209         public static function session()
210         {
211                 return self::$dice->create(Core\Session\ISession::class);
212         }
213
214         /**
215          * @return Core\StorageManager
216          */
217         public static function storageManager()
218         {
219                 return self::$dice->create(Core\StorageManager::class);
220         }
221
222         //
223         // "LoggerInterface" instances
224         //
225
226         /**
227          * @return LoggerInterface
228          */
229         public static function logger()
230         {
231                 return self::$dice->create(LoggerInterface::class);
232         }
233
234         /**
235          * @return LoggerInterface
236          */
237         public static function devLogger()
238         {
239                 return self::$dice->create('$devLogger');
240         }
241
242         /**
243          * @return LoggerInterface
244          */
245         public static function workerLogger()
246         {
247                 return self::$dice->create(Util\Logger\WorkerLogger::class);
248         }
249
250         //
251         // "Factory" namespace instances
252         //
253
254         /**
255          * @return Factory\Api\Mastodon\Account
256          */
257         public static function mstdnAccount()
258         {
259                 return self::$dice->create(Factory\Api\Mastodon\Account::class);
260         }
261
262         /**
263          * @return Factory\Api\Mastodon\Application
264          */
265         public static function mstdnApplication()
266         {
267                 return self::$dice->create(Factory\Api\Mastodon\Application::class);
268         }
269
270         /**
271          * @return Factory\Api\Mastodon\Attachment
272          */
273         public static function mstdnAttachment()
274         {
275                 return self::$dice->create(Factory\Api\Mastodon\Attachment::class);
276         }
277
278         /**
279          * @return Factory\Api\Mastodon\Card
280          */
281         public static function mstdnCard()
282         {
283                 return self::$dice->create(Factory\Api\Mastodon\Card::class);
284         }
285
286         /**
287          * @return Factory\Api\Mastodon\Conversation
288          */
289         public static function mstdnConversation()
290         {
291                 return self::$dice->create(Factory\Api\Mastodon\Conversation::class);
292         }
293
294         /**
295          * @return Factory\Api\Mastodon\Emoji
296          */
297         public static function mstdnEmoji()
298         {
299                 return self::$dice->create(Factory\Api\Mastodon\Emoji::class);
300         }
301
302         /**
303          * @return Factory\Api\Mastodon\Error
304          */
305         public static function mstdnError()
306         {
307                 return self::$dice->create(Factory\Api\Mastodon\Error::class);
308         }
309
310         /**
311          * @return Factory\Api\Mastodon\FollowRequest
312          */
313         public static function mstdnFollowRequest()
314         {
315                 return self::$dice->create(Factory\Api\Mastodon\FollowRequest::class);
316         }
317
318         /**
319          * @return Factory\Api\Mastodon\Relationship
320          */
321         public static function mstdnRelationship()
322         {
323                 return self::$dice->create(Factory\Api\Mastodon\Relationship::class);
324         }
325
326         /**
327          * @return Factory\Api\Mastodon\Status
328          */
329         public static function mstdnStatus()
330         {
331                 return self::$dice->create(Factory\Api\Mastodon\Status::class);
332         }
333
334         /**
335          * @return Factory\Api\Mastodon\ScheduledStatus
336          */
337         public static function mstdnScheduledStatus()
338         {
339                 return self::$dice->create(Factory\Api\Mastodon\ScheduledStatus::class);
340         }
341
342         /**
343          * @return Factory\Api\Mastodon\Subscription
344          */
345         public static function mstdnSubscription()
346         {
347                 return self::$dice->create(Factory\Api\Mastodon\Subscription::class);
348         }
349
350         /**
351          * @return Factory\Api\Mastodon\ListEntity
352          */
353         public static function mstdnList()
354         {
355                 return self::$dice->create(Factory\Api\Mastodon\ListEntity::class);
356         }
357
358         /**
359          * @return Factory\Api\Mastodon\Notification
360          */
361         public static function mstdnNotification()
362         {
363                 return self::$dice->create(Factory\Api\Mastodon\Notification::class);
364         }
365
366         /**
367          * @return Factory\Api\Twitter\User
368          */
369         public static function twitterUser()
370         {
371                 return self::$dice->create(Factory\Api\Twitter\User::class);
372         }
373
374         public static function notificationIntro(): Navigation\Notifications\Factory\Introduction
375         {
376                 return self::$dice->create(Navigation\Notifications\Factory\Introduction::class);
377         }
378
379         //
380         // "Model" namespace instances
381         //
382         /**
383          * @return Model\Process
384          */
385         public static function modelProcess()
386         {
387                 return self::$dice->create(Model\Process::class);
388         }
389
390         /**
391          * @return Model\User\Cookie
392          */
393         public static function cookie()
394         {
395                 return self::$dice->create(Model\User\Cookie::class);
396         }
397
398         /**
399          * @return Model\Storage\IWritableStorage
400          */
401         public static function storage()
402         {
403                 return self::$dice->create(Model\Storage\IWritableStorage::class);
404         }
405
406         /**
407          * @return Model\Log\ParsedLogIterator
408          */
409         public static function parsedLogIterator()
410         {
411                 return self::$dice->create(Model\Log\ParsedLogIterator::class);
412         }
413
414         //
415         // "Network" namespace
416         //
417
418         /**
419          * @return Network\IHTTPClient
420          */
421         public static function httpClient()
422         {
423                 return self::$dice->create(Network\IHTTPClient::class);
424         }
425
426         //
427         // "Repository" namespace
428         //
429
430         /**
431          * @return Repository\FSuggest;
432          */
433         public static function fsuggest()
434         {
435                 return self::$dice->create(Repository\FSuggest::class);
436         }
437
438         /**
439          * @return Repository\Introduction
440          */
441         public static function intro()
442         {
443                 return self::$dice->create(Repository\Introduction::class);
444         }
445
446         /**
447          * @return PermissionSet
448          */
449         public static function permissionSet()
450         {
451                 return self::$dice->create(PermissionSet::class);
452         }
453
454         /**
455          * @return \Friendica\Security\PermissionSet\Factory\PermissionSet
456          */
457         public static function permissionSetFactory()
458         {
459                 return self::$dice->create(\Friendica\Security\PermissionSet\Factory\PermissionSet::class);
460         }
461
462         /**
463          * @return Repository\ProfileField
464          */
465         public static function profileField()
466         {
467                 return self::$dice->create(Repository\ProfileField::class);
468         }
469
470         public static function notification(): Navigation\Notifications\Depository\Notification
471         {
472                 return self::$dice->create(Navigation\Notifications\Depository\Notification::class);
473         }
474
475         public static function notificationFactory(): Navigation\Notifications\Factory\Notification
476         {
477                 return self::$dice->create(Navigation\Notifications\Factory\Notification::class);
478         }
479
480         public static function notify(): Navigation\Notifications\Depository\Notify
481         {
482                 return self::$dice->create(Navigation\Notifications\Depository\Notify::class);
483         }
484
485         public static function notifyFactory(): Navigation\Notifications\Factory\Notify
486         {
487                 return self::$dice->create(Navigation\Notifications\Factory\Notify::class);
488         }
489
490         public static function formattedNotificationFactory(): Navigation\Notifications\Factory\FormattedNotification
491         {
492                 return self::$dice->create(Navigation\Notifications\Factory\FormattedNotification::class);
493         }
494
495         //
496         // "Protocol" namespace instances
497         //
498
499         /**
500          * @return Protocol\Activity
501          */
502         public static function activity()
503         {
504                 return self::$dice->create(Protocol\Activity::class);
505         }
506
507         //
508         // "Security" namespace instances
509         //
510
511         /**
512          * @return \Friendica\Security\Authentication
513          */
514         public static function auth()
515         {
516                 return self::$dice->create(Security\Authentication::class);
517         }
518
519         //
520         // "Util" namespace instances
521         //
522
523         /**
524          * @return Util\ACLFormatter
525          */
526         public static function aclFormatter()
527         {
528                 return self::$dice->create(Util\ACLFormatter::class);
529         }
530
531         /**
532          * @return string
533          */
534         public static function basePath()
535         {
536                 return self::$dice->create('$basepath');
537         }
538
539         /**
540          * @return Util\DateTimeFormat
541          */
542         public static function dtFormat()
543         {
544                 return self::$dice->create(Util\DateTimeFormat::class);
545         }
546
547         /**
548          * @return Util\FileSystem
549          */
550         public static function fs()
551         {
552                 return self::$dice->create(Util\FileSystem::class);
553         }
554
555         /**
556          * @return Util\Profiler
557          */
558         public static function profiler()
559         {
560                 return self::$dice->create(Util\Profiler::class);
561         }
562
563         /**
564          * @return Util\Emailer
565          */
566         public static function emailer()
567         {
568                 return self::$dice->create(Util\Emailer::class);
569         }
570 }