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