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\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);
185 * @return Core\PConfig\Capability\IManagePersonalConfigValues
187 public static function pConfig()
189 return self::$dice->create(Core\PConfig\Capability\IManagePersonalConfigValues::class);
193 * @return Core\Lock\Capability\ICanLock
195 public static function lock()
197 return self::$dice->create(Core\Lock\Capability\ICanLock::class);
203 public static function l10n()
205 return self::$dice->create(Core\L10n::class);
209 * @return Core\Worker\Repository\Process
211 public static function process()
213 return self::$dice->create(Core\Worker\Repository\Process::class);
216 public static function session(): IHandleSessions
218 return self::$dice->create(Core\Session\Capability\IHandleSessions::class);
221 public static function userSession(): IHandleUserSessions
223 return self::$dice->create(Core\Session\Capability\IHandleUserSessions::class);
227 * @return \Friendica\Core\Storage\Repository\StorageManager
229 public static function storageManager()
231 return self::$dice->create(Core\Storage\Repository\StorageManager::class);
235 * @return \Friendica\Core\System
237 public static function system()
239 return self::$dice->create(Core\System::class);
243 * @return \Friendica\Navigation\SystemMessages
245 public static function sysmsg()
247 return self::$dice->create(SystemMessages::class);
251 // "LoggerInterface" instances
255 * Flushes the Logger instance, so the factory is called again
256 * (creates a new id and retrieves the current PID)
258 public static function flushLogger()
260 $flushDice = self::$dice
261 ->addRule(LoggerInterface::class, self::$dice->getRule(LoggerInterface::class))
262 ->addRule('$devLogger', self::$dice->getRule('$devLogger'));
263 static::init($flushDice);
267 * @return LoggerInterface
269 public static function logger()
271 return self::$dice->create(LoggerInterface::class);
275 * @return LoggerInterface
277 public static function devLogger()
279 return self::$dice->create('$devLogger');
283 * @return LoggerInterface
285 public static function workerLogger()
287 return self::$dice->create(Core\Logger\Type\WorkerLogger::class);
291 // "Factory" namespace instances
295 * @return Factory\Api\Mastodon\Account
297 public static function mstdnAccount()
299 return self::$dice->create(Factory\Api\Mastodon\Account::class);
303 * @return Factory\Api\Mastodon\Application
305 public static function mstdnApplication()
307 return self::$dice->create(Factory\Api\Mastodon\Application::class);
311 * @return Factory\Api\Mastodon\Attachment
313 public static function mstdnAttachment()
315 return self::$dice->create(Factory\Api\Mastodon\Attachment::class);
319 * @return Factory\Api\Mastodon\Card
321 public static function mstdnCard()
323 return self::$dice->create(Factory\Api\Mastodon\Card::class);
327 * @return Factory\Api\Mastodon\Conversation
329 public static function mstdnConversation()
331 return self::$dice->create(Factory\Api\Mastodon\Conversation::class);
335 * @return Factory\Api\Mastodon\Emoji
337 public static function mstdnEmoji()
339 return self::$dice->create(Factory\Api\Mastodon\Emoji::class);
343 * @return Factory\Api\Mastodon\Error
345 public static function mstdnError()
347 return self::$dice->create(Factory\Api\Mastodon\Error::class);
351 * @return Factory\Api\Mastodon\FollowRequest
353 public static function mstdnFollowRequest()
355 return self::$dice->create(Factory\Api\Mastodon\FollowRequest::class);
359 * @return Factory\Api\Mastodon\Poll
361 public static function mstdnPoll()
363 return self::$dice->create(Factory\Api\Mastodon\Poll::class);
367 * @return Factory\Api\Mastodon\Relationship
369 public static function mstdnRelationship()
371 return self::$dice->create(Factory\Api\Mastodon\Relationship::class);
375 * @return Factory\Api\Mastodon\Status
377 public static function mstdnStatus()
379 return self::$dice->create(Factory\Api\Mastodon\Status::class);
383 * @return Factory\Api\Mastodon\ScheduledStatus
385 public static function mstdnScheduledStatus()
387 return self::$dice->create(Factory\Api\Mastodon\ScheduledStatus::class);
391 * @return Factory\Api\Mastodon\Subscription
393 public static function mstdnSubscription()
395 return self::$dice->create(Factory\Api\Mastodon\Subscription::class);
399 * @return Factory\Api\Mastodon\ListEntity
401 public static function mstdnList()
403 return self::$dice->create(Factory\Api\Mastodon\ListEntity::class);
407 * @return Factory\Api\Mastodon\Notification
409 public static function mstdnNotification()
411 return self::$dice->create(Factory\Api\Mastodon\Notification::class);
415 * @return Factory\Api\Twitter\Status
417 public static function twitterStatus()
419 return self::$dice->create(Factory\Api\Twitter\Status::class);
423 * @return Factory\Api\Twitter\User
425 public static function twitterUser()
427 return self::$dice->create(Factory\Api\Twitter\User::class);
430 public static function notificationIntro(): Navigation\Notifications\Factory\Introduction
432 return self::$dice->create(Navigation\Notifications\Factory\Introduction::class);
436 // "Model" namespace instances
439 * @return \Friendica\Core\Worker\Repository\Process
441 public static function modelProcess()
443 return self::$dice->create(Core\Worker\Repository\Process::class);
447 * @return Model\User\Cookie
449 public static function cookie()
451 return self::$dice->create(Model\User\Cookie::class);
455 * @return Core\Storage\Capability\ICanWriteToStorage
457 public static function storage()
459 return self::$dice->create(Core\Storage\Capability\ICanWriteToStorage::class);
463 * @return Model\Log\ParsedLogIterator
465 public static function parsedLogIterator()
467 return self::$dice->create(Model\Log\ParsedLogIterator::class);
471 // "Module" namespace
474 public static function apiResponse(): Module\Api\ApiResponse
476 return self::$dice->create(Module\Api\ApiResponse::class);
480 // "Network" namespace
484 * @return Network\HTTPClient\Capability\ICanSendHttpRequests
486 public static function httpClient()
488 return self::$dice->create(Network\HTTPClient\Capability\ICanSendHttpRequests::class);
492 // "Repository" namespace
496 * @return Contact\FriendSuggest\Repository\FriendSuggest;
498 public static function fsuggest()
500 return self::$dice->create(Contact\FriendSuggest\Repository\FriendSuggest::class);
504 * @return Contact\FriendSuggest\Factory\FriendSuggest;
506 public static function fsuggestFactory()
508 return self::$dice->create(Contact\FriendSuggest\Factory\FriendSuggest::class);
512 * @return Contact\Introduction\Repository\Introduction
514 public static function intro()
516 return self::$dice->create(Contact\Introduction\Repository\Introduction::class);
520 * @return Contact\Introduction\Factory\Introduction
522 public static function introFactory()
524 return self::$dice->create(Contact\Introduction\Factory\Introduction::class);
527 public static function localRelationship(): Contact\LocalRelationship\Repository\LocalRelationship
529 return self::$dice->create(Contact\LocalRelationship\Repository\LocalRelationship::class);
532 public static function permissionSet(): Security\PermissionSet\Repository\PermissionSet
534 return self::$dice->create(Security\PermissionSet\Repository\PermissionSet::class);
537 public static function permissionSetFactory(): Security\PermissionSet\Factory\PermissionSet
539 return self::$dice->create(Security\PermissionSet\Factory\PermissionSet::class);
542 public static function profileField(): Profile\ProfileField\Repository\ProfileField
544 return self::$dice->create(Profile\ProfileField\Repository\ProfileField::class);
547 public static function profileFieldFactory(): Profile\ProfileField\Factory\ProfileField
549 return self::$dice->create(Profile\ProfileField\Factory\ProfileField::class);
552 public static function notification(): Navigation\Notifications\Repository\Notification
554 return self::$dice->create(Navigation\Notifications\Repository\Notification::class);
557 public static function notificationFactory(): Navigation\Notifications\Factory\Notification
559 return self::$dice->create(Navigation\Notifications\Factory\Notification::class);
562 public static function notify(): Navigation\Notifications\Repository\Notify
564 return self::$dice->create(Navigation\Notifications\Repository\Notify::class);
567 public static function notifyFactory(): Navigation\Notifications\Factory\Notify
569 return self::$dice->create(Navigation\Notifications\Factory\Notify::class);
572 public static function formattedNotificationFactory(): Navigation\Notifications\Factory\FormattedNotify
574 return self::$dice->create(Navigation\Notifications\Factory\FormattedNotify::class);
577 public static function formattedNavNotificationFactory(): Navigation\Notifications\Factory\FormattedNavNotification
579 return self::$dice->create(Navigation\Notifications\Factory\FormattedNavNotification::class);
583 // "Protocol" namespace instances
587 * @return Protocol\Activity
589 public static function activity()
591 return self::$dice->create(Protocol\Activity::class);
595 // "Security" namespace instances
599 * @return \Friendica\Security\Authentication
601 public static function auth()
603 return self::$dice->create(Security\Authentication::class);
607 // "Util" namespace instances
611 * @return Util\ACLFormatter
613 public static function aclFormatter()
615 return self::$dice->create(Util\ACLFormatter::class);
621 public static function basePath()
623 return self::$dice->create('$basepath');
627 * @return Util\DateTimeFormat
629 public static function dtFormat()
631 return self::$dice->create(Util\DateTimeFormat::class);
635 * @return Util\FileSystem
637 public static function fs()
639 return self::$dice->create(Util\FileSystem::class);
643 * @return Util\Profiler
645 public static function profiler()
647 return self::$dice->create(Util\Profiler::class);
651 * @return Util\Emailer
653 public static function emailer()
655 return self::$dice->create(Util\Emailer::class);