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