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 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(): Database\Database
70 return self::$dice->create(Database\Database::class);
74 * @return \Friendica\Database\Definition\DbaDefinition
76 public static function dbaDefinition(): Database\Definition\DbaDefinition
78 return self::$dice->create(Database\Definition\DbaDefinition::class);
82 * @return \Friendica\Database\Definition\ViewDefinition
84 public static function viewDefinition(): Database\Definition\ViewDefinition
86 return self::$dice->create(Database\Definition\ViewDefinition::class);
90 // "App" namespace instances
94 * @return App\Arguments
96 public static function args()
98 return self::$dice->create(App\Arguments::class);
102 * @return App\BaseURL
104 public static function baseUrl()
106 return self::$dice->create(App\BaseURL::class);
112 public static function mode()
114 return self::$dice->create(App\Mode::class);
120 public static function page()
122 return self::$dice->create(App\Page::class);
128 public static function router()
130 return self::$dice->create(App\Router::class);
134 // "Content" namespace instances
138 * @return Content\Item
140 public static function contentItem()
142 return self::$dice->create(Content\Item::class);
146 * @return Content\Conversation
148 public static function conversation()
150 return self::$dice->create(Content\Conversation::class);
154 * @return Content\Text\BBCode\Video
156 public static function bbCodeVideo()
158 return self::$dice->create(Content\Text\BBCode\Video::class);
162 // "Core" namespace instances
166 * @return Core\Cache\Capability\ICanCache
168 public static function cache()
170 return self::$dice->create(Core\Cache\Capability\ICanCache::class);
174 * @return Core\Config\Capability\IManageConfigValues
176 public static function config()
178 return self::$dice->create(Core\Config\Capability\IManageConfigValues::class);
182 * @return Core\PConfig\Capability\IManagePersonalConfigValues
184 public static function pConfig()
186 return self::$dice->create(Core\PConfig\Capability\IManagePersonalConfigValues::class);
190 * @return Core\Lock\Capability\ICanLock
192 public static function lock()
194 return self::$dice->create(Core\Lock\Capability\ICanLock::class);
200 public static function l10n()
202 return self::$dice->create(Core\L10n::class);
206 * @return Core\Worker\Repository\Process
208 public static function process()
210 return self::$dice->create(Core\Worker\Repository\Process::class);
214 * @return Core\Session\Capability\IHandleSessions
216 public static function session()
218 return self::$dice->create(Core\Session\Capability\IHandleSessions::class);
222 * @return \Friendica\Core\Storage\Repository\StorageManager
224 public static function storageManager()
226 return self::$dice->create(Core\Storage\Repository\StorageManager::class);
230 * @return \Friendica\Core\System
232 public static function system()
234 return self::$dice->create(Core\System::class);
238 // "LoggerInterface" instances
242 * Flushes the Logger instance, so the factory is called again
243 * (creates a new id and retrieves the current PID)
245 public static function flushLogger()
247 $flushDice = self::$dice
248 ->addRule(LoggerInterface::class, self::$dice->getRule(LoggerInterface::class))
249 ->addRule('$devLogger', self::$dice->getRule('$devLogger'));
250 static::init($flushDice);
254 * @return LoggerInterface
256 public static function logger()
258 return self::$dice->create(LoggerInterface::class);
262 * @return LoggerInterface
264 public static function devLogger()
266 return self::$dice->create('$devLogger');
270 * @return LoggerInterface
272 public static function workerLogger()
274 return self::$dice->create(Core\Logger\Type\WorkerLogger::class);
278 // "Factory" namespace instances
282 * @return Factory\Api\Mastodon\Account
284 public static function mstdnAccount()
286 return self::$dice->create(Factory\Api\Mastodon\Account::class);
290 * @return Factory\Api\Mastodon\Application
292 public static function mstdnApplication()
294 return self::$dice->create(Factory\Api\Mastodon\Application::class);
298 * @return Factory\Api\Mastodon\Attachment
300 public static function mstdnAttachment()
302 return self::$dice->create(Factory\Api\Mastodon\Attachment::class);
306 * @return Factory\Api\Mastodon\Card
308 public static function mstdnCard()
310 return self::$dice->create(Factory\Api\Mastodon\Card::class);
314 * @return Factory\Api\Mastodon\Conversation
316 public static function mstdnConversation()
318 return self::$dice->create(Factory\Api\Mastodon\Conversation::class);
322 * @return Factory\Api\Mastodon\Emoji
324 public static function mstdnEmoji()
326 return self::$dice->create(Factory\Api\Mastodon\Emoji::class);
330 * @return Factory\Api\Mastodon\Error
332 public static function mstdnError()
334 return self::$dice->create(Factory\Api\Mastodon\Error::class);
338 * @return Factory\Api\Mastodon\FollowRequest
340 public static function mstdnFollowRequest()
342 return self::$dice->create(Factory\Api\Mastodon\FollowRequest::class);
346 * @return Factory\Api\Mastodon\Poll
348 public static function mstdnPoll()
350 return self::$dice->create(Factory\Api\Mastodon\Poll::class);
354 * @return Factory\Api\Mastodon\Relationship
356 public static function mstdnRelationship()
358 return self::$dice->create(Factory\Api\Mastodon\Relationship::class);
362 * @return Factory\Api\Mastodon\Status
364 public static function mstdnStatus()
366 return self::$dice->create(Factory\Api\Mastodon\Status::class);
370 * @return Factory\Api\Mastodon\ScheduledStatus
372 public static function mstdnScheduledStatus()
374 return self::$dice->create(Factory\Api\Mastodon\ScheduledStatus::class);
378 * @return Factory\Api\Mastodon\Subscription
380 public static function mstdnSubscription()
382 return self::$dice->create(Factory\Api\Mastodon\Subscription::class);
386 * @return Factory\Api\Mastodon\ListEntity
388 public static function mstdnList()
390 return self::$dice->create(Factory\Api\Mastodon\ListEntity::class);
394 * @return Factory\Api\Mastodon\Notification
396 public static function mstdnNotification()
398 return self::$dice->create(Factory\Api\Mastodon\Notification::class);
402 * @return Factory\Api\Twitter\Status
404 public static function twitterStatus()
406 return self::$dice->create(Factory\Api\Twitter\Status::class);
410 * @return Factory\Api\Twitter\User
412 public static function twitterUser()
414 return self::$dice->create(Factory\Api\Twitter\User::class);
417 public static function notificationIntro(): Navigation\Notifications\Factory\Introduction
419 return self::$dice->create(Navigation\Notifications\Factory\Introduction::class);
423 // "Model" namespace instances
426 * @return \Friendica\Core\Worker\Repository\Process
428 public static function modelProcess()
430 return self::$dice->create(Core\Worker\Repository\Process::class);
434 * @return Model\User\Cookie
436 public static function cookie()
438 return self::$dice->create(Model\User\Cookie::class);
442 * @return Core\Storage\Capability\ICanWriteToStorage
444 public static function storage()
446 return self::$dice->create(Core\Storage\Capability\ICanWriteToStorage::class);
450 * @return Model\Log\ParsedLogIterator
452 public static function parsedLogIterator()
454 return self::$dice->create(Model\Log\ParsedLogIterator::class);
458 // "Module" namespace
461 public static function apiResponse(): Module\Api\ApiResponse
463 return self::$dice->create(Module\Api\ApiResponse::class);
467 // "Network" namespace
471 * @return Network\HTTPClient\Capability\ICanSendHttpRequests
473 public static function httpClient()
475 return self::$dice->create(Network\HTTPClient\Capability\ICanSendHttpRequests::class);
479 // "Repository" namespace
483 * @return Contact\FriendSuggest\Repository\FriendSuggest;
485 public static function fsuggest()
487 return self::$dice->create(Contact\FriendSuggest\Repository\FriendSuggest::class);
491 * @return Contact\FriendSuggest\Factory\FriendSuggest;
493 public static function fsuggestFactory()
495 return self::$dice->create(Contact\FriendSuggest\Factory\FriendSuggest::class);
499 * @return Contact\Introduction\Repository\Introduction
501 public static function intro()
503 return self::$dice->create(Contact\Introduction\Repository\Introduction::class);
507 * @return Contact\Introduction\Factory\Introduction
509 public static function introFactory()
511 return self::$dice->create(Contact\Introduction\Factory\Introduction::class);
514 public static function localRelationship(): Contact\LocalRelationship\Repository\LocalRelationship
516 return self::$dice->create(Contact\LocalRelationship\Repository\LocalRelationship::class);
519 public static function permissionSet(): Security\PermissionSet\Repository\PermissionSet
521 return self::$dice->create(Security\PermissionSet\Repository\PermissionSet::class);
524 public static function permissionSetFactory(): Security\PermissionSet\Factory\PermissionSet
526 return self::$dice->create(Security\PermissionSet\Factory\PermissionSet::class);
529 public static function profileField(): Profile\ProfileField\Repository\ProfileField
531 return self::$dice->create(Profile\ProfileField\Repository\ProfileField::class);
534 public static function profileFieldFactory(): Profile\ProfileField\Factory\ProfileField
536 return self::$dice->create(Profile\ProfileField\Factory\ProfileField::class);
539 public static function notification(): Navigation\Notifications\Repository\Notification
541 return self::$dice->create(Navigation\Notifications\Repository\Notification::class);
544 public static function notificationFactory(): Navigation\Notifications\Factory\Notification
546 return self::$dice->create(Navigation\Notifications\Factory\Notification::class);
549 public static function notify(): Navigation\Notifications\Repository\Notify
551 return self::$dice->create(Navigation\Notifications\Repository\Notify::class);
554 public static function notifyFactory(): Navigation\Notifications\Factory\Notify
556 return self::$dice->create(Navigation\Notifications\Factory\Notify::class);
559 public static function formattedNotificationFactory(): Navigation\Notifications\Factory\FormattedNotify
561 return self::$dice->create(Navigation\Notifications\Factory\FormattedNotify::class);
564 public static function formattedNavNotificationFactory(): Navigation\Notifications\Factory\FormattedNavNotification
566 return self::$dice->create(Navigation\Notifications\Factory\FormattedNavNotification::class);
570 // "Protocol" namespace instances
574 * @return Protocol\Activity
576 public static function activity()
578 return self::$dice->create(Protocol\Activity::class);
582 // "Security" namespace instances
586 * @return \Friendica\Security\Authentication
588 public static function auth()
590 return self::$dice->create(Security\Authentication::class);
594 // "Util" namespace instances
598 * @return Util\ACLFormatter
600 public static function aclFormatter()
602 return self::$dice->create(Util\ACLFormatter::class);
608 public static function basePath()
610 return self::$dice->create('$basepath');
614 * @return Util\DateTimeFormat
616 public static function dtFormat()
618 return self::$dice->create(Util\DateTimeFormat::class);
622 * @return Util\FileSystem
624 public static function fs()
626 return self::$dice->create(Util\FileSystem::class);
630 * @return Util\Profiler
632 public static function profiler()
634 return self::$dice->create(Util\Profiler::class);
638 * @return Util\Emailer
640 public static function emailer()
642 return self::$dice->create(Util\Emailer::class);