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 configFileManager(): Core\Config\Util\ConfigFileManager
186 return self::$dice->create(Core\Config\Util\ConfigFileManager::class);
189 public static function keyValue(): Core\KeyValueStorage\Capabilities\IManageKeyValuePairs
191 return self::$dice->create(Core\KeyValueStorage\Capabilities\IManageKeyValuePairs::class);
195 * @return Core\PConfig\Capability\IManagePersonalConfigValues
197 public static function pConfig()
199 return self::$dice->create(Core\PConfig\Capability\IManagePersonalConfigValues::class);
203 * @return Core\Lock\Capability\ICanLock
205 public static function lock()
207 return self::$dice->create(Core\Lock\Capability\ICanLock::class);
213 public static function l10n()
215 return self::$dice->create(Core\L10n::class);
219 * @return Core\Worker\Repository\Process
221 public static function process()
223 return self::$dice->create(Core\Worker\Repository\Process::class);
226 public static function session(): IHandleSessions
228 return self::$dice->create(Core\Session\Capability\IHandleSessions::class);
231 public static function userSession(): IHandleUserSessions
233 return self::$dice->create(Core\Session\Capability\IHandleUserSessions::class);
237 * @return \Friendica\Core\Storage\Repository\StorageManager
239 public static function storageManager()
241 return self::$dice->create(Core\Storage\Repository\StorageManager::class);
245 * @return \Friendica\Core\System
247 public static function system()
249 return self::$dice->create(Core\System::class);
253 * @return \Friendica\Navigation\SystemMessages
255 public static function sysmsg()
257 return self::$dice->create(SystemMessages::class);
261 // "LoggerInterface" instances
265 * Flushes the Logger instance, so the factory is called again
266 * (creates a new id and retrieves the current PID)
268 public static function flushLogger()
270 $flushDice = self::$dice
271 ->addRule(LoggerInterface::class, self::$dice->getRule(LoggerInterface::class))
272 ->addRule('$devLogger', self::$dice->getRule('$devLogger'));
273 static::init($flushDice);
277 * @return LoggerInterface
279 public static function logger()
281 return self::$dice->create(LoggerInterface::class);
285 * @return LoggerInterface
287 public static function devLogger()
289 return self::$dice->create('$devLogger');
293 * @return LoggerInterface
295 public static function workerLogger()
297 return self::$dice->create(Core\Logger\Type\WorkerLogger::class);
301 // "Factory" namespace instances
305 * @return Factory\Api\Mastodon\Account
307 public static function mstdnAccount()
309 return self::$dice->create(Factory\Api\Mastodon\Account::class);
313 * @return Factory\Api\Mastodon\Application
315 public static function mstdnApplication()
317 return self::$dice->create(Factory\Api\Mastodon\Application::class);
321 * @return Factory\Api\Mastodon\Attachment
323 public static function mstdnAttachment()
325 return self::$dice->create(Factory\Api\Mastodon\Attachment::class);
329 * @return Factory\Api\Mastodon\Card
331 public static function mstdnCard()
333 return self::$dice->create(Factory\Api\Mastodon\Card::class);
337 * @return Factory\Api\Mastodon\Conversation
339 public static function mstdnConversation()
341 return self::$dice->create(Factory\Api\Mastodon\Conversation::class);
345 * @return Factory\Api\Mastodon\Emoji
347 public static function mstdnEmoji()
349 return self::$dice->create(Factory\Api\Mastodon\Emoji::class);
353 * @return Factory\Api\Mastodon\Error
355 public static function mstdnError()
357 return self::$dice->create(Factory\Api\Mastodon\Error::class);
361 * @return Factory\Api\Mastodon\FollowRequest
363 public static function mstdnFollowRequest()
365 return self::$dice->create(Factory\Api\Mastodon\FollowRequest::class);
369 * @return Factory\Api\Mastodon\Poll
371 public static function mstdnPoll()
373 return self::$dice->create(Factory\Api\Mastodon\Poll::class);
377 * @return Factory\Api\Mastodon\Relationship
379 public static function mstdnRelationship()
381 return self::$dice->create(Factory\Api\Mastodon\Relationship::class);
385 * @return Factory\Api\Mastodon\Status
387 public static function mstdnStatus()
389 return self::$dice->create(Factory\Api\Mastodon\Status::class);
393 * @return Factory\Api\Mastodon\StatusSource
395 public static function mstdnStatusSource()
397 return self::$dice->create(Factory\Api\Mastodon\StatusSource::class);
401 * @return Factory\Api\Mastodon\ScheduledStatus
403 public static function mstdnScheduledStatus()
405 return self::$dice->create(Factory\Api\Mastodon\ScheduledStatus::class);
409 * @return Factory\Api\Mastodon\Subscription
411 public static function mstdnSubscription()
413 return self::$dice->create(Factory\Api\Mastodon\Subscription::class);
417 * @return Factory\Api\Mastodon\ListEntity
419 public static function mstdnList()
421 return self::$dice->create(Factory\Api\Mastodon\ListEntity::class);
425 * @return Factory\Api\Mastodon\Notification
427 public static function mstdnNotification()
429 return self::$dice->create(Factory\Api\Mastodon\Notification::class);
433 * @return Factory\Api\Twitter\Status
435 public static function twitterStatus()
437 return self::$dice->create(Factory\Api\Twitter\Status::class);
441 * @return Factory\Api\Twitter\User
443 public static function twitterUser()
445 return self::$dice->create(Factory\Api\Twitter\User::class);
448 public static function notificationIntro(): Navigation\Notifications\Factory\Introduction
450 return self::$dice->create(Navigation\Notifications\Factory\Introduction::class);
454 // "Model" namespace instances
457 * @return \Friendica\Core\Worker\Repository\Process
459 public static function modelProcess()
461 return self::$dice->create(Core\Worker\Repository\Process::class);
465 * @return Model\User\Cookie
467 public static function cookie()
469 return self::$dice->create(Model\User\Cookie::class);
473 * @return Core\Storage\Capability\ICanWriteToStorage
475 public static function storage()
477 return self::$dice->create(Core\Storage\Capability\ICanWriteToStorage::class);
481 * @return Model\Log\ParsedLogIterator
483 public static function parsedLogIterator()
485 return self::$dice->create(Model\Log\ParsedLogIterator::class);
489 // "Module" namespace
492 public static function apiResponse(): Module\Api\ApiResponse
494 return self::$dice->create(Module\Api\ApiResponse::class);
498 // "Network" namespace
502 * @return Network\HTTPClient\Capability\ICanSendHttpRequests
504 public static function httpClient()
506 return self::$dice->create(Network\HTTPClient\Capability\ICanSendHttpRequests::class);
510 // "Repository" namespace
514 * @return Contact\FriendSuggest\Repository\FriendSuggest;
516 public static function fsuggest()
518 return self::$dice->create(Contact\FriendSuggest\Repository\FriendSuggest::class);
522 * @return Contact\FriendSuggest\Factory\FriendSuggest;
524 public static function fsuggestFactory()
526 return self::$dice->create(Contact\FriendSuggest\Factory\FriendSuggest::class);
530 * @return Contact\Introduction\Repository\Introduction
532 public static function intro()
534 return self::$dice->create(Contact\Introduction\Repository\Introduction::class);
538 * @return Contact\Introduction\Factory\Introduction
540 public static function introFactory()
542 return self::$dice->create(Contact\Introduction\Factory\Introduction::class);
545 public static function report(): Moderation\Repository\Report
547 return self::$dice->create(Moderation\Repository\Report::class);
550 public static function reportFactory(): Moderation\Factory\Report
552 return self::$dice->create(Moderation\Factory\Report::class);
555 public static function localRelationship(): Contact\LocalRelationship\Repository\LocalRelationship
557 return self::$dice->create(Contact\LocalRelationship\Repository\LocalRelationship::class);
560 public static function permissionSet(): Security\PermissionSet\Repository\PermissionSet
562 return self::$dice->create(Security\PermissionSet\Repository\PermissionSet::class);
565 public static function permissionSetFactory(): Security\PermissionSet\Factory\PermissionSet
567 return self::$dice->create(Security\PermissionSet\Factory\PermissionSet::class);
570 public static function profileField(): Profile\ProfileField\Repository\ProfileField
572 return self::$dice->create(Profile\ProfileField\Repository\ProfileField::class);
575 public static function profileFieldFactory(): Profile\ProfileField\Factory\ProfileField
577 return self::$dice->create(Profile\ProfileField\Factory\ProfileField::class);
580 public static function notification(): Navigation\Notifications\Repository\Notification
582 return self::$dice->create(Navigation\Notifications\Repository\Notification::class);
585 public static function notificationFactory(): Navigation\Notifications\Factory\Notification
587 return self::$dice->create(Navigation\Notifications\Factory\Notification::class);
590 public static function notify(): Navigation\Notifications\Repository\Notify
592 return self::$dice->create(Navigation\Notifications\Repository\Notify::class);
595 public static function notifyFactory(): Navigation\Notifications\Factory\Notify
597 return self::$dice->create(Navigation\Notifications\Factory\Notify::class);
600 public static function formattedNotificationFactory(): Navigation\Notifications\Factory\FormattedNotify
602 return self::$dice->create(Navigation\Notifications\Factory\FormattedNotify::class);
605 public static function formattedNavNotificationFactory(): Navigation\Notifications\Factory\FormattedNavNotification
607 return self::$dice->create(Navigation\Notifications\Factory\FormattedNavNotification::class);
611 // "Federation" namespace instances
614 public static function deliveryQueueItemFactory(): Federation\Factory\DeliveryQueueItem
616 return self::$dice->create(Federation\Factory\DeliveryQueueItem::class);
619 public static function deliveryQueueItemRepo(): Federation\Repository\DeliveryQueueItem
621 return self::$dice->create(Federation\Repository\DeliveryQueueItem::class);
625 // "Protocol" namespace instances
629 * @return Protocol\Activity
631 public static function activity()
633 return self::$dice->create(Protocol\Activity::class);
636 public static function dsprContact(): Protocol\Diaspora\Repository\DiasporaContact
638 return self::$dice->create(Protocol\Diaspora\Repository\DiasporaContact::class);
642 // "Security" namespace instances
646 * @return \Friendica\Security\Authentication
648 public static function auth()
650 return self::$dice->create(Security\Authentication::class);
654 // "Util" namespace instances
658 * @return Util\ACLFormatter
660 public static function aclFormatter()
662 return self::$dice->create(Util\ACLFormatter::class);
668 public static function basePath()
670 return self::$dice->create('$basepath');
674 * @return Util\DateTimeFormat
676 public static function dtFormat()
678 return self::$dice->create(Util\DateTimeFormat::class);
682 * @return Util\FileSystem
684 public static function fs()
686 return self::$dice->create(Util\FileSystem::class);
690 * @return Util\Profiler
692 public static function profiler()
694 return self::$dice->create(Util\Profiler::class);
698 * @return Util\Emailer
700 public static function emailer()
702 return self::$dice->create(Util\Emailer::class);