Browse Source

Replace BaseObject class with DI::* calls

pull/8019/head
nupplaPhil 2 years ago
parent
commit
388b963714
No known key found for this signature in database GPG Key ID: D8365C3D36B77D90
  1. 3
      bin/auth_ejabberd.php
  2. 2
      bin/daemon.php
  3. 3
      bin/worker.php
  4. 1
      boot.php
  5. 16
      include/api.php
  6. 19
      include/conversation.php
  7. 5
      include/items.php
  8. 2
      index.php
  9. 7
      mod/dfrn_poll.php
  10. 5
      mod/events.php
  11. 10
      mod/item.php
  12. 6
      mod/lockview.php
  13. 12
      mod/network.php
  14. 4
      mod/notifications.php
  15. 12
      mod/photos.php
  16. 7
      mod/settings.php
  17. 4
      src/App/Module.php
  18. 2
      src/BaseModule.php
  19. 58
      src/BaseObject.php
  20. 3
      src/Content/Text/BBCode.php
  21. 3
      src/Content/Text/Markdown.php
  22. 3
      src/Core/ACL.php
  23. 3
      src/Core/Addon.php
  24. 15
      src/Core/Cache.php
  25. 13
      src/Core/Config.php
  26. 2
      src/Core/Console.php
  27. 3
      src/Core/Hook.php
  28. 18
      src/Core/L10n.php
  29. 13
      src/Core/Lock.php
  30. 38
      src/Core/Logger.php
  31. 13
      src/Core/PConfig.php
  32. 3
      src/Core/Renderer.php
  33. 3
      src/Core/Search.php
  34. 29
      src/Core/Session.php
  35. 7
      src/Core/System.php
  36. 1
      src/Core/Theme.php
  37. 1
      src/Core/Worker.php
  38. 89
      src/DI.php
  39. 78
      src/Database/DBA.php
  40. 3
      src/Model/APContact.php
  41. 3
      src/Model/Attach.php
  42. 4
      src/Model/Contact.php
  43. 3
      src/Model/Event.php
  44. 3
      src/Model/Group.php
  45. 10
      src/Model/Item.php
  46. 3
      src/Model/ItemContent.php
  47. 3
      src/Model/ItemURI.php
  48. 3
      src/Model/Nodeinfo.php
  49. 3
      src/Model/Notify.php
  50. 3
      src/Model/PermissionSet.php
  51. 3
      src/Model/Photo.php
  52. 3
      src/Model/Process.php
  53. 3
      src/Model/Search.php
  54. 3
      src/Model/TwoFactor/AppSpecificPassword.php
  55. 3
      src/Model/TwoFactor/RecoveryCode.php
  56. 3
      src/Module/Admin/Summary.php
  57. 5
      src/Module/Api/Mastodon/FollowRequests.php
  58. 8
      src/Module/Base/Api.php
  59. 3
      src/Module/BaseSearchModule.php
  60. 5
      src/Module/Delegation.php
  61. 15
      src/Module/Diaspora/Receive.php
  62. 3
      src/Module/Item/Compose.php
  63. 9
      src/Module/Item/Ignore.php
  64. 9
      src/Module/Notifications/Notify.php
  65. 5
      src/Module/Profile.php
  66. 2
      src/Module/Register.php
  67. 4
      src/Module/Search/Index.php
  68. 6
      src/Module/Search/Saved.php
  69. 9
      src/Module/Security/Login.php
  70. 5
      src/Module/Security/TwoFactor/Recovery.php
  71. 4
      src/Module/Security/TwoFactor/Verify.php
  72. 3
      src/Module/Settings/Delegation.php
  73. 2
      src/Module/Settings/UserExport.php
  74. 7
      src/Network/FKOAuth1.php
  75. 12
      src/Object/Post.php
  76. 3
      src/Object/Thread.php
  77. 1
      src/Protocol/ActivityPub/Transmitter.php
  78. 7
      src/Protocol/DFRN.php
  79. 1
      src/Util/Images.php
  80. 1
      src/Util/Proxy.php
  81. 3
      src/Util/Security.php
  82. 3
      src/Worker/APDelivery.php
  83. 1
      src/Worker/Cron.php
  84. 1
      src/Worker/CronJobs.php
  85. 3
      src/Worker/DBUpdate.php
  86. 3
      src/Worker/Delivery.php
  87. 1
      src/Worker/Expire.php
  88. 4
      src/Worker/Notifier.php
  89. 2
      src/Worker/OnePoll.php
  90. 1
      src/Worker/ProfileUpdate.php
  91. 4
      tests/Util/AppMockTrait.php
  92. 6
      tests/include/ApiTest.php
  93. 4
      tests/src/Console/AutomaticInstallationConsoleTest.php
  94. 5
      tests/src/Core/InstallerTest.php
  95. 4
      tests/src/Core/Lock/SemaphoreLockTest.php
  96. 4
      tests/src/Database/DBATest.php
  97. 4
      tests/src/Database/DBStructureTest.php
  98. 4
      tests/src/Network/CurlResultTest.php

