Rewrite Process Model/Core
[friendica.git/.git] / src / DI.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
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         // common instances
44         //
45
46         /**
47          * @return App
48          */
49         public static function app()
50         {
51                 return self::$dice->create(App::class);
52         }
53
54         /**
55          * @return Database\Database
56          */
57         public static function dba()
58         {
59                 return self::$dice->create(Database\Database::class);
60         }
61
62         //
63         // "App" namespace instances
64         //
65
66         /**
67          * @return App\Authentication
68          */
69         public static function auth()
70         {
71                 return self::$dice->create(App\Authentication::class);
72         }
73
74         /**
75          * @return App\Arguments
76          */
77         public static function args()
78         {
79                 return self::$dice->create(App\Arguments::class);
80         }
81
82         /**
83          * @return App\BaseURL
84          */
85         public static function baseUrl()
86         {
87                 return self::$dice->create(App\BaseURL::class);
88         }
89
90         /**
91          * @return App\Mode
92          */
93         public static function mode()
94         {
95                 return self::$dice->create(App\Mode::class);
96         }
97
98         /**
99          * @return App\Module
100          */
101         public static function module()
102         {
103                 return self::$dice->create(App\Module::class);
104         }
105
106         /**
107          * @return App\Page
108          */
109         public static function page()
110         {
111                 return self::$dice->create(App\Page::class);
112         }
113
114         /**
115          * @return App\Router
116          */
117         public static function router()
118         {
119                 return self::$dice->create(App\Router::class);
120         }
121
122         //
123         // "Content" namespace instances
124         //
125
126         /**
127          * @return Content\Item
128          */
129         public static function contentItem()
130         {
131                 return self::$dice->create(Content\Item::class);
132         }
133
134         /**
135          * @return Content\Text\BBCode\Video
136          */
137         public static function bbCodeVideo()
138         {
139                 return self::$dice->create(Content\Text\BBCode\Video::class);
140         }
141
142         //
143         // "Core" namespace instances
144         //
145
146         /**
147          * @return Core\Cache\ICache
148          */
149         public static function cache()
150         {
151                 return self::$dice->create(Core\Cache\ICache::class);
152         }
153
154         /**
155          * @return Core\Config\IConfig
156          */
157         public static function config()
158         {
159                 return self::$dice->create(Core\Config\IConfig::class);
160         }
161
162         /**
163          * @return Core\PConfig\IPConfig
164          */
165         public static function pConfig()
166         {
167                 return self::$dice->create(Core\PConfig\IPConfig::class);
168         }
169
170         /**
171          * @return Core\Lock\ILock
172          */
173         public static function lock()
174         {
175                 return self::$dice->create(Core\Lock\ILock::class);
176         }
177
178         /**
179          * @return Core\L10n
180          */
181         public static function l10n()
182         {
183                 return self::$dice->create(Core\L10n::class);
184         }
185
186         /**
187          * @return Core\Process
188          */
189         public static function process()
190         {
191                 return self::$dice->create(Core\Process::class);
192         }
193
194         /**
195          * @return Core\Session\ISession
196          */
197         public static function session()
198         {
199                 return self::$dice->create(Core\Session\ISession::class);
200         }
201
202         /**
203          * @return Core\StorageManager
204          */
205         public static function storageManager()
206         {
207                 return self::$dice->create(Core\StorageManager::class);
208         }
209
210         //
211         // "LoggerInterface" instances
212         //
213
214         /**
215          * @return LoggerInterface
216          */
217         public static function logger()
218         {
219                 return self::$dice->create(LoggerInterface::class);
220         }
221
222         /**
223          * @return LoggerInterface
224          */
225         public static function devLogger()
226         {
227                 return self::$dice->create('$devLogger');
228         }
229
230         /**
231          * @return LoggerInterface
232          */
233         public static function workerLogger()
234         {
235                 return self::$dice->create(Util\Logger\WorkerLogger::class);
236         }
237
238         //
239         // "Factory" namespace instances
240         //
241
242         /**
243          * @return Factory\Api\Mastodon\Account
244          */
245         public static function mstdnAccount()
246         {
247                 return self::$dice->create(Factory\Api\Mastodon\Account::class);
248         }
249
250         /**
251          * @return Factory\Api\Mastodon\Emoji
252          */
253         public static function mstdnEmoji()
254         {
255                 return self::$dice->create(Factory\Api\Mastodon\Emoji::class);
256         }
257
258         /**
259          * @return Factory\Api\Mastodon\Field
260          */
261         public static function mstdnField()
262         {
263                 return self::$dice->create(Factory\Api\Mastodon\Field::class);
264         }
265
266         /**
267          * @return Factory\Api\Mastodon\FollowRequest
268          */
269         public static function mstdnFollowRequest()
270         {
271                 return self::$dice->create(Factory\Api\Mastodon\FollowRequest::class);
272         }
273
274         /**
275          * @return Factory\Api\Mastodon\Relationship
276          */
277         public static function mstdnRelationship()
278         {
279                 return self::$dice->create(Factory\Api\Mastodon\Relationship::class);
280         }
281
282         /**
283          * @return Factory\Api\Mastodon\Status
284          */
285         public static function mstdnStatus()
286         {
287                 return self::$dice->create(Factory\Api\Mastodon\Status::class);
288         }
289
290         /**
291          * @return Factory\Api\Twitter\User
292          */
293         public static function twitterUser()
294         {
295                 return self::$dice->create(Factory\Api\Twitter\User::class);
296         }
297
298         /**
299          * @return Factory\Notification\Notification
300          */
301         public static function notification()
302         {
303                 return self::$dice->create(Factory\Notification\Notification::class);
304         }
305
306         /**
307          * @return Factory\Notification\Introduction
308          */
309         public static function notificationIntro()
310         {
311                 return self::$dice->create(Factory\Notification\Introduction::class);
312         }
313
314         //
315         // "Model" namespace instances
316         //
317         /**
318          * @return Model\Process
319          */
320         public static function modelProcess()
321         {
322                 return self::$dice->create(Model\Process::class);
323         }
324
325         /**
326          * @return Model\User\Cookie
327          */
328         public static function cookie()
329         {
330                 return self::$dice->create(Model\User\Cookie::class);
331         }
332
333         /**
334          * @return Model\Storage\IStorage
335          */
336         public static function storage()
337         {
338                 return self::$dice->create(Model\Storage\IStorage::class);
339         }
340
341         //
342         // "Network" namespace
343         //
344
345         /**
346          * @return Network\IHTTPRequest
347          */
348         public static function httpRequest()
349         {
350                 return self::$dice->create(Network\IHTTPRequest::class);
351         }
352
353         //
354         // "Repository" namespace
355         //
356
357         /**
358          * @return Repository\FSuggest;
359          */
360         public static function fsuggest()
361         {
362                 return self::$dice->create(Repository\FSuggest::class);
363         }
364
365         /**
366          * @return Repository\Introduction
367          */
368         public static function intro()
369         {
370                 return self::$dice->create(Repository\Introduction::class);
371         }
372
373         /**
374          * @return Repository\PermissionSet
375          */
376         public static function permissionSet()
377         {
378                 return self::$dice->create(Repository\PermissionSet::class);
379         }
380
381         /**
382          * @return Repository\ProfileField
383          */
384         public static function profileField()
385         {
386                 return self::$dice->create(Repository\ProfileField::class);
387         }
388
389         /**
390          * @return Repository\Notify
391          */
392         public static function notify()
393         {
394                 return self::$dice->create(Repository\Notify::class);
395         }
396
397         //
398         // "Protocol" namespace instances
399         //
400
401         /**
402          * @return Protocol\Activity
403          */
404         public static function activity()
405         {
406                 return self::$dice->create(Protocol\Activity::class);
407         }
408
409         //
410         // "Util" namespace instances
411         //
412
413         /**
414          * @return Util\ACLFormatter
415          */
416         public static function aclFormatter()
417         {
418                 return self::$dice->create(Util\ACLFormatter::class);
419         }
420
421         /**
422          * @return string
423          */
424         public static function basePath()
425         {
426                 return self::$dice->create('$basepath');
427         }
428
429         /**
430          * @return Util\DateTimeFormat
431          */
432         public static function dtFormat()
433         {
434                 return self::$dice->create(Util\DateTimeFormat::class);
435         }
436
437         /**
438          * @return Util\FileSystem
439          */
440         public static function fs()
441         {
442                 return self::$dice->create(Util\FileSystem::class);
443         }
444
445         /**
446          * @return Util\Profiler
447          */
448         public static function profiler()
449         {
450                 return self::$dice->create(Util\Profiler::class);
451         }
452
453         /**
454          * @return Util\Emailer
455          */
456         public static function emailer()
457         {
458                 return self::$dice->create(Util\Emailer::class);
459         }
460 }