]> git.mxchange.org Git - friendica.git/blob - src/DI.php
Fix "Undefined constant Friendica\Content\Conversation::PARCEL_DIASPORA"
[friendica.git] / src / DI.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, 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         public static function configFileManager(): Core\Config\Util\ConfigFileManager
185         {
186                 return self::$dice->create(Core\Config\Util\ConfigFileManager::class);
187         }
188
189         public static function keyValue(): Core\KeyValueStorage\Capabilities\IManageKeyValuePairs
190         {
191                 return self::$dice->create(Core\KeyValueStorage\Capabilities\IManageKeyValuePairs::class);
192         }
193
194         /**
195          * @return Core\PConfig\Capability\IManagePersonalConfigValues
196          */
197         public static function pConfig()
198         {
199                 return self::$dice->create(Core\PConfig\Capability\IManagePersonalConfigValues::class);
200         }
201
202         /**
203          * @return Core\Lock\Capability\ICanLock
204          */
205         public static function lock()
206         {
207                 return self::$dice->create(Core\Lock\Capability\ICanLock::class);
208         }
209
210         /**
211          * @return Core\L10n
212          */
213         public static function l10n()
214         {
215                 return self::$dice->create(Core\L10n::class);
216         }
217
218         /**
219          * @return Core\Worker\Repository\Process
220          */
221         public static function process()
222         {
223                 return self::$dice->create(Core\Worker\Repository\Process::class);
224         }
225
226         public static function session(): IHandleSessions
227         {
228                 return self::$dice->create(Core\Session\Capability\IHandleSessions::class);
229         }
230
231         public static function userSession(): IHandleUserSessions
232         {
233                 return self::$dice->create(Core\Session\Capability\IHandleUserSessions::class);
234         }
235
236         /**
237          * @return \Friendica\Core\Storage\Repository\StorageManager
238          */
239         public static function storageManager()
240         {
241                 return self::$dice->create(Core\Storage\Repository\StorageManager::class);
242         }
243
244         /**
245          * @return \Friendica\Core\System
246          */
247         public static function system()
248         {
249                 return self::$dice->create(Core\System::class);
250         }
251
252         /**
253          * @return \Friendica\Navigation\SystemMessages
254          */
255         public static function sysmsg()
256         {
257                 return self::$dice->create(SystemMessages::class);
258         }
259
260         //
261         // "LoggerInterface" instances
262         //
263
264         /**
265          * Flushes the Logger instance, so the factory is called again
266          * (creates a new id and retrieves the current PID)
267          */
268         public static function flushLogger()
269         {
270                 $flushDice = self::$dice
271                         ->addRule(LoggerInterface::class, self::$dice->getRule(LoggerInterface::class))
272                         ->addRule('$devLogger', self::$dice->getRule('$devLogger'));
273                 static::init($flushDice);
274         }
275
276         /**
277          * @return LoggerInterface
278          */
279         public static function logger()
280         {
281                 return self::$dice->create(LoggerInterface::class);
282         }
283
284         /**
285          * @return LoggerInterface
286          */
287         public static function devLogger()
288         {
289                 return self::$dice->create('$devLogger');
290         }
291
292         /**
293          * @return LoggerInterface
294          */
295         public static function workerLogger()
296         {
297                 return self::$dice->create(Core\Logger\Type\WorkerLogger::class);
298         }
299
300         //
301         // "Factory" namespace instances
302         //
303
304         /**
305          * @return Factory\Api\Mastodon\Account
306          */
307         public static function mstdnAccount()
308         {
309                 return self::$dice->create(Factory\Api\Mastodon\Account::class);
310         }
311
312         /**
313          * @return Factory\Api\Mastodon\Application
314          */
315         public static function mstdnApplication()
316         {
317                 return self::$dice->create(Factory\Api\Mastodon\Application::class);
318         }
319
320         /**
321          * @return Factory\Api\Mastodon\Attachment
322          */
323         public static function mstdnAttachment()
324         {
325                 return self::$dice->create(Factory\Api\Mastodon\Attachment::class);
326         }
327
328         /**
329          * @return Factory\Api\Mastodon\Card
330          */
331         public static function mstdnCard()
332         {
333                 return self::$dice->create(Factory\Api\Mastodon\Card::class);
334         }
335
336         /**
337          * @return Factory\Api\Mastodon\Conversation
338          */
339         public static function mstdnConversation()
340         {
341                 return self::$dice->create(Factory\Api\Mastodon\Conversation::class);
342         }
343
344         /**
345          * @return Factory\Api\Mastodon\Emoji
346          */
347         public static function mstdnEmoji()
348         {
349                 return self::$dice->create(Factory\Api\Mastodon\Emoji::class);
350         }
351
352         /**
353          * @return Factory\Api\Mastodon\Error
354          */
355         public static function mstdnError()
356         {
357                 return self::$dice->create(Factory\Api\Mastodon\Error::class);
358         }
359
360         /**
361          * @return Factory\Api\Mastodon\FollowRequest
362          */
363         public static function mstdnFollowRequest()
364         {
365                 return self::$dice->create(Factory\Api\Mastodon\FollowRequest::class);
366         }
367
368         /**
369          * @return Factory\Api\Mastodon\Poll
370          */
371         public static function mstdnPoll()
372         {
373                 return self::$dice->create(Factory\Api\Mastodon\Poll::class);
374         }
375
376         /**
377          * @return Factory\Api\Mastodon\Relationship
378          */
379         public static function mstdnRelationship()
380         {
381                 return self::$dice->create(Factory\Api\Mastodon\Relationship::class);
382         }
383
384         /**
385          * @return Factory\Api\Mastodon\Status
386          */
387         public static function mstdnStatus()
388         {
389                 return self::$dice->create(Factory\Api\Mastodon\Status::class);
390         }
391
392         /**
393          * @return Factory\Api\Mastodon\StatusSource
394          */
395         public static function mstdnStatusSource()
396         {
397                 return self::$dice->create(Factory\Api\Mastodon\StatusSource::class);
398         }
399
400         /**
401          * @return Factory\Api\Mastodon\ScheduledStatus
402          */
403         public static function mstdnScheduledStatus()
404         {
405                 return self::$dice->create(Factory\Api\Mastodon\ScheduledStatus::class);
406         }
407
408         /**
409          * @return Factory\Api\Mastodon\Subscription
410          */
411         public static function mstdnSubscription()
412         {
413                 return self::$dice->create(Factory\Api\Mastodon\Subscription::class);
414         }
415
416         /**
417          * @return Factory\Api\Mastodon\ListEntity
418          */
419         public static function mstdnList()
420         {
421                 return self::$dice->create(Factory\Api\Mastodon\ListEntity::class);
422         }
423
424         /**
425          * @return Factory\Api\Mastodon\Notification
426          */
427         public static function mstdnNotification()
428         {
429                 return self::$dice->create(Factory\Api\Mastodon\Notification::class);
430         }
431
432         /**
433          * @return Factory\Api\Twitter\Status
434          */
435         public static function twitterStatus()
436         {
437                 return self::$dice->create(Factory\Api\Twitter\Status::class);
438         }
439
440         /**
441          * @return Factory\Api\Twitter\User
442          */
443         public static function twitterUser()
444         {
445                 return self::$dice->create(Factory\Api\Twitter\User::class);
446         }
447
448         public static function notificationIntro(): Navigation\Notifications\Factory\Introduction
449         {
450                 return self::$dice->create(Navigation\Notifications\Factory\Introduction::class);
451         }
452
453         //
454         // "Model" namespace instances
455         //
456         /**
457          * @return \Friendica\Core\Worker\Repository\Process
458          */
459         public static function modelProcess()
460         {
461                 return self::$dice->create(Core\Worker\Repository\Process::class);
462         }
463
464         /**
465          * @return Model\User\Cookie
466          */
467         public static function cookie()
468         {
469                 return self::$dice->create(Model\User\Cookie::class);
470         }
471
472         /**
473          * @return Core\Storage\Capability\ICanWriteToStorage
474          */
475         public static function storage()
476         {
477                 return self::$dice->create(Core\Storage\Capability\ICanWriteToStorage::class);
478         }
479
480         /**
481          * @return Model\Log\ParsedLogIterator
482          */
483         public static function parsedLogIterator()
484         {
485                 return self::$dice->create(Model\Log\ParsedLogIterator::class);
486         }
487
488         //
489         // "Module" namespace
490         //
491
492         public static function apiResponse(): Module\Api\ApiResponse
493         {
494                 return self::$dice->create(Module\Api\ApiResponse::class);
495         }
496
497         //
498         // "Network" namespace
499         //
500
501         /**
502          * @return Network\HTTPClient\Capability\ICanSendHttpRequests
503          */
504         public static function httpClient()
505         {
506                 return self::$dice->create(Network\HTTPClient\Capability\ICanSendHttpRequests::class);
507         }
508
509         //
510         // "Repository" namespace
511         //
512
513         /**
514          * @return Contact\FriendSuggest\Repository\FriendSuggest;
515          */
516         public static function fsuggest()
517         {
518                 return self::$dice->create(Contact\FriendSuggest\Repository\FriendSuggest::class);
519         }
520
521         /**
522          * @return Contact\FriendSuggest\Factory\FriendSuggest;
523          */
524         public static function fsuggestFactory()
525         {
526                 return self::$dice->create(Contact\FriendSuggest\Factory\FriendSuggest::class);
527         }
528
529         /**
530          * @return Contact\Introduction\Repository\Introduction
531          */
532         public static function intro()
533         {
534                 return self::$dice->create(Contact\Introduction\Repository\Introduction::class);
535         }
536
537         /**
538          * @return Contact\Introduction\Factory\Introduction
539          */
540         public static function introFactory()
541         {
542                 return self::$dice->create(Contact\Introduction\Factory\Introduction::class);
543         }
544
545         public static function report(): Moderation\Repository\Report
546         {
547                 return self::$dice->create(Moderation\Repository\Report::class);
548         }
549
550         public static function reportFactory(): Moderation\Factory\Report
551         {
552                 return self::$dice->create(Moderation\Factory\Report::class);
553         }
554
555         public static function localRelationship(): Contact\LocalRelationship\Repository\LocalRelationship
556         {
557                 return self::$dice->create(Contact\LocalRelationship\Repository\LocalRelationship::class);
558         }
559
560         public static function permissionSet(): Security\PermissionSet\Repository\PermissionSet
561         {
562                 return self::$dice->create(Security\PermissionSet\Repository\PermissionSet::class);
563         }
564
565         public static function permissionSetFactory(): Security\PermissionSet\Factory\PermissionSet
566         {
567                 return self::$dice->create(Security\PermissionSet\Factory\PermissionSet::class);
568         }
569
570         public static function profileField(): Profile\ProfileField\Repository\ProfileField
571         {
572                 return self::$dice->create(Profile\ProfileField\Repository\ProfileField::class);
573         }
574
575         public static function profileFieldFactory(): Profile\ProfileField\Factory\ProfileField
576         {
577                 return self::$dice->create(Profile\ProfileField\Factory\ProfileField::class);
578         }
579
580         public static function notification(): Navigation\Notifications\Repository\Notification
581         {
582                 return self::$dice->create(Navigation\Notifications\Repository\Notification::class);
583         }
584
585         public static function notificationFactory(): Navigation\Notifications\Factory\Notification
586         {
587                 return self::$dice->create(Navigation\Notifications\Factory\Notification::class);
588         }
589
590         public static function notify(): Navigation\Notifications\Repository\Notify
591         {
592                 return self::$dice->create(Navigation\Notifications\Repository\Notify::class);
593         }
594
595         public static function notifyFactory(): Navigation\Notifications\Factory\Notify
596         {
597                 return self::$dice->create(Navigation\Notifications\Factory\Notify::class);
598         }
599
600         public static function formattedNotificationFactory(): Navigation\Notifications\Factory\FormattedNotify
601         {
602                 return self::$dice->create(Navigation\Notifications\Factory\FormattedNotify::class);
603         }
604
605         public static function formattedNavNotificationFactory(): Navigation\Notifications\Factory\FormattedNavNotification
606         {
607                 return self::$dice->create(Navigation\Notifications\Factory\FormattedNavNotification::class);
608         }
609
610         //
611         // "Federation" namespace instances
612         //
613
614         public static function deliveryQueueItemFactory(): Federation\Factory\DeliveryQueueItem
615         {
616                 return self::$dice->create(Federation\Factory\DeliveryQueueItem::class);
617         }
618
619         public static function deliveryQueueItemRepo(): Federation\Repository\DeliveryQueueItem
620         {
621                 return self::$dice->create(Federation\Repository\DeliveryQueueItem::class);
622         }
623
624         //
625         // "Protocol" namespace instances
626         //
627
628         /**
629          * @return Protocol\Activity
630          */
631         public static function activity()
632         {
633                 return self::$dice->create(Protocol\Activity::class);
634         }
635
636         public static function dsprContact(): Protocol\Diaspora\Repository\DiasporaContact
637         {
638                 return self::$dice->create(Protocol\Diaspora\Repository\DiasporaContact::class);
639         }
640
641         //
642         // "Security" namespace instances
643         //
644
645         /**
646          * @return \Friendica\Security\Authentication
647          */
648         public static function auth()
649         {
650                 return self::$dice->create(Security\Authentication::class);
651         }
652
653         //
654         // "Util" namespace instances
655         //
656
657         /**
658          * @return Util\ACLFormatter
659          */
660         public static function aclFormatter()
661         {
662                 return self::$dice->create(Util\ACLFormatter::class);
663         }
664
665         /**
666          * @return string
667          */
668         public static function basePath()
669         {
670                 return self::$dice->create('$basepath');
671         }
672
673         /**
674          * @return Util\DateTimeFormat
675          */
676         public static function dtFormat()
677         {
678                 return self::$dice->create(Util\DateTimeFormat::class);
679         }
680
681         /**
682          * @return Util\FileSystem
683          */
684         public static function fs()
685         {
686                 return self::$dice->create(Util\FileSystem::class);
687         }
688
689         /**
690          * @return Util\Profiler
691          */
692         public static function profiler()
693         {
694                 return self::$dice->create(Util\Profiler::class);
695         }
696
697         /**
698          * @return Util\Emailer
699          */
700         public static function emailer()
701         {
702                 return self::$dice->create(Util\Emailer::class);
703         }
704 }