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\Navigation\SystemMessages;
26 use Psr\Log\LoggerInterface;
29 * This class is capable of getting all dynamic created classes
31 * @see https://designpatternsphp.readthedocs.io/en/latest/Structural/Registry/README.html
38 public static function init(Dice $dice)
44 * Returns a clone of the current dice instance
45 * This usefull for overloading the current instance with mocked methods during tests
49 public static function getDice()
51 return clone self::$dice;
61 public static function app()
63 return self::$dice->create(App::class);
67 * @return Database\Database
69 public static function dba(): Database\Database
71 return self::$dice->create(Database\Database::class);
75 * @return \Friendica\Database\Definition\DbaDefinition
77 public static function dbaDefinition(): Database\Definition\DbaDefinition
79 return self::$dice->create(Database\Definition\DbaDefinition::class);
83 * @return \Friendica\Database\Definition\ViewDefinition
85 public static function viewDefinition(): Database\Definition\ViewDefinition
87 return self::$dice->create(Database\Definition\ViewDefinition::class);
91 // "App" namespace instances
95 * @return App\Arguments
97 public static function args()
99 return self::$dice->create(App\Arguments::class);
103 * @return App\BaseURL
105 public static function baseUrl()
107 return self::$dice->create(App\BaseURL::class);
113 public static function mode()
115 return self::$dice->create(App\Mode::class);
121 public static function page()
123 return self::$dice->create(App\Page::class);
129 public static function router()
131 return self::$dice->create(App\Router::class);
135 // "Content" namespace instances
139 * @return Content\Item
141 public static function contentItem()
143 return self::$dice->create(Content\Item::class);
147 * @return Content\Conversation
149 public static function conversation()
151 return self::$dice->create(Content\Conversation::class);
155 * @return Content\Text\BBCode\Video
157 public static function bbCodeVideo()
159 return self::$dice->create(Content\Text\BBCode\Video::class);
163 // "Core" namespace instances
167 * @return Core\Cache\Capability\ICanCache
169 public static function cache()
171 return self::$dice->create(Core\Cache\Capability\ICanCache::class);
175 * @return Core\Config\Capability\IManageConfigValues
177 public static function config()
179 return self::$dice->create(Core\Config\Capability\IManageConfigValues::class);
183 * @return Core\PConfig\Capability\IManagePersonalConfigValues
185 public static function pConfig()
187 return self::$dice->create(Core\PConfig\Capability\IManagePersonalConfigValues::class);
191 * @return Core\Lock\Capability\ICanLock
193 public static function lock()
195 return self::$dice->create(Core\Lock\Capability\ICanLock::class);
201 public static function l10n()
203 return self::$dice->create(Core\L10n::class);
207 * @return Core\Worker\Repository\Process
209 public static function process()
211 return self::$dice->create(Core\Worker\Repository\Process::class);
215 * @return Core\Session\Capability\IHandleSessions
217 public static function session()
219 return self::$dice->create(Core\Session\Capability\IHandleSessions::class);
223 * @return \Friendica\Core\Storage\Repository\StorageManager
225 public static function storageManager()
227 return self::$dice->create(Core\Storage\Repository\StorageManager::class);
231 * @return \Friendica\Core\System
233 public static function system()
235 return self::$dice->create(Core\System::class);
239 * @return \Friendica\Navigation\SystemMessages
241 public static function sysmsg()
243 return self::$dice->create(SystemMessages::class);
247 // "LoggerInterface" instances
251 * Flushes the Logger instance, so the factory is called again
252 * (creates a new id and retrieves the current PID)
254 public static function flushLogger()
256 $flushDice = self::$dice
257 ->addRule(LoggerInterface::class, self::$dice->getRule(LoggerInterface::class))
258 ->addRule('$devLogger', self::$dice->getRule('$devLogger'));
259 static::init($flushDice);
263 * @return LoggerInterface
265 public static function logger()
267 return self::$dice->create(LoggerInterface::class);
271 * @return LoggerInterface
273 public static function devLogger()
275 return self::$dice->create('$devLogger');
279 * @return LoggerInterface
281 public static function workerLogger()
283 return self::$dice->create(Core\Logger\Type\WorkerLogger::class);
287 // "Factory" namespace instances
291 * @return Factory\Api\Mastodon\Account
293 public static function mstdnAccount()
295 return self::$dice->create(Factory\Api\Mastodon\Account::class);
299 * @return Factory\Api\Mastodon\Application
301 public static function mstdnApplication()
303 return self::$dice->create(Factory\Api\Mastodon\Application::class);
307 * @return Factory\Api\Mastodon\Attachment
309 public static function mstdnAttachment()
311 return self::$dice->create(Factory\Api\Mastodon\Attachment::class);
315 * @return Factory\Api\Mastodon\Card
317 public static function mstdnCard()
319 return self::$dice->create(Factory\Api\Mastodon\Card::class);
323 * @return Factory\Api\Mastodon\Conversation
325 public static function mstdnConversation()
327 return self::$dice->create(Factory\Api\Mastodon\Conversation::class);
331 * @return Factory\Api\Mastodon\Emoji
333 public static function mstdnEmoji()
335 return self::$dice->create(Factory\Api\Mastodon\Emoji::class);
339 * @return Factory\Api\Mastodon\Error
341 public static function mstdnError()
343 return self::$dice->create(Factory\Api\Mastodon\Error::class);
347 * @return Factory\Api\Mastodon\FollowRequest
349 public static function mstdnFollowRequest()
351 return self::$dice->create(Factory\Api\Mastodon\FollowRequest::class);
355 * @return Factory\Api\Mastodon\Poll
357 public static function mstdnPoll()
359 return self::$dice->create(Factory\Api\Mastodon\Poll::class);
363 * @return Factory\Api\Mastodon\Relationship
365 public static function mstdnRelationship()
367 return self::$dice->create(Factory\Api\Mastodon\Relationship::class);
371 * @return Factory\Api\Mastodon\Status
373 public static function mstdnStatus()
375 return self::$dice->create(Factory\Api\Mastodon\Status::class);
379 * @return Factory\Api\Mastodon\ScheduledStatus
381 public static function mstdnScheduledStatus()
383 return self::$dice->create(Factory\Api\Mastodon\ScheduledStatus::class);
387 * @return Factory\Api\Mastodon\Subscription
389 public static function mstdnSubscription()
391 return self::$dice->create(Factory\Api\Mastodon\Subscription::class);
395 * @return Factory\Api\Mastodon\ListEntity
397 public static function mstdnList()
399 return self::$dice->create(Factory\Api\Mastodon\ListEntity::class);
403 * @return Factory\Api\Mastodon\Notification
405 public static function mstdnNotification()
407 return self::$dice->create(Factory\Api\Mastodon\Notification::class);
411 * @return Factory\Api\Twitter\Status
413 public static function twitterStatus()
415 return self::$dice->create(Factory\Api\Twitter\Status::class);
419 * @return Factory\Api\Twitter\User
421 public static function twitterUser()
423 return self::$dice->create(Factory\Api\Twitter\User::class);
426 public static function notificationIntro(): Navigation\Notifications\Factory\Introduction
428 return self::$dice->create(Navigation\Notifications\Factory\Introduction::class);
432 // "Model" namespace instances
435 * @return \Friendica\Core\Worker\Repository\Process
437 public static function modelProcess()
439 return self::$dice->create(Core\Worker\Repository\Process::class);
443 * @return Model\User\Cookie
445 public static function cookie()
447 return self::$dice->create(Model\User\Cookie::class);
451 * @return Core\Storage\Capability\ICanWriteToStorage
453 public static function storage()
455 return self::$dice->create(Core\Storage\Capability\ICanWriteToStorage::class);
459 * @return Model\Log\ParsedLogIterator
461 public static function parsedLogIterator()
463 return self::$dice->create(Model\Log\ParsedLogIterator::class);
467 // "Module" namespace
470 public static function apiResponse(): Module\Api\ApiResponse
472 return self::$dice->create(Module\Api\ApiResponse::class);
476 // "Network" namespace
480 * @return Network\HTTPClient\Capability\ICanSendHttpRequests
482 public static function httpClient()
484 return self::$dice->create(Network\HTTPClient\Capability\ICanSendHttpRequests::class);
488 // "Repository" namespace
492 * @return Contact\FriendSuggest\Repository\FriendSuggest;
494 public static function fsuggest()
496 return self::$dice->create(Contact\FriendSuggest\Repository\FriendSuggest::class);
500 * @return Contact\FriendSuggest\Factory\FriendSuggest;
502 public static function fsuggestFactory()
504 return self::$dice->create(Contact\FriendSuggest\Factory\FriendSuggest::class);
508 * @return Contact\Introduction\Repository\Introduction
510 public static function intro()
512 return self::$dice->create(Contact\Introduction\Repository\Introduction::class);
516 * @return Contact\Introduction\Factory\Introduction
518 public static function introFactory()
520 return self::$dice->create(Contact\Introduction\Factory\Introduction::class);
523 public static function localRelationship(): Contact\LocalRelationship\Repository\LocalRelationship
525 return self::$dice->create(Contact\LocalRelationship\Repository\LocalRelationship::class);
528 public static function permissionSet(): Security\PermissionSet\Repository\PermissionSet
530 return self::$dice->create(Security\PermissionSet\Repository\PermissionSet::class);
533 public static function permissionSetFactory(): Security\PermissionSet\Factory\PermissionSet
535 return self::$dice->create(Security\PermissionSet\Factory\PermissionSet::class);
538 public static function profileField(): Profile\ProfileField\Repository\ProfileField
540 return self::$dice->create(Profile\ProfileField\Repository\ProfileField::class);
543 public static function profileFieldFactory(): Profile\ProfileField\Factory\ProfileField
545 return self::$dice->create(Profile\ProfileField\Factory\ProfileField::class);
548 public static function notification(): Navigation\Notifications\Repository\Notification
550 return self::$dice->create(Navigation\Notifications\Repository\Notification::class);
553 public static function notificationFactory(): Navigation\Notifications\Factory\Notification
555 return self::$dice->create(Navigation\Notifications\Factory\Notification::class);
558 public static function notify(): Navigation\Notifications\Repository\Notify
560 return self::$dice->create(Navigation\Notifications\Repository\Notify::class);
563 public static function notifyFactory(): Navigation\Notifications\Factory\Notify
565 return self::$dice->create(Navigation\Notifications\Factory\Notify::class);
568 public static function formattedNotificationFactory(): Navigation\Notifications\Factory\FormattedNotify
570 return self::$dice->create(Navigation\Notifications\Factory\FormattedNotify::class);
573 public static function formattedNavNotificationFactory(): Navigation\Notifications\Factory\FormattedNavNotification
575 return self::$dice->create(Navigation\Notifications\Factory\FormattedNavNotification::class);
579 // "Protocol" namespace instances
583 * @return Protocol\Activity
585 public static function activity()
587 return self::$dice->create(Protocol\Activity::class);
591 // "Security" namespace instances
595 * @return \Friendica\Security\Authentication
597 public static function auth()
599 return self::$dice->create(Security\Authentication::class);
603 // "Util" namespace instances
607 * @return Util\ACLFormatter
609 public static function aclFormatter()
611 return self::$dice->create(Util\ACLFormatter::class);
617 public static function basePath()
619 return self::$dice->create('$basepath');
623 * @return Util\DateTimeFormat
625 public static function dtFormat()
627 return self::$dice->create(Util\DateTimeFormat::class);
631 * @return Util\FileSystem
633 public static function fs()
635 return self::$dice->create(Util\FileSystem::class);
639 * @return Util\Profiler
641 public static function profiler()
643 return self::$dice->create(Util\Profiler::class);
647 * @return Util\Emailer
649 public static function emailer()
651 return self::$dice->create(Util\Emailer::class);