]> git.mxchange.org Git - friendica.git/blob - src/DI.php
Merge pull request #9086 from annando/insert-replace
[friendica.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\Twitter\User
284          */
285         public static function twitterUser()
286         {
287                 return self::$dice->create(Factory\Api\Twitter\User::class);
288         }
289
290         /**
291          * @return Factory\Notification\Notification
292          */
293         public static function notification()
294         {
295                 return self::$dice->create(Factory\Notification\Notification::class);
296         }
297
298         /**
299          * @return Factory\Notification\Introduction
300          */
301         public static function notificationIntro()
302         {
303                 return self::$dice->create(Factory\Notification\Introduction::class);
304         }
305
306         //
307         // "Model" namespace instances
308         //
309
310         /**
311          * @return Model\User\Cookie
312          */
313         public static function cookie()
314         {
315                 return self::$dice->create(Model\User\Cookie::class);
316         }
317
318         /**
319          * @return Model\Storage\IStorage
320          */
321         public static function storage()
322         {
323                 return self::$dice->create(Model\Storage\IStorage::class);
324         }
325
326         //
327         // "Network" namespace
328         //
329
330         /**
331          * @return Network\IHTTPRequest
332          */
333         public static function httpRequest()
334         {
335                 return self::$dice->create(Network\IHTTPRequest::class);
336         }
337
338         //
339         // "Repository" namespace
340         //
341
342         /**
343          * @return Repository\FSuggest;
344          */
345         public static function fsuggest()
346         {
347                 return self::$dice->create(Repository\FSuggest::class);
348         }
349
350         /**
351          * @return Repository\Introduction
352          */
353         public static function intro()
354         {
355                 return self::$dice->create(Repository\Introduction::class);
356         }
357
358         /**
359          * @return Repository\PermissionSet
360          */
361         public static function permissionSet()
362         {
363                 return self::$dice->create(Repository\PermissionSet::class);
364         }
365
366         /**
367          * @return Repository\ProfileField
368          */
369         public static function profileField()
370         {
371                 return self::$dice->create(Repository\ProfileField::class);
372         }
373
374         /**
375          * @return Repository\Notify
376          */
377         public static function notify()
378         {
379                 return self::$dice->create(Repository\Notify::class);
380         }
381
382         //
383         // "Protocol" namespace instances
384         //
385
386         /**
387          * @return Protocol\Activity
388          */
389         public static function activity()
390         {
391                 return self::$dice->create(Protocol\Activity::class);
392         }
393
394         //
395         // "Util" namespace instances
396         //
397
398         /**
399          * @return Util\ACLFormatter
400          */
401         public static function aclFormatter()
402         {
403                 return self::$dice->create(Util\ACLFormatter::class);
404         }
405
406         /**
407          * @return string
408          */
409         public static function basePath()
410         {
411                 return self::$dice->create('$basepath');
412         }
413
414         /**
415          * @return Util\DateTimeFormat
416          */
417         public static function dtFormat()
418         {
419                 return self::$dice->create(Util\DateTimeFormat::class);
420         }
421
422         /**
423          * @return Util\FileSystem
424          */
425         public static function fs()
426         {
427                 return self::$dice->create(Util\FileSystem::class);
428         }
429
430         /**
431          * @return Util\Profiler
432          */
433         public static function profiler()
434         {
435                 return self::$dice->create(Util\Profiler::class);
436         }
437
438         /**
439          * @return Util\Emailer
440          */
441         public static function emailer()
442         {
443                 return self::$dice->create(Util\Emailer::class);
444         }
445 }