3 * @copyright Copyright (C) 2010-2021, the Friendica project
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
25 use Psr\Log\LoggerInterface;
28 * This class is capable of getting all dynamic created classes
30 * @see https://designpatternsphp.readthedocs.io/en/latest/Structural/Registry/README.html
37 public static function init(Dice $dice)
43 * Returns a clone of the current dice instance
44 * This usefull for overloading the current instance with mocked methods during tests
48 public static function getDice()
50 return clone self::$dice;
60 public static function app()
62 return self::$dice->create(App::class);
66 * @return Database\Database
68 public static function dba()
70 return self::$dice->create(Database\Database::class);
74 // "App" namespace instances
78 * @return App\Arguments
80 public static function args()
82 return self::$dice->create(App\Arguments::class);
88 public static function baseUrl()
90 return self::$dice->create(App\BaseURL::class);
96 public static function mode()
98 return self::$dice->create(App\Mode::class);
104 public static function page()
106 return self::$dice->create(App\Page::class);
112 public static function router()
114 return self::$dice->create(App\Router::class);
118 // "Content" namespace instances
122 * @return Content\Item
124 public static function contentItem()
126 return self::$dice->create(Content\Item::class);
130 * @return Content\Conversation
132 public static function conversation()
134 return self::$dice->create(Content\Conversation::class);
138 * @return Content\Text\BBCode\Video
140 public static function bbCodeVideo()
142 return self::$dice->create(Content\Text\BBCode\Video::class);
146 // "Core" namespace instances
150 * @return Core\Cache\Capability\ICanCache
152 public static function cache()
154 return self::$dice->create(Core\Cache\Capability\ICanCache::class);
158 * @return Core\Config\Capability\IManageConfigValues
160 public static function config()
162 return self::$dice->create(Core\Config\Capability\IManageConfigValues::class);
166 * @return Core\PConfig\Capability\IManagePersonalConfigValues
168 public static function pConfig()
170 return self::$dice->create(Core\PConfig\Capability\IManagePersonalConfigValues::class);
174 * @return Core\Lock\Capability\ICanLock
176 public static function lock()
178 return self::$dice->create(Core\Lock\Capability\ICanLock::class);
184 public static function l10n()
186 return self::$dice->create(Core\L10n::class);
190 * @return Core\Worker\Repository\Process
192 public static function process()
194 return self::$dice->create(Core\Worker\Repository\Process::class);
198 * @return Core\Session\Capability\IHandleSessions
200 public static function session()
202 return self::$dice->create(Core\Session\Capability\IHandleSessions::class);
206 * @return \Friendica\Core\Storage\Repository\StorageManager
208 public static function storageManager()
210 return self::$dice->create(Core\Storage\Repository\StorageManager::class);
214 * @return \Friendica\Core\System
216 public static function system()
218 return self::$dice->create(Core\System::class);
222 // "LoggerInterface" instances
226 * Flushes the Logger instance, so the factory is called again
227 * (creates a new id and retrieves the current PID)
229 public static function flushLogger()
231 $flushDice = self::$dice
232 ->addRule(LoggerInterface::class, self::$dice->getRule(LoggerInterface::class))
233 ->addRule('$devLogger', self::$dice->getRule('$devLogger'));
234 static::init($flushDice);
238 * @return LoggerInterface
240 public static function logger()
242 return self::$dice->create(LoggerInterface::class);
246 * @return LoggerInterface
248 public static function devLogger()
250 return self::$dice->create('$devLogger');
254 * @return LoggerInterface
256 public static function workerLogger()
258 return self::$dice->create(Core\Logger\Type\WorkerLogger::class);
262 // "Factory" namespace instances
266 * @return Factory\Api\Friendica\Activities
268 public static function friendicaActivities()
270 return self::$dice->create(Factory\Api\Friendica\Activities::class);
274 * @return Factory\Api\Mastodon\Account
276 public static function mstdnAccount()
278 return self::$dice->create(Factory\Api\Mastodon\Account::class);
282 * @return Factory\Api\Mastodon\Application
284 public static function mstdnApplication()
286 return self::$dice->create(Factory\Api\Mastodon\Application::class);
290 * @return Factory\Api\Mastodon\Attachment
292 public static function mstdnAttachment()
294 return self::$dice->create(Factory\Api\Mastodon\Attachment::class);
298 * @return Factory\Api\Mastodon\Card
300 public static function mstdnCard()
302 return self::$dice->create(Factory\Api\Mastodon\Card::class);
306 * @return Factory\Api\Mastodon\Conversation
308 public static function mstdnConversation()
310 return self::$dice->create(Factory\Api\Mastodon\Conversation::class);
314 * @return Factory\Api\Mastodon\Emoji
316 public static function mstdnEmoji()
318 return self::$dice->create(Factory\Api\Mastodon\Emoji::class);
322 * @return Factory\Api\Mastodon\Error
324 public static function mstdnError()
326 return self::$dice->create(Factory\Api\Mastodon\Error::class);
330 * @return Factory\Api\Mastodon\FollowRequest
332 public static function mstdnFollowRequest()
334 return self::$dice->create(Factory\Api\Mastodon\FollowRequest::class);
338 * @return Factory\Api\Mastodon\Relationship
340 public static function mstdnRelationship()
342 return self::$dice->create(Factory\Api\Mastodon\Relationship::class);
346 * @return Factory\Api\Mastodon\Status
348 public static function mstdnStatus()
350 return self::$dice->create(Factory\Api\Mastodon\Status::class);
354 * @return Factory\Api\Mastodon\ScheduledStatus
356 public static function mstdnScheduledStatus()
358 return self::$dice->create(Factory\Api\Mastodon\ScheduledStatus::class);
362 * @return Factory\Api\Mastodon\Subscription
364 public static function mstdnSubscription()
366 return self::$dice->create(Factory\Api\Mastodon\Subscription::class);
370 * @return Factory\Api\Mastodon\ListEntity
372 public static function mstdnList()
374 return self::$dice->create(Factory\Api\Mastodon\ListEntity::class);
378 * @return Factory\Api\Mastodon\Notification
380 public static function mstdnNotification()
382 return self::$dice->create(Factory\Api\Mastodon\Notification::class);
386 * @return Factory\Api\Twitter\Status
388 public static function twitterStatus()
390 return self::$dice->create(Factory\Api\Twitter\Status::class);
394 * @return Factory\Api\Twitter\User
396 public static function twitterUser()
398 return self::$dice->create(Factory\Api\Twitter\User::class);
402 * @return Factory\Api\Twitter\DirectMessage
404 public static function twitterDirectMessage()
406 return self::$dice->create(Factory\Api\Twitter\DirectMessage::class);
409 public static function notificationIntro(): Navigation\Notifications\Factory\Introduction
411 return self::$dice->create(Navigation\Notifications\Factory\Introduction::class);
415 // "Model" namespace instances
418 * @return \Friendica\Core\Worker\Repository\Process
420 public static function modelProcess()
422 return self::$dice->create(Core\Worker\Repository\Process::class);
426 * @return Model\User\Cookie
428 public static function cookie()
430 return self::$dice->create(Model\User\Cookie::class);
434 * @return Core\Storage\Capability\ICanWriteToStorage
436 public static function storage()
438 return self::$dice->create(Core\Storage\Capability\ICanWriteToStorage::class);
442 * @return Model\Log\ParsedLogIterator
444 public static function parsedLogIterator()
446 return self::$dice->create(Model\Log\ParsedLogIterator::class);
450 // "Module" namespace
453 public static function apiResponse(): Module\Api\ApiResponse
455 return self::$dice->create(Module\Api\ApiResponse::class);
459 // "Network" namespace
463 * @return Network\HTTPClient\Capability\ICanSendHttpRequests
465 public static function httpClient()
467 return self::$dice->create(Network\HTTPClient\Capability\ICanSendHttpRequests::class);
471 // "Repository" namespace
475 * @return Contact\FriendSuggest\Repository\FriendSuggest;
477 public static function fsuggest()
479 return self::$dice->create(Contact\FriendSuggest\Repository\FriendSuggest::class);
483 * @return Contact\FriendSuggest\Factory\FriendSuggest;
485 public static function fsuggestFactory()
487 return self::$dice->create(Contact\FriendSuggest\Factory\FriendSuggest::class);
491 * @return Contact\Introduction\Repository\Introduction
493 public static function intro()
495 return self::$dice->create(Contact\Introduction\Repository\Introduction::class);
499 * @return Contact\Introduction\Factory\Introduction
501 public static function introFactory()
503 return self::$dice->create(Contact\Introduction\Factory\Introduction::class);
506 public static function permissionSet(): Security\PermissionSet\Repository\PermissionSet
508 return self::$dice->create(Security\PermissionSet\Repository\PermissionSet::class);
511 public static function permissionSetFactory(): Security\PermissionSet\Factory\PermissionSet
513 return self::$dice->create(Security\PermissionSet\Factory\PermissionSet::class);
516 public static function profileField(): Profile\ProfileField\Repository\ProfileField
518 return self::$dice->create(Profile\ProfileField\Repository\ProfileField::class);
521 public static function profileFieldFactory(): Profile\ProfileField\Factory\ProfileField
523 return self::$dice->create(Profile\ProfileField\Factory\ProfileField::class);
526 public static function notification(): Navigation\Notifications\Repository\Notification
528 return self::$dice->create(Navigation\Notifications\Repository\Notification::class);
531 public static function notificationFactory(): Navigation\Notifications\Factory\Notification
533 return self::$dice->create(Navigation\Notifications\Factory\Notification::class);
536 public static function notify(): Navigation\Notifications\Repository\Notify
538 return self::$dice->create(Navigation\Notifications\Repository\Notify::class);
541 public static function notifyFactory(): Navigation\Notifications\Factory\Notify
543 return self::$dice->create(Navigation\Notifications\Factory\Notify::class);
546 public static function formattedNotificationFactory(): Navigation\Notifications\Factory\FormattedNotification
548 return self::$dice->create(Navigation\Notifications\Factory\FormattedNotification::class);
552 // "Protocol" namespace instances
556 * @return Protocol\Activity
558 public static function activity()
560 return self::$dice->create(Protocol\Activity::class);
564 // "Security" namespace instances
568 * @return \Friendica\Security\Authentication
570 public static function auth()
572 return self::$dice->create(Security\Authentication::class);
576 // "Util" namespace instances
580 * @return Util\ACLFormatter
582 public static function aclFormatter()
584 return self::$dice->create(Util\ACLFormatter::class);
590 public static function basePath()
592 return self::$dice->create('$basepath');
596 * @return Util\DateTimeFormat
598 public static function dtFormat()
600 return self::$dice->create(Util\DateTimeFormat::class);
604 * @return Util\FileSystem
606 public static function fs()
608 return self::$dice->create(Util\FileSystem::class);
612 * @return Util\Profiler
614 public static function profiler()
616 return self::$dice->create(Util\Profiler::class);
620 * @return Util\Emailer
622 public static function emailer()
624 return self::$dice->create(Util\Emailer::class);