3 * @copyright Copyright (C) 2010-2022, 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\IHandleUserSessions;
26 use Friendica\Navigation\SystemMessages;
27 use Psr\Log\LoggerInterface;
30 * This class is capable of getting all dynamic created classes
32 * @see https://designpatternsphp.readthedocs.io/en/latest/Structural/Registry/README.html
39 public static function init(Dice $dice)
45 * Returns a clone of the current dice instance
46 * This usefull for overloading the current instance with mocked methods during tests
50 public static function getDice()
52 return clone self::$dice;
62 public static function app()
64 return self::$dice->create(App::class);
68 * @return Database\Database
70 public static function dba(): Database\Database
72 return self::$dice->create(Database\Database::class);
76 * @return \Friendica\Database\Definition\DbaDefinition
78 public static function dbaDefinition(): Database\Definition\DbaDefinition
80 return self::$dice->create(Database\Definition\DbaDefinition::class);
84 * @return \Friendica\Database\Definition\ViewDefinition
86 public static function viewDefinition(): Database\Definition\ViewDefinition
88 return self::$dice->create(Database\Definition\ViewDefinition::class);
92 // "App" namespace instances
96 * @return App\Arguments
98 public static function args()
100 return self::$dice->create(App\Arguments::class);
104 * @return App\BaseURL
106 public static function baseUrl()
108 return self::$dice->create(App\BaseURL::class);
114 public static function mode()
116 return self::$dice->create(App\Mode::class);
122 public static function page()
124 return self::$dice->create(App\Page::class);
130 public static function router()
132 return self::$dice->create(App\Router::class);
136 // "Content" namespace instances
140 * @return Content\Item
142 public static function contentItem()
144 return self::$dice->create(Content\Item::class);
148 * @return Content\Conversation
150 public static function conversation()
152 return self::$dice->create(Content\Conversation::class);
156 * @return Content\Text\BBCode\Video
158 public static function bbCodeVideo()
160 return self::$dice->create(Content\Text\BBCode\Video::class);
164 // "Core" namespace instances
168 * @return Core\Cache\Capability\ICanCache
170 public static function cache()
172 return self::$dice->create(Core\Cache\Capability\ICanCache::class);
176 * @return Core\Config\Capability\IManageConfigValues
178 public static function config()
180 return self::$dice->create(Core\Config\Capability\IManageConfigValues::class);
184 * @return Core\PConfig\Capability\IManagePersonalConfigValues
186 public static function pConfig()
188 return self::$dice->create(Core\PConfig\Capability\IManagePersonalConfigValues::class);
192 * @return Core\Lock\Capability\ICanLock
194 public static function lock()
196 return self::$dice->create(Core\Lock\Capability\ICanLock::class);
202 public static function l10n()
204 return self::$dice->create(Core\L10n::class);
208 * @return Core\Worker\Repository\Process
210 public static function process()
212 return self::$dice->create(Core\Worker\Repository\Process::class);
216 * @return Core\Session\Capability\IHandleSessions
218 public static function session()
220 return self::$dice->create(Core\Session\Capability\IHandleSessions::class);
223 public static function userSession(): IHandleUserSessions
225 return self::$dice->create(Core\Session\Capability\IHandleUserSessions::class);
229 * @return \Friendica\Core\Storage\Repository\StorageManager
231 public static function storageManager()
233 return self::$dice->create(Core\Storage\Repository\StorageManager::class);
237 * @return \Friendica\Core\System
239 public static function system()
241 return self::$dice->create(Core\System::class);
245 * @return \Friendica\Navigation\SystemMessages
247 public static function sysmsg()
249 return self::$dice->create(SystemMessages::class);
253 // "LoggerInterface" instances
257 * Flushes the Logger instance, so the factory is called again
258 * (creates a new id and retrieves the current PID)
260 public static function flushLogger()
262 $flushDice = self::$dice
263 ->addRule(LoggerInterface::class, self::$dice->getRule(LoggerInterface::class))
264 ->addRule('$devLogger', self::$dice->getRule('$devLogger'));
265 static::init($flushDice);
269 * @return LoggerInterface
271 public static function logger()
273 return self::$dice->create(LoggerInterface::class);
277 * @return LoggerInterface
279 public static function devLogger()
281 return self::$dice->create('$devLogger');
285 * @return LoggerInterface
287 public static function workerLogger()
289 return self::$dice->create(Core\Logger\Type\WorkerLogger::class);
293 // "Factory" namespace instances
297 * @return Factory\Api\Mastodon\Account
299 public static function mstdnAccount()
301 return self::$dice->create(Factory\Api\Mastodon\Account::class);
305 * @return Factory\Api\Mastodon\Application
307 public static function mstdnApplication()
309 return self::$dice->create(Factory\Api\Mastodon\Application::class);
313 * @return Factory\Api\Mastodon\Attachment
315 public static function mstdnAttachment()
317 return self::$dice->create(Factory\Api\Mastodon\Attachment::class);
321 * @return Factory\Api\Mastodon\Card
323 public static function mstdnCard()
325 return self::$dice->create(Factory\Api\Mastodon\Card::class);
329 * @return Factory\Api\Mastodon\Conversation
331 public static function mstdnConversation()
333 return self::$dice->create(Factory\Api\Mastodon\Conversation::class);
337 * @return Factory\Api\Mastodon\Emoji
339 public static function mstdnEmoji()
341 return self::$dice->create(Factory\Api\Mastodon\Emoji::class);
345 * @return Factory\Api\Mastodon\Error
347 public static function mstdnError()
349 return self::$dice->create(Factory\Api\Mastodon\Error::class);
353 * @return Factory\Api\Mastodon\FollowRequest
355 public static function mstdnFollowRequest()
357 return self::$dice->create(Factory\Api\Mastodon\FollowRequest::class);
361 * @return Factory\Api\Mastodon\Poll
363 public static function mstdnPoll()
365 return self::$dice->create(Factory\Api\Mastodon\Poll::class);
369 * @return Factory\Api\Mastodon\Relationship
371 public static function mstdnRelationship()
373 return self::$dice->create(Factory\Api\Mastodon\Relationship::class);
377 * @return Factory\Api\Mastodon\Status
379 public static function mstdnStatus()
381 return self::$dice->create(Factory\Api\Mastodon\Status::class);
385 * @return Factory\Api\Mastodon\ScheduledStatus
387 public static function mstdnScheduledStatus()
389 return self::$dice->create(Factory\Api\Mastodon\ScheduledStatus::class);
393 * @return Factory\Api\Mastodon\Subscription
395 public static function mstdnSubscription()
397 return self::$dice->create(Factory\Api\Mastodon\Subscription::class);
401 * @return Factory\Api\Mastodon\ListEntity
403 public static function mstdnList()
405 return self::$dice->create(Factory\Api\Mastodon\ListEntity::class);
409 * @return Factory\Api\Mastodon\Notification
411 public static function mstdnNotification()
413 return self::$dice->create(Factory\Api\Mastodon\Notification::class);
417 * @return Factory\Api\Twitter\Status
419 public static function twitterStatus()
421 return self::$dice->create(Factory\Api\Twitter\Status::class);
425 * @return Factory\Api\Twitter\User
427 public static function twitterUser()
429 return self::$dice->create(Factory\Api\Twitter\User::class);
432 public static function notificationIntro(): Navigation\Notifications\Factory\Introduction
434 return self::$dice->create(Navigation\Notifications\Factory\Introduction::class);
438 // "Model" namespace instances
441 * @return \Friendica\Core\Worker\Repository\Process
443 public static function modelProcess()
445 return self::$dice->create(Core\Worker\Repository\Process::class);
449 * @return Model\User\Cookie
451 public static function cookie()
453 return self::$dice->create(Model\User\Cookie::class);
457 * @return Core\Storage\Capability\ICanWriteToStorage
459 public static function storage()
461 return self::$dice->create(Core\Storage\Capability\ICanWriteToStorage::class);
465 * @return Model\Log\ParsedLogIterator
467 public static function parsedLogIterator()
469 return self::$dice->create(Model\Log\ParsedLogIterator::class);
473 // "Module" namespace
476 public static function apiResponse(): Module\Api\ApiResponse
478 return self::$dice->create(Module\Api\ApiResponse::class);
482 // "Network" namespace
486 * @return Network\HTTPClient\Capability\ICanSendHttpRequests
488 public static function httpClient()
490 return self::$dice->create(Network\HTTPClient\Capability\ICanSendHttpRequests::class);
494 // "Repository" namespace
498 * @return Contact\FriendSuggest\Repository\FriendSuggest;
500 public static function fsuggest()
502 return self::$dice->create(Contact\FriendSuggest\Repository\FriendSuggest::class);
506 * @return Contact\FriendSuggest\Factory\FriendSuggest;
508 public static function fsuggestFactory()
510 return self::$dice->create(Contact\FriendSuggest\Factory\FriendSuggest::class);
514 * @return Contact\Introduction\Repository\Introduction
516 public static function intro()
518 return self::$dice->create(Contact\Introduction\Repository\Introduction::class);
522 * @return Contact\Introduction\Factory\Introduction
524 public static function introFactory()
526 return self::$dice->create(Contact\Introduction\Factory\Introduction::class);
529 public static function localRelationship(): Contact\LocalRelationship\Repository\LocalRelationship
531 return self::$dice->create(Contact\LocalRelationship\Repository\LocalRelationship::class);
534 public static function permissionSet(): Security\PermissionSet\Repository\PermissionSet
536 return self::$dice->create(Security\PermissionSet\Repository\PermissionSet::class);
539 public static function permissionSetFactory(): Security\PermissionSet\Factory\PermissionSet
541 return self::$dice->create(Security\PermissionSet\Factory\PermissionSet::class);
544 public static function profileField(): Profile\ProfileField\Repository\ProfileField
546 return self::$dice->create(Profile\ProfileField\Repository\ProfileField::class);
549 public static function profileFieldFactory(): Profile\ProfileField\Factory\ProfileField
551 return self::$dice->create(Profile\ProfileField\Factory\ProfileField::class);
554 public static function notification(): Navigation\Notifications\Repository\Notification
556 return self::$dice->create(Navigation\Notifications\Repository\Notification::class);
559 public static function notificationFactory(): Navigation\Notifications\Factory\Notification
561 return self::$dice->create(Navigation\Notifications\Factory\Notification::class);
564 public static function notify(): Navigation\Notifications\Repository\Notify
566 return self::$dice->create(Navigation\Notifications\Repository\Notify::class);
569 public static function notifyFactory(): Navigation\Notifications\Factory\Notify
571 return self::$dice->create(Navigation\Notifications\Factory\Notify::class);
574 public static function formattedNotificationFactory(): Navigation\Notifications\Factory\FormattedNotify
576 return self::$dice->create(Navigation\Notifications\Factory\FormattedNotify::class);
579 public static function formattedNavNotificationFactory(): Navigation\Notifications\Factory\FormattedNavNotification
581 return self::$dice->create(Navigation\Notifications\Factory\FormattedNavNotification::class);
585 // "Protocol" namespace instances
589 * @return Protocol\Activity
591 public static function activity()
593 return self::$dice->create(Protocol\Activity::class);
597 // "Security" namespace instances
601 * @return \Friendica\Security\Authentication
603 public static function auth()
605 return self::$dice->create(Security\Authentication::class);
609 // "Util" namespace instances
613 * @return Util\ACLFormatter
615 public static function aclFormatter()
617 return self::$dice->create(Util\ACLFormatter::class);
623 public static function basePath()
625 return self::$dice->create('$basepath');
629 * @return Util\DateTimeFormat
631 public static function dtFormat()
633 return self::$dice->create(Util\DateTimeFormat::class);
637 * @return Util\FileSystem
639 public static function fs()
641 return self::$dice->create(Util\FileSystem::class);
645 * @return Util\Profiler
647 public static function profiler()
649 return self::$dice->create(Util\Profiler::class);
653 * @return Util\Emailer
655 public static function emailer()
657 return self::$dice->create(Util\Emailer::class);