]> git.mxchange.org Git - friendica.git/blob - src/DI.php
AP: We can now store received reports
[friendica.git] / src / DI.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, 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\Core\Session\Capability\IHandleSessions;
26 use Friendica\Core\Session\Capability\IHandleUserSessions;
27 use Friendica\Navigation\SystemMessages;
28 use Psr\Log\LoggerInterface;
29
30 /**
31  * This class is capable of getting all dynamic created classes
32  *
33  * @see https://designpatternsphp.readthedocs.io/en/latest/Structural/Registry/README.html
34  */
35 abstract class DI
36 {
37         /** @var Dice */
38         private static $dice;
39
40         public static function init(Dice $dice)
41         {
42                 self::$dice = $dice;
43         }
44
45         /**
46          * Returns a clone of the current dice instance
47          * This usefull for overloading the current instance with mocked methods during tests
48          *
49          * @return Dice
50          */
51         public static function getDice()
52         {
53                 return clone self::$dice;
54         }
55
56         //
57         // common instances
58         //
59
60         /**
61          * @return App
62          */
63         public static function app()
64         {
65                 return self::$dice->create(App::class);
66         }
67
68         /**
69          * @return Database\Database
70          */
71         public static function dba(): Database\Database
72         {
73                 return self::$dice->create(Database\Database::class);
74         }
75
76         /**
77          * @return \Friendica\Database\Definition\DbaDefinition
78          */
79         public static function dbaDefinition(): Database\Definition\DbaDefinition
80         {
81                 return self::$dice->create(Database\Definition\DbaDefinition::class);
82         }
83
84         /**
85          * @return \Friendica\Database\Definition\ViewDefinition
86          */
87         public static function viewDefinition(): Database\Definition\ViewDefinition
88         {
89                 return self::$dice->create(Database\Definition\ViewDefinition::class);
90         }
91
92         //
93         // "App" namespace instances
94         //
95
96         /**
97          * @return App\Arguments
98          */
99         public static function args()
100         {
101                 return self::$dice->create(App\Arguments::class);
102         }
103
104         /**
105          * @return App\BaseURL
106          */
107         public static function baseUrl()
108         {
109                 return self::$dice->create(App\BaseURL::class);
110         }
111
112         /**
113          * @return App\Mode
114          */
115         public static function mode()
116         {
117                 return self::$dice->create(App\Mode::class);
118         }
119
120         /**
121          * @return App\Page
122          */
123         public static function page()
124         {
125                 return self::$dice->create(App\Page::class);
126         }
127
128         /**
129          * @return App\Router
130          */
131         public static function router()
132         {
133                 return self::$dice->create(App\Router::class);
134         }
135
136         //
137         // "Content" namespace instances
138         //
139
140         /**
141          * @return Content\Item
142          */
143         public static function contentItem()
144         {
145                 return self::$dice->create(Content\Item::class);
146         }
147
148         /**
149          * @return Content\Conversation
150          */
151         public static function conversation()
152         {
153                 return self::$dice->create(Content\Conversation::class);
154         }
155
156         /**
157          * @return Content\Text\BBCode\Video
158          */
159         public static function bbCodeVideo()
160         {
161                 return self::$dice->create(Content\Text\BBCode\Video::class);
162         }
163
164         //
165         // "Core" namespace instances
166         //
167
168         /**
169          * @return Core\Cache\Capability\ICanCache
170          */
171         public static function cache()
172         {
173                 return self::$dice->create(Core\Cache\Capability\ICanCache::class);
174         }
175
176         /**
177          * @return Core\Config\Capability\IManageConfigValues
178          */
179         public static function config()
180         {
181                 return self::$dice->create(Core\Config\Capability\IManageConfigValues::class);
182         }
183
184         /**
185          * @return Core\PConfig\Capability\IManagePersonalConfigValues
186          */
187         public static function pConfig()
188         {
189                 return self::$dice->create(Core\PConfig\Capability\IManagePersonalConfigValues::class);
190         }
191
192         /**
193          * @return Core\Lock\Capability\ICanLock
194          */
195         public static function lock()
196         {
197                 return self::$dice->create(Core\Lock\Capability\ICanLock::class);
198         }
199
200         /**
201          * @return Core\L10n
202          */
203         public static function l10n()
204         {
205                 return self::$dice->create(Core\L10n::class);
206         }
207
208         /**
209          * @return Core\Worker\Repository\Process
210          */
211         public static function process()
212         {
213                 return self::$dice->create(Core\Worker\Repository\Process::class);
214         }
215
216         public static function session(): IHandleSessions
217         {
218                 return self::$dice->create(Core\Session\Capability\IHandleSessions::class);
219         }
220
221         public static function userSession(): IHandleUserSessions
222         {
223                 return self::$dice->create(Core\Session\Capability\IHandleUserSessions::class);
224         }
225
226         /**
227          * @return \Friendica\Core\Storage\Repository\StorageManager
228          */
229         public static function storageManager()
230         {
231                 return self::$dice->create(Core\Storage\Repository\StorageManager::class);
232         }
233
234         /**
235          * @return \Friendica\Core\System
236          */
237         public static function system()
238         {
239                 return self::$dice->create(Core\System::class);
240         }
241
242         /**
243          * @return \Friendica\Navigation\SystemMessages
244          */
245         public static function sysmsg()
246         {
247                 return self::$dice->create(SystemMessages::class);
248         }
249
250         //
251         // "LoggerInterface" instances
252         //
253
254         /**
255          * Flushes the Logger instance, so the factory is called again
256          * (creates a new id and retrieves the current PID)
257          */
258         public static function flushLogger()
259         {
260                 $flushDice = self::$dice
261                         ->addRule(LoggerInterface::class, self::$dice->getRule(LoggerInterface::class))
262                         ->addRule('$devLogger', self::$dice->getRule('$devLogger'));
263                 static::init($flushDice);
264         }
265
266         /**
267          * @return LoggerInterface
268          */
269         public static function logger()
270         {
271                 return self::$dice->create(LoggerInterface::class);
272         }
273
274         /**
275          * @return LoggerInterface
276          */
277         public static function devLogger()
278         {
279                 return self::$dice->create('$devLogger');
280         }
281
282         /**
283          * @return LoggerInterface
284          */
285         public static function workerLogger()
286         {
287                 return self::$dice->create(Core\Logger\Type\WorkerLogger::class);
288         }
289
290         //
291         // "Factory" namespace instances
292         //
293
294         /**
295          * @return Factory\Api\Mastodon\Account
296          */
297         public static function mstdnAccount()
298         {
299                 return self::$dice->create(Factory\Api\Mastodon\Account::class);
300         }
301
302         /**
303          * @return Factory\Api\Mastodon\Application
304          */
305         public static function mstdnApplication()
306         {
307                 return self::$dice->create(Factory\Api\Mastodon\Application::class);
308         }
309
310         /**
311          * @return Factory\Api\Mastodon\Attachment
312          */
313         public static function mstdnAttachment()
314         {
315                 return self::$dice->create(Factory\Api\Mastodon\Attachment::class);
316         }
317
318         /**
319          * @return Factory\Api\Mastodon\Card
320          */
321         public static function mstdnCard()
322         {
323                 return self::$dice->create(Factory\Api\Mastodon\Card::class);
324         }
325
326         /**
327          * @return Factory\Api\Mastodon\Conversation
328          */
329         public static function mstdnConversation()
330         {
331                 return self::$dice->create(Factory\Api\Mastodon\Conversation::class);
332         }
333
334         /**
335          * @return Factory\Api\Mastodon\Emoji
336          */
337         public static function mstdnEmoji()
338         {
339                 return self::$dice->create(Factory\Api\Mastodon\Emoji::class);
340         }
341
342         /**
343          * @return Factory\Api\Mastodon\Error
344          */
345         public static function mstdnError()
346         {
347                 return self::$dice->create(Factory\Api\Mastodon\Error::class);
348         }
349
350         /**
351          * @return Factory\Api\Mastodon\FollowRequest
352          */
353         public static function mstdnFollowRequest()
354         {
355                 return self::$dice->create(Factory\Api\Mastodon\FollowRequest::class);
356         }
357
358         /**
359          * @return Factory\Api\Mastodon\Poll
360          */
361         public static function mstdnPoll()
362         {
363                 return self::$dice->create(Factory\Api\Mastodon\Poll::class);
364         }
365
366         /**
367          * @return Factory\Api\Mastodon\Relationship
368          */
369         public static function mstdnRelationship()
370         {
371                 return self::$dice->create(Factory\Api\Mastodon\Relationship::class);
372         }
373
374         /**
375          * @return Factory\Api\Mastodon\Status
376          */
377         public static function mstdnStatus()
378         {
379                 return self::$dice->create(Factory\Api\Mastodon\Status::class);
380         }
381
382         /**
383          * @return Factory\Api\Mastodon\StatusSource
384          */
385         public static function mstdnStatusSource()
386         {
387                 return self::$dice->create(Factory\Api\Mastodon\StatusSource::class);
388         }
389
390         /**
391          * @return Factory\Api\Mastodon\ScheduledStatus
392          */
393         public static function mstdnScheduledStatus()
394         {
395                 return self::$dice->create(Factory\Api\Mastodon\ScheduledStatus::class);
396         }
397
398         /**
399          * @return Factory\Api\Mastodon\Subscription
400          */
401         public static function mstdnSubscription()
402         {
403                 return self::$dice->create(Factory\Api\Mastodon\Subscription::class);
404         }
405
406         /**
407          * @return Factory\Api\Mastodon\ListEntity
408          */
409         public static function mstdnList()
410         {
411                 return self::$dice->create(Factory\Api\Mastodon\ListEntity::class);
412         }
413
414         /**
415          * @return Factory\Api\Mastodon\Notification
416          */
417         public static function mstdnNotification()
418         {
419                 return self::$dice->create(Factory\Api\Mastodon\Notification::class);
420         }
421
422         /**
423          * @return Factory\Api\Twitter\Status
424          */
425         public static function twitterStatus()
426         {
427                 return self::$dice->create(Factory\Api\Twitter\Status::class);
428         }
429
430         /**
431          * @return Factory\Api\Twitter\User
432          */
433         public static function twitterUser()
434         {
435                 return self::$dice->create(Factory\Api\Twitter\User::class);
436         }
437
438         public static function notificationIntro(): Navigation\Notifications\Factory\Introduction
439         {
440                 return self::$dice->create(Navigation\Notifications\Factory\Introduction::class);
441         }
442
443         //
444         // "Model" namespace instances
445         //
446         /**
447          * @return \Friendica\Core\Worker\Repository\Process
448          */
449         public static function modelProcess()
450         {
451                 return self::$dice->create(Core\Worker\Repository\Process::class);
452         }
453
454         /**
455          * @return Model\User\Cookie
456          */
457         public static function cookie()
458         {
459                 return self::$dice->create(Model\User\Cookie::class);
460         }
461
462         /**
463          * @return Core\Storage\Capability\ICanWriteToStorage
464          */
465         public static function storage()
466         {
467                 return self::$dice->create(Core\Storage\Capability\ICanWriteToStorage::class);
468         }
469
470         /**
471          * @return Model\Log\ParsedLogIterator
472          */
473         public static function parsedLogIterator()
474         {
475                 return self::$dice->create(Model\Log\ParsedLogIterator::class);
476         }
477
478         //
479         // "Module" namespace
480         //
481
482         public static function apiResponse(): Module\Api\ApiResponse
483         {
484                 return self::$dice->create(Module\Api\ApiResponse::class);
485         }
486
487         //
488         // "Network" namespace
489         //
490
491         /**
492          * @return Network\HTTPClient\Capability\ICanSendHttpRequests
493          */
494         public static function httpClient()
495         {
496                 return self::$dice->create(Network\HTTPClient\Capability\ICanSendHttpRequests::class);
497         }
498
499         //
500         // "Repository" namespace
501         //
502
503         /**
504          * @return Contact\FriendSuggest\Repository\FriendSuggest;
505          */
506         public static function fsuggest()
507         {
508                 return self::$dice->create(Contact\FriendSuggest\Repository\FriendSuggest::class);
509         }
510
511         /**
512          * @return Contact\FriendSuggest\Factory\FriendSuggest;
513          */
514         public static function fsuggestFactory()
515         {
516                 return self::$dice->create(Contact\FriendSuggest\Factory\FriendSuggest::class);
517         }
518
519         /**
520          * @return Contact\Introduction\Repository\Introduction
521          */
522         public static function intro()
523         {
524                 return self::$dice->create(Contact\Introduction\Repository\Introduction::class);
525         }
526
527         /**
528          * @return Contact\Introduction\Factory\Introduction
529          */
530         public static function introFactory()
531         {
532                 return self::$dice->create(Contact\Introduction\Factory\Introduction::class);
533         }
534
535         public static function report(): Moderation\Repository\Report
536         {
537                 return self::$dice->create(Moderation\Repository\Report::class);
538         }
539
540         public static function reportFactory(): Moderation\Factory\Report
541         {
542                 return self::$dice->create(Moderation\Factory\Report::class);
543         }
544
545         public static function localRelationship(): Contact\LocalRelationship\Repository\LocalRelationship
546         {
547                 return self::$dice->create(Contact\LocalRelationship\Repository\LocalRelationship::class);
548         }
549
550         public static function permissionSet(): Security\PermissionSet\Repository\PermissionSet
551         {
552                 return self::$dice->create(Security\PermissionSet\Repository\PermissionSet::class);
553         }
554
555         public static function permissionSetFactory(): Security\PermissionSet\Factory\PermissionSet
556         {
557                 return self::$dice->create(Security\PermissionSet\Factory\PermissionSet::class);
558         }
559
560         public static function profileField(): Profile\ProfileField\Repository\ProfileField
561         {
562                 return self::$dice->create(Profile\ProfileField\Repository\ProfileField::class);
563         }
564
565         public static function profileFieldFactory(): Profile\ProfileField\Factory\ProfileField
566         {
567                 return self::$dice->create(Profile\ProfileField\Factory\ProfileField::class);
568         }
569
570         public static function notification(): Navigation\Notifications\Repository\Notification
571         {
572                 return self::$dice->create(Navigation\Notifications\Repository\Notification::class);
573         }
574
575         public static function notificationFactory(): Navigation\Notifications\Factory\Notification
576         {
577                 return self::$dice->create(Navigation\Notifications\Factory\Notification::class);
578         }
579
580         public static function notify(): Navigation\Notifications\Repository\Notify
581         {
582                 return self::$dice->create(Navigation\Notifications\Repository\Notify::class);
583         }
584
585         public static function notifyFactory(): Navigation\Notifications\Factory\Notify
586         {
587                 return self::$dice->create(Navigation\Notifications\Factory\Notify::class);
588         }
589
590         public static function formattedNotificationFactory(): Navigation\Notifications\Factory\FormattedNotify
591         {
592                 return self::$dice->create(Navigation\Notifications\Factory\FormattedNotify::class);
593         }
594
595         public static function formattedNavNotificationFactory(): Navigation\Notifications\Factory\FormattedNavNotification
596         {
597                 return self::$dice->create(Navigation\Notifications\Factory\FormattedNavNotification::class);
598         }
599
600         //
601         // "Protocol" namespace instances
602         //
603
604         /**
605          * @return Protocol\Activity
606          */
607         public static function activity()
608         {
609                 return self::$dice->create(Protocol\Activity::class);
610         }
611
612         public static function dsprContact(): Protocol\Diaspora\Repository\DiasporaContact
613         {
614                 return self::$dice->create(Protocol\Diaspora\Repository\DiasporaContact::class);
615         }
616
617         //
618         // "Security" namespace instances
619         //
620
621         /**
622          * @return \Friendica\Security\Authentication
623          */
624         public static function auth()
625         {
626                 return self::$dice->create(Security\Authentication::class);
627         }
628
629         //
630         // "Util" namespace instances
631         //
632
633         /**
634          * @return Util\ACLFormatter
635          */
636         public static function aclFormatter()
637         {
638                 return self::$dice->create(Util\ACLFormatter::class);
639         }
640
641         /**
642          * @return string
643          */
644         public static function basePath()
645         {
646                 return self::$dice->create('$basepath');
647         }
648
649         /**
650          * @return Util\DateTimeFormat
651          */
652         public static function dtFormat()
653         {
654                 return self::$dice->create(Util\DateTimeFormat::class);
655         }
656
657         /**
658          * @return Util\FileSystem
659          */
660         public static function fs()
661         {
662                 return self::$dice->create(Util\FileSystem::class);
663         }
664
665         /**
666          * @return Util\Profiler
667          */
668         public static function profiler()
669         {
670                 return self::$dice->create(Util\Profiler::class);
671         }
672
673         /**
674          * @return Util\Emailer
675          */
676         public static function emailer()
677         {
678                 return self::$dice->create(Util\Emailer::class);
679         }
680 }