3 * @copyright Copyright (C) 2010-2023, 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 Friendica\Core\Session\Capability\IHandleSessions;
26 use Friendica\Core\Session\Capability\IHandleUserSessions;
27 use Friendica\Navigation\SystemMessages;
28 use Psr\Log\LoggerInterface;
31 * This class is capable of getting all dynamic created classes
33 * @see https://designpatternsphp.readthedocs.io/en/latest/Structural/Registry/README.html
40 public static function init(Dice $dice)
46 * Returns a clone of the current dice instance
47 * This usefull for overloading the current instance with mocked methods during tests
51 public static function getDice()
53 return clone self::$dice;
63 public static function app()
65 return self::$dice->create(App::class);
69 * @return Database\Database
71 public static function dba(): Database\Database
73 return self::$dice->create(Database\Database::class);
77 * @return \Friendica\Database\Definition\DbaDefinition
79 public static function dbaDefinition(): Database\Definition\DbaDefinition
81 return self::$dice->create(Database\Definition\DbaDefinition::class);
85 * @return \Friendica\Database\Definition\ViewDefinition
87 public static function viewDefinition(): Database\Definition\ViewDefinition
89 return self::$dice->create(Database\Definition\ViewDefinition::class);
93 // "App" namespace instances
97 * @return App\Arguments
99 public static function args()
101 return self::$dice->create(App\Arguments::class);
105 * @return App\BaseURL
107 public static function baseUrl()
109 return self::$dice->create(App\BaseURL::class);
115 public static function mode()
117 return self::$dice->create(App\Mode::class);
123 public static function page()
125 return self::$dice->create(App\Page::class);
131 public static function router()
133 return self::$dice->create(App\Router::class);
137 // "Content" namespace instances
141 * @return Content\Item
143 public static function contentItem()
145 return self::$dice->create(Content\Item::class);
149 * @return Content\Conversation
151 public static function conversation()
153 return self::$dice->create(Content\Conversation::class);
157 * @return Content\Text\BBCode\Video
159 public static function bbCodeVideo()
161 return self::$dice->create(Content\Text\BBCode\Video::class);
165 // "Core" namespace instances
169 * @return Core\Cache\Capability\ICanCache
171 public static function cache()
173 return self::$dice->create(Core\Cache\Capability\ICanCache::class);
177 * @return Core\Config\Capability\IManageConfigValues
179 public static function config()
181 return self::$dice->create(Core\Config\Capability\IManageConfigValues::class);
184 public static function keyValue(): Core\KeyValueStorage\Capabilities\IManageKeyValuePairs
186 return self::$dice->create(Core\KeyValueStorage\Capabilities\IManageKeyValuePairs::class);
190 * @return Core\PConfig\Capability\IManagePersonalConfigValues
192 public static function pConfig()
194 return self::$dice->create(Core\PConfig\Capability\IManagePersonalConfigValues::class);
198 * @return Core\Lock\Capability\ICanLock
200 public static function lock()
202 return self::$dice->create(Core\Lock\Capability\ICanLock::class);
208 public static function l10n()
210 return self::$dice->create(Core\L10n::class);
214 * @return Core\Worker\Repository\Process
216 public static function process()
218 return self::$dice->create(Core\Worker\Repository\Process::class);
221 public static function session(): IHandleSessions
223 return self::$dice->create(Core\Session\Capability\IHandleSessions::class);
226 public static function userSession(): IHandleUserSessions
228 return self::$dice->create(Core\Session\Capability\IHandleUserSessions::class);
232 * @return \Friendica\Core\Storage\Repository\StorageManager
234 public static function storageManager()
236 return self::$dice->create(Core\Storage\Repository\StorageManager::class);
240 * @return \Friendica\Core\System
242 public static function system()
244 return self::$dice->create(Core\System::class);
248 * @return \Friendica\Navigation\SystemMessages
250 public static function sysmsg()
252 return self::$dice->create(SystemMessages::class);
256 // "LoggerInterface" instances
260 * Flushes the Logger instance, so the factory is called again
261 * (creates a new id and retrieves the current PID)
263 public static function flushLogger()
265 $flushDice = self::$dice
266 ->addRule(LoggerInterface::class, self::$dice->getRule(LoggerInterface::class))
267 ->addRule('$devLogger', self::$dice->getRule('$devLogger'));
268 static::init($flushDice);
272 * @return LoggerInterface
274 public static function logger()
276 return self::$dice->create(LoggerInterface::class);
280 * @return LoggerInterface
282 public static function devLogger()
284 return self::$dice->create('$devLogger');
288 * @return LoggerInterface
290 public static function workerLogger()
292 return self::$dice->create(Core\Logger\Type\WorkerLogger::class);
296 // "Factory" namespace instances
300 * @return Factory\Api\Mastodon\Account
302 public static function mstdnAccount()
304 return self::$dice->create(Factory\Api\Mastodon\Account::class);
308 * @return Factory\Api\Mastodon\Application
310 public static function mstdnApplication()
312 return self::$dice->create(Factory\Api\Mastodon\Application::class);
316 * @return Factory\Api\Mastodon\Attachment
318 public static function mstdnAttachment()
320 return self::$dice->create(Factory\Api\Mastodon\Attachment::class);
324 * @return Factory\Api\Mastodon\Card
326 public static function mstdnCard()
328 return self::$dice->create(Factory\Api\Mastodon\Card::class);
332 * @return Factory\Api\Mastodon\Conversation
334 public static function mstdnConversation()
336 return self::$dice->create(Factory\Api\Mastodon\Conversation::class);
340 * @return Factory\Api\Mastodon\Emoji
342 public static function mstdnEmoji()
344 return self::$dice->create(Factory\Api\Mastodon\Emoji::class);
348 * @return Factory\Api\Mastodon\Error
350 public static function mstdnError()
352 return self::$dice->create(Factory\Api\Mastodon\Error::class);
356 * @return Factory\Api\Mastodon\FollowRequest
358 public static function mstdnFollowRequest()
360 return self::$dice->create(Factory\Api\Mastodon\FollowRequest::class);
364 * @return Factory\Api\Mastodon\Poll
366 public static function mstdnPoll()
368 return self::$dice->create(Factory\Api\Mastodon\Poll::class);
372 * @return Factory\Api\Mastodon\Relationship
374 public static function mstdnRelationship()
376 return self::$dice->create(Factory\Api\Mastodon\Relationship::class);
380 * @return Factory\Api\Mastodon\Status
382 public static function mstdnStatus()
384 return self::$dice->create(Factory\Api\Mastodon\Status::class);
388 * @return Factory\Api\Mastodon\StatusSource
390 public static function mstdnStatusSource()
392 return self::$dice->create(Factory\Api\Mastodon\StatusSource::class);
396 * @return Factory\Api\Mastodon\ScheduledStatus
398 public static function mstdnScheduledStatus()
400 return self::$dice->create(Factory\Api\Mastodon\ScheduledStatus::class);
404 * @return Factory\Api\Mastodon\Subscription
406 public static function mstdnSubscription()
408 return self::$dice->create(Factory\Api\Mastodon\Subscription::class);
412 * @return Factory\Api\Mastodon\ListEntity
414 public static function mstdnList()
416 return self::$dice->create(Factory\Api\Mastodon\ListEntity::class);
420 * @return Factory\Api\Mastodon\Notification
422 public static function mstdnNotification()
424 return self::$dice->create(Factory\Api\Mastodon\Notification::class);
428 * @return Factory\Api\Twitter\Status
430 public static function twitterStatus()
432 return self::$dice->create(Factory\Api\Twitter\Status::class);
436 * @return Factory\Api\Twitter\User
438 public static function twitterUser()
440 return self::$dice->create(Factory\Api\Twitter\User::class);
443 public static function notificationIntro(): Navigation\Notifications\Factory\Introduction
445 return self::$dice->create(Navigation\Notifications\Factory\Introduction::class);
449 // "Model" namespace instances
452 * @return \Friendica\Core\Worker\Repository\Process
454 public static function modelProcess()
456 return self::$dice->create(Core\Worker\Repository\Process::class);
460 * @return Model\User\Cookie
462 public static function cookie()
464 return self::$dice->create(Model\User\Cookie::class);
468 * @return Core\Storage\Capability\ICanWriteToStorage
470 public static function storage()
472 return self::$dice->create(Core\Storage\Capability\ICanWriteToStorage::class);
476 * @return Model\Log\ParsedLogIterator
478 public static function parsedLogIterator()
480 return self::$dice->create(Model\Log\ParsedLogIterator::class);
484 // "Module" namespace
487 public static function apiResponse(): Module\Api\ApiResponse
489 return self::$dice->create(Module\Api\ApiResponse::class);
493 // "Network" namespace
497 * @return Network\HTTPClient\Capability\ICanSendHttpRequests
499 public static function httpClient()
501 return self::$dice->create(Network\HTTPClient\Capability\ICanSendHttpRequests::class);
505 // "Repository" namespace
509 * @return Contact\FriendSuggest\Repository\FriendSuggest;
511 public static function fsuggest()
513 return self::$dice->create(Contact\FriendSuggest\Repository\FriendSuggest::class);
517 * @return Contact\FriendSuggest\Factory\FriendSuggest;
519 public static function fsuggestFactory()
521 return self::$dice->create(Contact\FriendSuggest\Factory\FriendSuggest::class);
525 * @return Contact\Introduction\Repository\Introduction
527 public static function intro()
529 return self::$dice->create(Contact\Introduction\Repository\Introduction::class);
533 * @return Contact\Introduction\Factory\Introduction
535 public static function introFactory()
537 return self::$dice->create(Contact\Introduction\Factory\Introduction::class);
540 public static function report(): Moderation\Repository\Report
542 return self::$dice->create(Moderation\Repository\Report::class);
545 public static function reportFactory(): Moderation\Factory\Report
547 return self::$dice->create(Moderation\Factory\Report::class);
550 public static function localRelationship(): Contact\LocalRelationship\Repository\LocalRelationship
552 return self::$dice->create(Contact\LocalRelationship\Repository\LocalRelationship::class);
555 public static function permissionSet(): Security\PermissionSet\Repository\PermissionSet
557 return self::$dice->create(Security\PermissionSet\Repository\PermissionSet::class);
560 public static function permissionSetFactory(): Security\PermissionSet\Factory\PermissionSet
562 return self::$dice->create(Security\PermissionSet\Factory\PermissionSet::class);
565 public static function profileField(): Profile\ProfileField\Repository\ProfileField
567 return self::$dice->create(Profile\ProfileField\Repository\ProfileField::class);
570 public static function profileFieldFactory(): Profile\ProfileField\Factory\ProfileField
572 return self::$dice->create(Profile\ProfileField\Factory\ProfileField::class);
575 public static function notification(): Navigation\Notifications\Repository\Notification
577 return self::$dice->create(Navigation\Notifications\Repository\Notification::class);
580 public static function notificationFactory(): Navigation\Notifications\Factory\Notification
582 return self::$dice->create(Navigation\Notifications\Factory\Notification::class);
585 public static function notify(): Navigation\Notifications\Repository\Notify
587 return self::$dice->create(Navigation\Notifications\Repository\Notify::class);
590 public static function notifyFactory(): Navigation\Notifications\Factory\Notify
592 return self::$dice->create(Navigation\Notifications\Factory\Notify::class);
595 public static function formattedNotificationFactory(): Navigation\Notifications\Factory\FormattedNotify
597 return self::$dice->create(Navigation\Notifications\Factory\FormattedNotify::class);
600 public static function formattedNavNotificationFactory(): Navigation\Notifications\Factory\FormattedNavNotification
602 return self::$dice->create(Navigation\Notifications\Factory\FormattedNavNotification::class);
606 // "Protocol" namespace instances
610 * @return Protocol\Activity
612 public static function activity()
614 return self::$dice->create(Protocol\Activity::class);
617 public static function dsprContact(): Protocol\Diaspora\Repository\DiasporaContact
619 return self::$dice->create(Protocol\Diaspora\Repository\DiasporaContact::class);
623 // "Security" namespace instances
627 * @return \Friendica\Security\Authentication
629 public static function auth()
631 return self::$dice->create(Security\Authentication::class);
635 // "Util" namespace instances
639 * @return Util\ACLFormatter
641 public static function aclFormatter()
643 return self::$dice->create(Util\ACLFormatter::class);
649 public static function basePath()
651 return self::$dice->create('$basepath');
655 * @return Util\DateTimeFormat
657 public static function dtFormat()
659 return self::$dice->create(Util\DateTimeFormat::class);
663 * @return Util\FileSystem
665 public static function fs()
667 return self::$dice->create(Util\FileSystem::class);
671 * @return Util\Profiler
673 public static function profiler()
675 return self::$dice->create(Util\Profiler::class);
679 * @return Util\Emailer
681 public static function emailer()
683 return self::$dice->create(Util\Emailer::class);