3
bin/auth_ejabberd.php

@ -34,7 +34,6 @@
use Dice\Dice;
use Friendica\App\Mode;
use Friendica\BaseObject;
use Friendica\Util\ExAuth;
use Psr\Log\LoggerInterface;
@ -57,7 +56,7 @@ require dirname(__DIR__) . '/vendor/autoload.php';
$dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php');
$dice = $dice->addRule(LoggerInterface::class,['constructParams' => ['auth_ejabberd']]);
BaseObject::setDependencyInjection($dice);
\Friendica\DI::init($dice);
$appMode = $dice->create(Mode::class);

2
bin/daemon.php

@ -36,7 +36,7 @@ require dirname(__DIR__) . '/vendor/autoload.php';
$dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php');
$dice = $dice->addRule(LoggerInterface::class,['constructParams' => ['daemon']]);
\Friendica\BaseObject::setDependencyInjection($dice);
\Friendica\DI::init($dice);
$a = \Friendica\DI::app();
if ($a->getMode()->isInstall()) {

3
bin/worker.php

@ -7,7 +7,6 @@
use Dice\Dice;
use Friendica\App;
use Friendica\BaseObject;
use Friendica\Core\Config;
use Friendica\Core\Update;
use Friendica\Core\Worker;
@ -35,7 +34,7 @@ require dirname(__DIR__) . '/vendor/autoload.php';
$dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php');
$dice = $dice->addRule(LoggerInterface::class,['constructParams' => ['worker']]);
BaseObject::setDependencyInjection($dice);
\Friendica\DI::init($dice);
$a = Friendica\DI::app();
// Check the database structure and possibly fixes it

1
boot.php

@ -18,7 +18,6 @@
*/
use Friendica\App;
use Friendica\BaseObject;
use Friendica\Core\Config;
use Friendica\Core\PConfig;
use Friendica\Core\Protocol;

16
include/api.php

@ -7,12 +7,10 @@
*/
use Friendica\App;
use Friendica\BaseObject;
use Friendica\Content\ContactSelector;
use Friendica\Content\Feature;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML;
use Friendica\App\Authentication;
use Friendica\Core\Config;
use Friendica\Core\Hook;
use Friendica\Core\L10n;
@ -23,11 +21,11 @@ use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Group;
use Friendica\Model\Item;
use Friendica\Model\Mail;
use Friendica\Model\Notify;
use Friendica\Model\Photo;
use Friendica\Model\Profile;
use Friendica\Model\User;
@ -254,9 +252,7 @@ function api_login(App $a)
throw new UnauthorizedException("This API requires login");
}
/** @var Authentication $authentication */
$authentication = BaseObject::getClass(Authentication::class);
$authentication->setForUser($a, $record);
DI::auth()->setForUser($a, $record);
$_SESSION["allow_api"] = true;
@ -5909,10 +5905,7 @@ function api_friendica_notification($type)
if ($a->argc!==3) {
throw new BadRequestException("Invalid argument count");
}
/** @var Notify $nm */
$nm = BaseObject::getClass(Notify::class);
$notes = $nm->getAll([], ['seen' => 'ASC', 'date' => 'DESC'], 50);
$notes = DI::notify()->getAll([], ['seen' => 'ASC', 'date' => 'DESC'], 50);
if ($type == "xml") {
$xmlnotes = [];
@ -5954,8 +5947,7 @@ function api_friendica_notification_seen($type)
$id = (!empty($_REQUEST['id']) ? intval($_REQUEST['id']) : 0);
/** @var Notify $nm */
$nm = BaseObject::getClass(Notify::class);
$nm = DI::notify();
$note = $nm->getByID($id);
if (is_null($note)) {
throw new BadRequestException("Invalid argument");

19
include/conversation.php

@ -4,10 +4,8 @@
*/
use Friendica\App;
use Friendica\BaseObject;
use Friendica\Content\ContactSelector;
use Friendica\Content\Feature;
use Friendica\Content\Item as ContentItem;
use Friendica\Content\Pager;
use Friendica\Content\Text\BBCode;
use Friendica\Core\Config;
@ -20,6 +18,7 @@ use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\Profile;
@ -141,8 +140,7 @@ function localize_item(&$item)
During the further steps of the database restructuring I would like to address this issue.
*/
/** @var Activity $activity */
$activity = BaseObject::getClass(Activity::class);
$activity = DI::activity();
$xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
if ($activity->match($item['verb'], Activity::LIKE)
@ -399,8 +397,7 @@ function count_descendants($item) {
function visible_activity($item) {
/** @var Activity $activity */
$activity = BaseObject::getClass(Activity::class);
$activity = DI::activity();
if (empty($item['verb']) || $activity->isHidden($item['verb'])) {
return false;
@ -668,10 +665,7 @@ function conversation(App $a, array $items, Pager $pager, $mode, $update, $previ
$body = Item::prepareBody($item, true, $preview);
/** @var ContentItem $contItem */
$contItem = BaseObject::getClass(ContentItem::class);
list($categories, $folders) = $contItem->determineCategoriesTerms($item);
list($categories, $folders) = DI::contentItem()->determineCategoriesTerms($item);
if (!empty($item['content-warning']) && PConfig::get(local_user(), 'system', 'disable_cw', false)) {
$title = ucfirst($item['content-warning']);
@ -1031,10 +1025,7 @@ function builtin_activity_puller($item, &$conv_responses) {
return;
}
/** @var Activity $activity */
$activity = BaseObject::getClass(Activity::class);
if (!empty($item['verb']) && $activity->match($item['verb'], $verb) && ($item['id'] != $item['parent'])) {
if (!empty($item['verb']) && DI::activity()->match($item['verb'], $verb) && ($item['id'] != $item['parent'])) {
$author = ['uid' => 0, 'id' => $item['author-id'],
'network' => $item['author-network'], 'url' => $item['author-link']];
$url = Contact::magicLinkByContact($author);

5
include/items.php

@ -3,13 +3,10 @@
* @file include/items.php
*/
use Friendica\BaseObject;
use Friendica\Content\Feature;
use Friendica\Core\Config;
use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\Logger;
use Friendica\Core\PConfig;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\System;
@ -19,11 +16,9 @@ use Friendica\Model\Item;
use Friendica\Protocol\DFRN;
use Friendica\Protocol\Feed;
use Friendica\Protocol\OStatus;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
use Friendica\Util\ParseUrl;
use Friendica\Util\Strings;
use Friendica\Util\Temporal;
require_once __DIR__ . '/../mod/share.php';

2
index.php

@ -15,7 +15,7 @@ require __DIR__ . '/vendor/autoload.php';
$dice = (new Dice())->addRules(include __DIR__ . '/static/dependencies.config.php');
$dice = $dice->addRule(Friendica\App\Mode::class, ['call' => [['determineRunMode', [false, $_SERVER], Dice::CHAIN_CALL]]]);
\Friendica\BaseObject::setDependencyInjection($dice);
\Friendica\DI::init($dice);
$a = \Friendica\DI::app();

7
mod/dfrn_poll.php

@ -5,14 +5,13 @@
*/
use Friendica\App;
use Friendica\BaseObject;
use Friendica\App\Authentication;
use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\Core\Logger;
use Friendica\Core\System;
use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Module\Security\Login;
use Friendica\Protocol\DFRN;
use Friendica\Protocol\OStatus;
@ -22,9 +21,7 @@ use Friendica\Util\XML;
function dfrn_poll_init(App $a)
{
/** @var Authentication $authentication */
$authentication = BaseObject::getClass(Authentication::class);
$authentication->withSession($a);
DI::auth()->withSession($a);
$dfrn_id = $_GET['dfrn_id'] ?? '';
$type = ($_GET['type'] ?? '') ?: 'data';

5
mod/events.php

@ -5,7 +5,6 @@
*/
use Friendica\App;
use Friendica\BaseObject;
use Friendica\Content\Nav;
use Friendica\Content\Widget\CalendarExport;
use Friendica\Core\ACL;
@ -19,6 +18,7 @@ use Friendica\Database\DBA;
use Friendica\Model\Event;
use Friendica\Model\Item;
use Friendica\Model\Profile;
use Friendica\Module\Login;
use Friendica\Module\Security\Login;
use Friendica\Util\ACLFormatter;
use Friendica\Util\DateTimeFormat;
@ -150,8 +150,7 @@ function events_post(App $a)
if ($share) {
/** @var ACLFormatter $aclFormatter */
$aclFormatter = BaseObject::getClass(ACLFormatter::class);
$aclFormatter = \Friendica\DI::aclFormatter();
$str_group_allow = $aclFormatter->toString($_POST['group_allow'] ?? '');
$str_contact_allow = $aclFormatter->toString($_POST['contact_allow'] ?? '');

10
mod/item.php

@ -16,7 +16,6 @@
*/
use Friendica\App;
use Friendica\BaseObject;
use Friendica\Content\Pager;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML;
@ -29,6 +28,7 @@ use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Attach;
use Friendica\Model\Contact;
use Friendica\Model\Conversation;
@ -39,7 +39,6 @@ use Friendica\Model\Term;
use Friendica\Protocol\Activity;
use Friendica\Protocol\Diaspora;
use Friendica\Protocol\Email;
use Friendica\Util\ACLFormatter;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Emailer;
use Friendica\Util\Security;
@ -273,8 +272,7 @@ function item_post(App $a) {
} else {
// use the posted permissions
/** @var ACLFormatter $aclFormatter */
$aclFormatter = BaseObject::getClass(ACLFormatter::class);
$aclFormatter = DI::aclFormatter();
$str_group_allow = $aclFormatter->toString($_REQUEST['group_allow'] ?? '');
$str_contact_allow = $aclFormatter->toString($_REQUEST['contact_allow'] ?? '');
@ -506,9 +504,7 @@ function item_post(App $a) {
$objecttype = Activity\ObjectType::BOOKMARK;
}
/** @var BBCode\Video $bbCodeVideo */
$bbCodeVideo = BaseObject::getClass(BBCode\Video::class);
$body = $bbCodeVideo->transform($body);
$body = DI::bbCodeVideo()->transform($body);
// Fold multi-line [code] sequences
$body = preg_replace('/\[\/code\]\s*\[code\]/ism', "\n", $body);

6
mod/lockview.php

@ -3,13 +3,12 @@
* @file mod/lockview.php
*/
use Friendica\App;
use Friendica\BaseObject;
use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Group;
use Friendica\Model\Item;
use Friendica\Util\ACLFormatter;
function lockview_content(App $a)
{
@ -61,8 +60,7 @@ function lockview_content(App $a)
exit();
}
/** @var ACLFormatter $aclFormatter */
$aclFormatter = BaseObject::getClass(ACLFormatter::class);
$aclFormatter = DI::aclFormatter();
$allowed_users = $aclFormatter->expand($item['allow_cid']);
$allowed_groups = $aclFormatter->expand($item['allow_gid']);

12
mod/network.php

@ -5,7 +5,6 @@
*/
use Friendica\App;
use Friendica\BaseObject;
use Friendica\Content\Feature;
use Friendica\Content\ForumManager;
use Friendica\Content\Nav;
@ -22,6 +21,7 @@ use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Group;
use Friendica\Model\Item;
@ -52,12 +52,9 @@ function network_init(App $a)
$group_id = 0;
}
/** @var DateTimeFormat $dtFormat */
$dtFormat = BaseObject::getClass(DateTimeFormat::class);
if ($a->argc > 1) {
for ($x = 1; $x < $a->argc; $x ++) {
if ($dtFormat->isYearMonth($a->argv[$x])) {
if (DI::dtFormat()->isYearMonth($a->argv[$x])) {
$is_a_date_query = true;
break;
}
@ -465,12 +462,9 @@ function networkThreadedView(App $a, $update, $parent)
$default_permissions = [];
/** @var DateTimeFormat $dtFormat */
$dtFormat = BaseObject::getClass(DateTimeFormat::class);
if ($a->argc > 1) {
for ($x = 1; $x < $a->argc; $x ++) {
if ($dtFormat->isYearMonth($a->argv[$x])) {
if (DI::dtFormat()->isYearMonth($a->argv[$x])) {
if ($datequery) {
$datequery2 = Strings::escapeHtml($a->argv[$x]);
} else {

4
mod/notifications.php

@ -13,6 +13,7 @@ use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Module\Security\Login;
use Friendica\Model\Introduction;
use Friendica\Model\Notify;
@ -61,8 +62,7 @@ function notifications_content(App $a)
$json = (($a->argc > 1 && $a->argv[$a->argc - 1] === 'json') ? true : false);
/** @var Notify $nm */
$nm = \Friendica\BaseObject::getClass(Notify::class);
$nm = DI::notify();
$o = '';
// Get the nav tabs for the notification pages

12
mod/photos.php

@ -4,7 +4,6 @@
*/
use Friendica\App;
use Friendica\BaseObject;
use Friendica\Content\Feature;
use Friendica\Content\Nav;
use Friendica\Content\Pager;
@ -18,6 +17,7 @@ use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\Photo;
@ -26,7 +26,6 @@ use Friendica\Model\User;
use Friendica\Network\Probe;
use Friendica\Object\Image;
use Friendica\Protocol\Activity;
use Friendica\Util\ACLFormatter;
use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Images;
@ -298,8 +297,7 @@ function photos_post(App $a)
$albname = !empty($_POST['albname']) ? Strings::escapeTags(trim($_POST['albname'])) : '';
$origaname = !empty($_POST['origaname']) ? Strings::escapeTags(trim($_POST['origaname'])) : '';
/** @var ACLFormatter $aclFormatter */
$aclFormatter = BaseObject::getClass(ACLFormatter::class);
$aclFormatter = DI::aclFormatter();
$str_group_allow = !empty($_POST['group_allow']) ? $aclFormatter->toString($_POST['group_allow']) : '';
$str_contact_allow = !empty($_POST['contact_allow']) ? $aclFormatter->toString($_POST['contact_allow']) : '';
@ -640,8 +638,7 @@ function photos_post(App $a)
$group_deny = $_REQUEST['group_deny'] ?? [];
$contact_deny = $_REQUEST['contact_deny'] ?? [];
/** @var ACLFormatter $aclFormatter */
$aclFormatter = BaseObject::getClass(ACLFormatter::class);
$aclFormatter = DI::aclFormatter();
$str_group_allow = $aclFormatter->toString(is_array($group_allow) ? $group_allow : explode(',', $group_allow));
$str_contact_allow = $aclFormatter->toString(is_array($contact_allow) ? $contact_allow : explode(',', $contact_allow));
@ -1442,8 +1439,7 @@ function photos_content(App $a)
$template = $tpl;
$sparkle = '';
/** @var Activity $activity */
$activity = BaseObject::getClass(Activity::class);
$activity = DI::activity();
if (($activity->match($item['verb'], Activity::LIKE) ||
$activity->match($item['verb'], Activity::DISLIKE)) &&

7
mod/settings.php

@ -5,7 +5,6 @@
use Friendica\App;
use Friendica\BaseModule;
use Friendica\BaseObject;
use Friendica\Content\Feature;
use Friendica\Content\Nav;
use Friendica\Core\ACL;
@ -20,14 +19,13 @@ use Friendica\Core\System;
use Friendica\Core\Theme;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\GContact;
use Friendica\Model\Group;
use Friendica\Model\User;
use Friendica\Module\Security\Login;
use Friendica\Protocol\Email;
use Friendica\Util\ACLFormatter;
use Friendica\Util\Network;
use Friendica\Util\Strings;
use Friendica\Util\Temporal;
use Friendica\Worker\Delivery;
@ -564,8 +562,7 @@ function settings_post(App $a)
date_default_timezone_set($timezone);
}
/** @var ACLFormatter $aclFormatter */
$aclFormatter = BaseObject::getClass(ACLFormatter::class);
$aclFormatter = DI::aclFormatter();
$str_group_allow = !empty($_POST['group_allow']) ? $aclFormatter->toString($_POST['group_allow']) : '';
$str_contact_allow = !empty($_POST['contact_allow']) ? $aclFormatter->toString($_POST['contact_allow']) : '';

4
src/App/Module.php

@ -3,7 +3,7 @@
namespace Friendica\App;
use Friendica\App;
use Friendica\BaseObject;
use Friendica\BaseModule;
use Friendica\Core;
use Friendica\LegacyModule;
use Friendica\Module\Home;
@ -59,7 +59,7 @@ class Module
private $module;
/**
* @var BaseObject The module class
* @var BaseModule The module class
*/
private $module_class;

2
src/BaseModule.php

@ -14,7 +14,7 @@ use Friendica\Core\Logger;
*
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
abstract class BaseModule extends BaseObject
abstract class BaseModule
{
/**
* @brief Initialization method common to both content() and post()

58
src/BaseObject.php

@ -1,58 +0,0 @@
<?php
/**
* @file src/BaseObject.php
*/
namespace Friendica;
require_once __DIR__ . '/../boot.php';
use Dice\Dice;
use Friendica\Network\HTTPException\InternalServerErrorException;
/**
* Basic object
*
* Contains what is useful to any object
*
* Act's like a global registry for classes
*/
class BaseObject
{
/**
* @var Dice The Dependency Injection library
*/
private static $dice;
/**
* Set's the dependency injection library for a global usage
*
* @param Dice $dice The dependency injection library
*/
public static function setDependencyInjection(Dice $dice)
{
self::$dice = $dice;
DI::init($dice);
}
/**
* Returns the initialized class based on it's name
*
* @param string $name The name of the class
*
* @return object The initialized name
*
* @throws InternalServerErrorException
*/
public static function getClass(string $name)
{
if (empty(self::$dice)) {
throw new InternalServerErrorException('DICE isn\'t initialized.');
}
if (class_exists($name) || interface_exists($name)) {
return self::$dice->create($name);
} else {
throw new InternalServerErrorException('Class \'' . $name . '\' isn\'t valid.');
}
}
}

3
src/Content/Text/BBCode.php

@ -8,7 +8,6 @@ namespace Friendica\Content\Text;
use DOMDocument;
use DOMXPath;
use Exception;
use Friendica\BaseObject;
use Friendica\Content\OEmbed;
use Friendica\Content\Smilies;
use Friendica\Core\Cache;
@ -34,7 +33,7 @@ use Friendica\Util\Proxy as ProxyUtils;
use Friendica\Util\Strings;
use Friendica\Util\XML;
class BBCode extends BaseObject
class BBCode
{
/**
* @brief Fetches attachment data that were generated the old way

3
src/Content/Text/Markdown.php

@ -6,7 +6,6 @@
namespace Friendica\Content\Text;
use Friendica\BaseObject;
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Model\Contact;
@ -16,7 +15,7 @@ use Friendica\Model\Contact;
*
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class Markdown extends BaseObject
class Markdown
{
/**
* Converts a Markdown string into HTML. The hardwrap parameter maximizes

3
src/Core/ACL.php

@ -7,7 +7,6 @@
namespace Friendica\Core;
use Friendica\App\Page;
use Friendica\BaseObject;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
@ -18,7 +17,7 @@ use Friendica\Model\Group;
*
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class ACL extends BaseObject
class ACL
{
/**
* Returns a select input tag with all the contact of the local user

3
src/Core/Addon.php

@ -5,7 +5,6 @@
namespace Friendica\Core;
use Friendica\BaseObject;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Util\Strings;
@ -13,7 +12,7 @@ use Friendica\Util\Strings;
/**
* Some functions to handle addons
*/
class Addon extends BaseObject
class Addon
{
/**
* The addon sub-directory

15
src/Core/Cache.php

@ -4,14 +4,13 @@
*/
namespace Friendica\Core;
use Friendica\BaseObject;
use Friendica\Core\Cache\Cache as CacheClass;
use Friendica\Core\Cache\ICache;
use Friendica\DI;
/**
* @brief Class for storing data for a short time
*/
class Cache extends BaseObject
class Cache
{
/** @deprecated Use CacheClass::MONTH */
const MONTH = CacheClass::MONTH;
@ -42,7 +41,7 @@ class Cache extends BaseObject
*/
public static function getAllKeys($prefix = null)
{
return self::getClass(ICache::class)->getAllKeys($prefix);
return DI::cache()->getAllKeys($prefix);
}
/**
@ -55,7 +54,7 @@ class Cache extends BaseObject
*/
public static function get($key)
{
return self::getClass(ICache::class)->get($key);
return DI::cache()->get($key);
}
/**
@ -72,7 +71,7 @@ class Cache extends BaseObject
*/
public static function set($key, $value, $duration = CacheClass::MONTH)
{
return self::getClass(ICache::class)->set($key, $value, $duration);
return DI::cache()->set($key, $value, $duration);
}
/**
@ -85,7 +84,7 @@ class Cache extends BaseObject
*/
public static function delete($key)
{
return self::getClass(ICache::class)->delete($key);
return DI::cache()->delete($key);
}
/**
@ -98,6 +97,6 @@ class Cache extends BaseObject
*/
public static function clear($outdated = true)
{
return self::getClass(ICache::class)->clear($outdated);
return DI::cache()->clear($outdated);
}
}

13
src/Core/Config.php

@ -8,8 +8,7 @@
*/
namespace Friendica\Core;
use Friendica\BaseObject;
use Friendica\Core\Config\Configuration;
use Friendica\DI;
/**
* @brief Arbitrary system configuration storage
@ -18,7 +17,7 @@ use Friendica\Core\Config\Configuration;
* If we ever would decide to return exactly the variable type as entered,
* we will have fun with the additional features. :-)
*/
class Config extends BaseObject
class Config
{
/**
* @brief Loads all configuration values of family into a cached storage.
@ -29,7 +28,7 @@ class Config extends BaseObject
*/
public static function load($cat = "config")
{
self::getClass(Configuration::class)->load($cat);
DI::config()->load($cat);
}
/**
@ -45,7 +44,7 @@ class Config extends BaseObject
*/
public static function get($cat, $key, $default_value = null, $refresh = false)
{
return self::getClass(Configuration::class)->get($cat, $key, $default_value, $refresh);
return DI::config()->get($cat, $key, $default_value, $refresh);
}
/**
@ -63,7 +62,7 @@ class Config extends BaseObject
*/
public static function set($cat, $key, $value)
{
return self::getClass(Configuration::class)->set($cat, $key, $value);
return DI::config()->set($cat, $key, $value);
}
/**
@ -76,6 +75,6 @@ class Config extends BaseObject
*/
public static function delete($cat, $key)
{
return self::getClass(Configuration::class)->delete($cat, $key);
return DI::config()->delete($cat, $key);
}
}

2
src/Core/Console.php

@ -146,7 +146,7 @@ HELP;
$className = $this->subConsoles[$command];
Friendica\BaseObject::setDependencyInjection($this->dice);
Friendica\DI::init($this->dice);
/** @var Console $subconsole */
$subconsole = $this->dice->create($className, [$subargs]);

3
src/Core/Hook.php

@ -5,7 +5,6 @@
namespace Friendica\Core;
use Friendica\App;
use Friendica\BaseObject;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Util\Strings;
@ -13,7 +12,7 @@ use Friendica\Util\Strings;
/**
* Some functions to handle hooks
*/
class Hook extends BaseObject
class Hook
{
/**
* Array of registered hooks

18
src/Core/L10n.php

@ -4,14 +4,14 @@
*/
namespace Friendica\Core;
use Friendica\BaseObject;
use Friendica\Core\L10n\L10n as L10nClass;
use Friendica\DI;
/**
* Provide Language, Translation, and Localization functions to the application
* Localization can be referred to by the numeronym L10N (as in: "L", followed by ten more letters, and then "N").
*/
class L10n extends BaseObject
class L10n
{
/**
* Returns the current language code
@ -20,7 +20,7 @@ class L10n extends BaseObject
*/
public static function getCurrentLang()
{
return self::getClass(L10nClass::class)->getCurrentLang();
return DI::l10n()->getCurrentLang();
}
/**
@ -32,7 +32,7 @@ class L10n extends BaseObject
*/
public static function withLang(string $lang)
{
return self::getClass(L10nClass::class)->withLang($lang);
DI::l10n()->withLang($lang);
}
/**
@ -54,7 +54,7 @@ class L10n extends BaseObject
*/
public static function t($s, ...$vars)
{
return self::getClass(L10nClass::class)->t($s, ...$vars);
return DI::l10n()->t($s, ...$vars);
}
/**
@ -79,7 +79,7 @@ class L10n extends BaseObject
*/
public static function tt(string $singular, string $plural, int $count)
{
return self::getClass(L10nClass::class)->tt($singular, $plural, $count);
return DI::l10n()->tt($singular, $plural, $count);
}
/**
@ -107,7 +107,7 @@ class L10n extends BaseObject
*/
public static function getDay($s)
{
return self::getClass(L10nClass::class)->getDay($s);
return DI::l10n()->getDay($s);
}
/**
@ -119,7 +119,7 @@ class L10n extends BaseObject
*/
public static function getDayShort($s)
{
return self::getClass(L10nClass::class)->getDayShort($s);
return DI::l10n()->getDayShort($s);
}
/**
@ -131,6 +131,6 @@ class L10n extends BaseObject
*/
public static function getPokeVerbs()
{
return self::getClass(L10nClass::class)->getPokeVerbs();
return DI::l10n()->getPokeVerbs();
}
}

13
src/Core/Lock.php

@ -7,14 +7,13 @@
namespace Friendica\Core;
use Friendica\BaseObject;
use Friendica\Core\Cache\Cache;
use Friendica\Core\Lock\ILock;
use Friendica\DI;
/**
* This class contain Functions for preventing parallel execution of functions
*/
class Lock extends BaseObject
class Lock
{
/**
* @brief Acquires a lock for a given name
@ -28,7 +27,7 @@ class Lock extends BaseObject
*/
public static function acquire($key, $timeout = 120, $ttl = Cache::FIVE_MINUTES)
{
return self::getClass(ILock::class)->acquireLock($key, $timeout, $ttl);
return DI::lock()->acquireLock($key, $timeout, $ttl);
}
/**
@ -37,12 +36,12 @@ class Lock extends BaseObject
* @param string $key Name of the lock
* @param bool $override Overrides the lock to get releases
*
* @return void
* @return bool
* @throws \Exception
*/
public static function release($key, $override = false)
{
return self::getClass(ILock::class)->releaseLock($key, $override);
return DI::lock()->releaseLock($key, $override);
}
/**
@ -52,6 +51,6 @@ class Lock extends BaseObject
*/
public static function releaseAll()
{
self::getClass(ILock::class)->releaseAll();
DI::lock()->releaseAll();
}
}

38
src/Core/Logger.php

@ -4,7 +4,7 @@
*/
namespace Friendica\Core;
use Friendica\BaseObject;
use Friendica\DI;
use Friendica\Util\Logger\WorkerLogger;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
@ -12,7 +12,7 @@ use Psr\Log\LogLevel;
/**
* @brief Logger functions
*/
class Logger extends BaseObject
class Logger
{
/**
* @see Logger::error()
@ -66,6 +66,18 @@ class Logger extends BaseObject
self::DATA => 'Data',
];
/**
* @return LoggerInterface
*/
private static function getWorker()
{
if (self::$type === self::TYPE_LOGGER) {
return DI::logger();
} else {
return DI::workerLogger();
}
}
/**
* Enable additional logging for worker usage
*
@ -76,7 +88,7 @@ class Logger extends BaseObject
public static function enableWorker(string $functionName)
{
self::$type = self::TYPE_WORKER;
self::getClass(self::$type)->setFunctionName($functionName);
self::getWorker()->setFunctionName($functionName);
}
/**
@ -100,7 +112,7 @@ class Logger extends BaseObject
*/
public static function emergency($message, $context = [])
{
self::getClass(self::$type)->emergency($message, $context);
self::getWorker()->emergency($message, $context);
}
/**
@ -118,7 +130,7 @@ class Logger extends BaseObject
*/
public static function alert($message, $context = [])
{
self::getClass(self::$type)->alert($message, $context);
self::getWorker()->alert($message, $context);
}
/**
@ -135,7 +147,7 @@ class Logger extends BaseObject
*/
public static function critical($message, $context = [])
{
self::getClass(self::$type)->critical($message, $context);
self::getWorker()->critical($message, $context);
}
/**
@ -151,7 +163,7 @@ class Logger extends BaseObject
*/
public static function error($message, $context = [])
{
self::getClass(self::$type)->error($message, $context);
self::getWorker()->error($message, $context);
}
/**
@ -169,7 +181,7 @@ class Logger extends BaseObject
*/
public static function warning($message, $context = [])
{
self::getClass(self::$type)->warning($message, $context);
self::getWorker()->warning($message, $context);
}
/**
@ -184,7 +196,7 @@ class Logger extends BaseObject
*/
public static function notice($message, $context = [])
{
self::getClass(self::$type)->notice($message, $context);
self::getWorker()->notice($message, $context);
}
/**
@ -201,7 +213,7 @@ class Logger extends BaseObject
*/
public static function info($message, $context = [])
{
self::getClass(self::$type)->info($message, $context);
self::getWorker()->info($message, $context);
}
/**
@ -216,7 +228,7 @@ class Logger extends BaseObject
*/
public static function debug($message, $context = [])
{
self::getClass(self::$type)->debug($message, $context);
self::getWorker()->debug($message, $context);
}
/**
@ -230,7 +242,7 @@ class Logger extends BaseObject
*/
public static function log($msg, $level = LogLevel::INFO)
{
self::getClass(self::$type)->log($level, $msg);
self::getWorker()->log($level, $msg);
}
/**
@ -245,6 +257,6 @@ class Logger extends BaseObject
*/
public static function devLog($msg, $level = LogLevel::DEBUG)
{
self::getClass('$devLogger')->log($level, $msg);
DI::devLogger()->log($level, $msg);
}
}

13
src/Core/PConfig.php

@ -8,8 +8,7 @@
*/
namespace Friendica\Core;
use Friendica\BaseObject;
use Friendica\Core\Config\PConfiguration;
use Friendica\DI;
/**
* @brief Management of user configuration storage
@ -18,7 +17,7 @@ use Friendica\Core\Config\PConfiguration;
* The PConfig::get() functions return boolean false for keys that are unset,
* and this could lead to subtle bugs.
*/
class PConfig extends BaseObject
class PConfig
{
/**
* @brief Loads all configuration values of a user's config family into a cached storage.
@ -30,7 +29,7 @@ class PConfig extends BaseObject
*/
public static function load(int $uid, string $cat)
{
self::getClass(PConfiguration::class)->load($uid, $cat);
DI::pConfig()->load($uid, $cat);
}
/**
@ -47,7 +46,7 @@ class PConfig extends BaseObject
*/
public static function get(int $uid, string $cat, string $key, $default_value = null, bool $refresh = false)
{
return self::getClass(PConfiguration::class)->get($uid, $cat, $key, $default_value, $refresh);
return DI::pConfig()->get($uid, $cat, $key, $default_value, $refresh);
}
/**
@ -62,7 +61,7 @@ class PConfig extends BaseObject
*/
public static function set(int $uid, string $cat, string $key, $value)
{
return self::getClass(PConfiguration::class)->set($uid, $cat, $key, $value);
return DI::pConfig()->set($uid, $cat, $key, $value);
}
/**
@ -76,6 +75,6 @@ class PConfig extends BaseObject
*/
public static function delete(int $uid, string $cat, string $key)
{
return self::getClass(PConfiguration::class)->delete($uid, $cat, $key);
return DI::pConfig()->delete($uid, $cat, $key);
}
}

3
src/Core/Renderer.php

@ -6,7 +6,6 @@
namespace Friendica\Core;
use Exception;
use Friendica\BaseObject;
use Friendica\DI;
use Friendica\Render\FriendicaSmarty;
use Friendica\Render\ITemplateEngine;
@ -14,7 +13,7 @@ use Friendica\Render\ITemplateEngine;
/**
* @brief This class handles Renderer related functions.
*/
class Renderer extends BaseObject
class Renderer
{
/**
* @brief An array of registered template engines ('name'=>'class name')

3
src/Core/Search.php

@ -2,7 +2,6 @@
namespace Friendica\Core;
use Friendica\BaseObject;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
@ -21,7 +20,7 @@ use Friendica\Util\Strings;
* - Search in the local directory
* - Search in the global directory
*/
class Search extends BaseObject
class Search
{
const DEFAULT_DIRECTORY = 'https://dir.friendica.social';

29
src/Core/Session.php

@ -5,9 +5,8 @@
*/
namespace Friendica\Core;
use Friendica\BaseObject;
use Friendica\Core\Session\ISession;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Util\Strings;
@ -16,39 +15,39 @@ use Friendica\Util\Strings;
*
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class Session extends BaseObject
class Session
{
public static $exists = false;
public static $expire = 180000;
public static function exists($name)
{
return self::getClass(ISession::class)->exists($name);
return DI::session()->exists($name);
}
public static function get($name, $defaults = null)
{
return self::getClass(ISession::class)->get($name, $defaults);
return DI::session()->get($name, $defaults);
}
public static function set($name, $value)
{
self::getClass(ISession::class)->set($name, $value);
DI::session()->set($name, $value);
}
public static function setMultiple(array $values)
{
self::getClass(ISession::class)->setMultiple($values);
DI::session()->setMultiple($values);
}
public static function remove($name)
{
self::getClass(ISession::class)->remove($name);
DI::session()->remove($name);
}
public static function clear()
{
self::getClass(ISession::class)->clear();
DI::session()->clear();
}
/**
@ -59,8 +58,7 @@ class Session extends BaseObject
*/
public static function getRemoteContactID($uid)
{
/** @var ISession $session */
$session = self::getClass(ISession::class);
$session = DI::session();
if (empty($session->get('remote')[$uid])) {
return false;
@ -77,8 +75,7 @@ class Session extends BaseObject
*/
public static function getUserIDForVisitorContactID($cid)
{
/** @var ISession $session */
$session = self::getClass(ISession::class);
$session = DI::session();
if (empty($session->get('remote'))) {
return false;
@ -94,8 +91,7 @@ class Session extends BaseObject
*/
public static function setVisitorsContacts()
{
/** @var ISession $session */
$session = self::getClass(ISession::class);
$session = DI::session();