From 1de3f186d79f3703850524c1d58c237be3eb25f3 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Sun, 15 Dec 2019 22:34:11 +0100 Subject: [PATCH 01/34] Introduce new DI container - Adding Friendica\DI class for getting dynamic classes - Replacing BaseObject::getApp() with this class --- bin/daemon.php | 2 +- bin/worker.php | 2 +- boot.php | 6 ++-- include/api.php | 6 ++-- include/items.php | 2 +- index.php | 2 +- src/BaseObject.php | 13 +------ src/Console/PostUpdate.php | 2 +- src/Content/Text/BBCode.php | 9 ++--- src/Content/Text/Markdown.php | 3 +- src/Core/ACL.php | 5 +-- src/Core/Addon.php | 9 ++--- src/Core/Hook.php | 9 ++--- src/Core/Renderer.php | 5 +-- src/Core/Search.php | 5 +-- src/Core/System.php | 5 +-- src/Core/Theme.php | 5 +-- src/Core/Worker.php | 5 +-- src/DI.php | 33 +++++++++++++++++ src/LegacyModule.php | 2 +- src/Model/Attach.php | 3 +- src/Model/Contact.php | 3 +- src/Model/Item.php | 9 ++--- src/Model/Nodeinfo.php | 3 +- src/Model/Notify.php | 5 +-- src/Model/Photo.php | 3 +- src/Module/Admin/Addons/Details.php | 5 +-- src/Module/Admin/Addons/Index.php | 3 +- src/Module/Admin/Blocklist/Contact.php | 5 +-- src/Module/Admin/Blocklist/Server.php | 5 +-- src/Module/Admin/DBSync.php | 3 +- src/Module/Admin/Features.php | 3 +- src/Module/Admin/Item/Delete.php | 3 +- src/Module/Admin/Item/Source.php | 3 +- src/Module/Admin/Logs/Settings.php | 5 +-- src/Module/Admin/Queue.php | 3 +- src/Module/Admin/Site.php | 5 +-- src/Module/Admin/Summary.php | 5 +-- src/Module/Admin/Themes/Details.php | 5 +-- src/Module/Admin/Themes/Embed.php | 7 ++-- src/Module/Admin/Themes/Index.php | 3 +- src/Module/Admin/Tos.php | 3 +- src/Module/Admin/Users.php | 5 +-- src/Module/AllFriends.php | 3 +- src/Module/Apps.php | 3 +- src/Module/Attach.php | 3 +- src/Module/Base/Api.php | 7 ++-- src/Module/BaseAdminModule.php | 3 +- src/Module/BaseSearchModule.php | 5 +-- src/Module/BaseSettingsModule.php | 3 +- src/Module/Bookmarklet.php | 3 +- src/Module/Contact.php | 5 +-- src/Module/Debug/Feed.php | 3 +- src/Module/Debug/ItemBody.php | 3 +- src/Module/Debug/Localtime.php | 5 +-- src/Module/Delegation.php | 11 +++--- src/Module/Diaspora/Fetch.php | 3 +- src/Module/Directory.php | 3 +- src/Module/Feed.php | 3 +- src/Module/Filer/RemoveTag.php | 3 +- src/Module/Filer/SaveTag.php | 5 +-- src/Module/FollowConfirm.php | 3 +- src/Module/Followers.php | 3 +- src/Module/Following.php | 3 +- src/Module/Friendica.php | 5 +-- src/Module/Group.php | 7 ++-- src/Module/Help.php | 3 +- src/Module/Home.php | 3 +- src/Module/Inbox.php | 3 +- src/Module/Install.php | 7 ++-- src/Module/Invite.php | 5 +-- src/Module/Item/Compose.php | 5 +-- src/Module/Item/Ignore.php | 3 +- src/Module/Like.php | 3 +- src/Module/Magic.php | 5 +-- src/Module/Maintenance.php | 3 +- src/Module/Manifest.php | 3 +- src/Module/NodeInfo.php | 3 +- src/Module/Notifications/Notify.php | 5 +-- src/Module/Objects.php | 3 +- src/Module/Oembed.php | 3 +- src/Module/OpenSearch.php | 5 +-- src/Module/Outbox.php | 3 +- src/Module/Photo.php | 3 +- src/Module/Pinned.php | 3 +- src/Module/Profile.php | 5 +-- src/Module/Profile/Contacts.php | 3 +- src/Module/Proxy.php | 7 ++-- src/Module/PublicRSAKey.php | 3 +- src/Module/RandomProfile.php | 3 +- src/Module/ReallySimpleDiscovery.php | 3 +- src/Module/Register.php | 7 ++-- src/Module/Search/Directory.php | 3 +- src/Module/Search/Index.php | 5 +-- src/Module/Search/Saved.php | 3 +- src/Module/Security/Login.php | 9 ++--- src/Module/Security/Logout.php | 3 +- src/Module/Security/TwoFactor/Recovery.php | 7 ++-- src/Module/Security/TwoFactor/Verify.php | 7 ++-- src/Module/Settings/Delegation.php | 11 +++--- src/Module/Settings/TwoFactor/AppSpecific.php | 13 +++---- src/Module/Settings/TwoFactor/Index.php | 11 +++--- src/Module/Settings/TwoFactor/Recovery.php | 7 ++-- src/Module/Settings/TwoFactor/Verify.php | 7 ++-- src/Module/Settings/UserExport.php | 11 +++--- src/Module/Smilies.php | 3 +- src/Module/Starred.php | 3 +- src/Module/Statistics.php | 7 ++-- src/Module/Theme.php | 3 +- src/Module/ToggleMobile.php | 3 +- src/Module/Tos.php | 3 +- src/Module/Welcome.php | 3 +- src/Module/WellKnown/HostMeta.php | 3 +- src/Module/WellKnown/NodeInfo.php | 3 +- src/Module/WellKnown/XSocialRelay.php | 3 +- src/Module/Xrd.php | 3 +- src/Network/FKOAuth1.php | 3 +- src/Object/Post.php | 9 ++--- src/Object/Thread.php | 3 +- src/Protocol/ActivityPub/Transmitter.php | 3 +- src/Util/Images.php | 3 +- src/Util/Proxy.php | 3 +- src/Worker/Cron.php | 3 +- src/Worker/CronJobs.php | 3 +- src/Worker/DBUpdate.php | 3 +- src/Worker/Delivery.php | 5 +-- src/Worker/Expire.php | 3 +- src/Worker/ForkHook.php | 3 +- src/Worker/Notifier.php | 3 +- src/Worker/ProfileUpdate.php | 3 +- tests/include/ApiTest.php | 3 +- tests/src/BaseObjectTest.php | 36 ------------------- 132 files changed, 377 insertions(+), 270 deletions(-) create mode 100644 src/DI.php delete mode 100644 tests/src/BaseObjectTest.php diff --git a/bin/daemon.php b/bin/daemon.php index 948829c1bf..b3166145b8 100755 --- a/bin/daemon.php +++ b/bin/daemon.php @@ -37,7 +37,7 @@ $dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config $dice = $dice->addRule(LoggerInterface::class,['constructParams' => ['daemon']]); \Friendica\BaseObject::setDependencyInjection($dice); -$a = \Friendica\BaseObject::getApp(); +$a = \Friendica\DI::app(); if ($a->getMode()->isInstall()) { die("Friendica isn't properly installed yet.\n"); diff --git a/bin/worker.php b/bin/worker.php index 469dcb001e..1de90d8cae 100755 --- a/bin/worker.php +++ b/bin/worker.php @@ -36,7 +36,7 @@ $dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config $dice = $dice->addRule(LoggerInterface::class,['constructParams' => ['worker']]); BaseObject::setDependencyInjection($dice); -$a = BaseObject::getApp(); +$a = Friendica\DI::app(); // Check the database structure and possibly fixes it Update::check($a->getBasePath(), true, $a->getMode()); diff --git a/boot.php b/boot.php index fd87576725..2dcc15f7d3 100644 --- a/boot.php +++ b/boot.php @@ -23,8 +23,8 @@ use Friendica\Core\Config; use Friendica\Core\PConfig; use Friendica\Core\Protocol; use Friendica\Core\System; -use Friendica\Core\Session; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Term; use Friendica\Util\BasePath; @@ -241,12 +241,12 @@ if (!defined('CURLE_OPERATION_TIMEDOUT')) { * Useful in functions which require it but don't get it passed to them * * @deprecated since version 2018.09 - * @see BaseObject::getApp() + * @see DI::app() * @return App */ function get_app() { - return BaseObject::getApp(); + return DI::app(); } /** diff --git a/include/api.php b/include/api.php index 4b7a1f742f..916051f06c 100644 --- a/include/api.php +++ b/include/api.php @@ -1370,7 +1370,7 @@ function api_get_item(array $condition) */ function api_users_show($type) { - $a = BaseObject::getApp(); + $a = Friendica\DI::app(); $user_info = api_get_user($a); @@ -2968,7 +2968,7 @@ function api_format_items_profiles($profile_row) */ function api_format_items($items, $user_info, $filter_user = false, $type = "json") { - $a = BaseObject::getApp(); + $a = Friendica\DI::app(); $ret = []; @@ -3002,7 +3002,7 @@ function api_format_items($items, $user_info, $filter_user = false, $type = "jso */ function api_format_item($item, $type = "json", $status_user = null, $author_user = null, $owner_user = null) { - $a = BaseObject::getApp(); + $a = Friendica\DI::app(); if (empty($status_user) || empty($author_user) || empty($owner_user)) { list($status_user, $author_user, $owner_user) = api_item_get_user($a, $item); diff --git a/include/items.php b/include/items.php index 3868db40a2..a449571ff7 100644 --- a/include/items.php +++ b/include/items.php @@ -344,7 +344,7 @@ function drop_items(array $items) function drop_item($id, $return = '') { - $a = BaseObject::getApp(); + $a = Friendica\DI::app(); // locate item to be deleted diff --git a/index.php b/index.php index dbdac5fcbf..a7eee2a331 100644 --- a/index.php +++ b/index.php @@ -17,7 +17,7 @@ $dice = $dice->addRule(Friendica\App\Mode::class, ['call' => [['determineRunMode \Friendica\BaseObject::setDependencyInjection($dice); -$a = \Friendica\BaseObject::getApp(); +$a = \Friendica\DI::app(); $a->runFrontend( $dice->create(\Friendica\App\Module::class), diff --git a/src/BaseObject.php b/src/BaseObject.php index 2048188451..742b2c8598 100644 --- a/src/BaseObject.php +++ b/src/BaseObject.php @@ -31,18 +31,7 @@ class BaseObject public static function setDependencyInjection(Dice $dice) { self::$dice = $dice; - } - - /** - * Get the app - * - * Same as get_app from boot.php - * - * @return App - */ - public static function getApp() - { - return self::getClass(App::class); + DI::init($dice); } /** diff --git a/src/Console/PostUpdate.php b/src/Console/PostUpdate.php index fb640a0b0e..f6a7f69d22 100644 --- a/src/Console/PostUpdate.php +++ b/src/Console/PostUpdate.php @@ -57,7 +57,7 @@ HELP; protected function doExecute() { - $a = \Friendica\BaseObject::getApp(); + $a = \Friendica\DI::app(); if ($this->getOption($this->helpOptions)) { $this->out($this->getHelp()); diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 3617470df4..037ea901af 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -19,6 +19,7 @@ use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Core\Renderer; use Friendica\Core\System; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Event; use Friendica\Model\Photo; @@ -1093,7 +1094,7 @@ class BBCode extends BaseObject $text = Cache::get($cache_key); if (is_null($text)) { - $a = self::getApp(); + $a = DI::app(); $stamp1 = microtime(true); @@ -1149,7 +1150,7 @@ class BBCode extends BaseObject private static function cleanPictureLinksCallback($match) { - $a = self::getApp(); + $a = DI::app(); // When the picture link is the own photo path then we can avoid fetching the link $own_photo_url = preg_quote(Strings::normaliseLink($a->getBaseURL()) . '/photos/'); @@ -1253,7 +1254,7 @@ class BBCode extends BaseObject */ public static function convert($text, $try_oembed = true, $simple_html = 0, $for_plaintext = false) { - $a = self::getApp(); + $a = DI::app(); /* * preg_match_callback function to replace potential Oembed tags with Oembed content @@ -2010,7 +2011,7 @@ class BBCode extends BaseObject */ public static function toMarkdown($text, $for_diaspora = true) { - $a = self::getApp(); + $a = DI::app(); $original_text = $text; diff --git a/src/Content/Text/Markdown.php b/src/Content/Text/Markdown.php index a715de7e97..cca64b0ab2 100644 --- a/src/Content/Text/Markdown.php +++ b/src/Content/Text/Markdown.php @@ -8,6 +8,7 @@ namespace Friendica\Content\Text; use Friendica\BaseObject; use Friendica\Core\System; +use Friendica\DI; use Friendica\Model\Contact; /** @@ -43,7 +44,7 @@ class Markdown extends BaseObject $html = $MarkdownParser->transform($text); - self::getApp()->getProfiler()->saveTimestamp($stamp1, "parser", System::callstack()); + DI::app()->getProfiler()->saveTimestamp($stamp1, "parser", System::callstack()); return $html; } diff --git a/src/Core/ACL.php b/src/Core/ACL.php index 64e03d4719..6134828658 100644 --- a/src/Core/ACL.php +++ b/src/Core/ACL.php @@ -9,6 +9,7 @@ namespace Friendica\Core; use Friendica\App\Page; use Friendica\BaseObject; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Group; @@ -35,7 +36,7 @@ class ACL extends BaseObject */ public static function getSuggestContactSelectHTML($selname, $selclass, array $options = [], array $preselected = []) { - $a = self::getApp(); + $a = DI::app(); $networks = null; @@ -145,7 +146,7 @@ class ACL extends BaseObject */ public static function getMessageContactSelectHTML($selname, $selclass, array $preselected = [], $size = 4, $tabindex = null) { - $a = self::getApp(); + $a = DI::app(); $o = ''; diff --git a/src/Core/Addon.php b/src/Core/Addon.php index 2ec46b71c1..b1c1ad2e60 100644 --- a/src/Core/Addon.php +++ b/src/Core/Addon.php @@ -7,6 +7,7 @@ namespace Friendica\Core; use Friendica\BaseObject; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Util\Strings; /** @@ -177,7 +178,7 @@ class Addon extends BaseObject @include_once('addon/' . $addon . '/' . $addon . '.php'); if (function_exists($addon . '_install')) { $func = $addon . '_install'; - $func(self::getApp()); + $func(DI::app()); $addon_admin = (function_exists($addon . "_addon_admin") ? 1 : 0); @@ -234,11 +235,11 @@ class Addon extends BaseObject if (function_exists($addon . '_uninstall')) { $func = $addon . '_uninstall'; - $func(self::getApp()); + $func(DI::app()); } if (function_exists($addon . '_install')) { $func = $addon . '_install'; - $func(self::getApp()); + $func(DI::app()); } DBA::update('addon', ['timestamp' => $t], ['id' => $i['id']]); } @@ -267,7 +268,7 @@ class Addon extends BaseObject */ public static function getInfo($addon) { - $a = self::getApp(); + $a = DI::app(); $addon = Strings::sanitizeFilePathItem($addon); diff --git a/src/Core/Hook.php b/src/Core/Hook.php index 5caa543194..959ed9fa16 100644 --- a/src/Core/Hook.php +++ b/src/Core/Hook.php @@ -7,6 +7,7 @@ namespace Friendica\Core; use Friendica\App; use Friendica\BaseObject; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Util\Strings; /** @@ -75,7 +76,7 @@ class Hook extends BaseObject */ public static function register($hook, $file, $function, $priority = 0) { - $file = str_replace(self::getApp()->getBasePath() . DIRECTORY_SEPARATOR, '', $file); + $file = str_replace(DI::app()->getBasePath() . DIRECTORY_SEPARATOR, '', $file); $condition = ['hook' => $hook, 'file' => $file, 'function' => $function]; if (DBA::exists('hook', $condition)) { @@ -98,7 +99,7 @@ class Hook extends BaseObject */ public static function unregister($hook, $file, $function) { - $relative_file = str_replace(self::getApp()->getBasePath() . DIRECTORY_SEPARATOR, '', $file); + $relative_file = str_replace(DI::app()->getBasePath() . DIRECTORY_SEPARATOR, '', $file); // This here is only needed for fixing a problem that existed on the develop branch $condition = ['hook' => $hook, 'file' => $file, 'function' => $function]; @@ -148,7 +149,7 @@ class Hook extends BaseObject if ($hook[0] != $fork_hook[0]) { continue; } - self::callSingle(self::getApp(), 'hook_fork', $fork_hook, $hookdata); + self::callSingle(DI::app(), 'hook_fork', $fork_hook, $hookdata); } if (!$hookdata['execute']) { @@ -175,7 +176,7 @@ class Hook extends BaseObject { if (array_key_exists($name, self::$hooks)) { foreach (self::$hooks[$name] as $hook) { - self::callSingle(self::getApp(), $name, $hook, $data); + self::callSingle(DI::app(), $name, $hook, $data); } } } diff --git a/src/Core/Renderer.php b/src/Core/Renderer.php index d9d913050f..ce90d78dee 100644 --- a/src/Core/Renderer.php +++ b/src/Core/Renderer.php @@ -7,6 +7,7 @@ namespace Friendica\Core; use Exception; use Friendica\BaseObject; +use Friendica\DI; use Friendica\Render\FriendicaSmarty; use Friendica\Render\ITemplateEngine; @@ -61,7 +62,7 @@ class Renderer extends BaseObject public static function replaceMacros($s, array $vars = []) { $stamp1 = microtime(true); - $a = self::getApp(); + $a = DI::app(); // pass $baseurl to all templates if it isn't set $vars = array_merge(['$baseurl' => $a->getBaseURL()], $vars); @@ -92,7 +93,7 @@ class Renderer extends BaseObject public static function getMarkupTemplate($s, $root = '') { $stamp1 = microtime(true); - $a = self::getApp(); + $a = DI::app(); $t = self::getTemplateEngine(); try { diff --git a/src/Core/Search.php b/src/Core/Search.php index e43e621d29..ff1a8a317c 100644 --- a/src/Core/Search.php +++ b/src/Core/Search.php @@ -4,6 +4,7 @@ namespace Friendica\Core; use Friendica\BaseObject; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\GContact; use Friendica\Network\HTTPException; @@ -92,7 +93,7 @@ class Search extends BaseObject */ public static function getContactsFromGlobalDirectory($search, $type = self::TYPE_ALL, $page = 1) { - $config = self::getApp()->getConfig(); + $config = DI::app()->getConfig(); $server = $config->get('system', 'directory', self::DEFAULT_DIRECTORY); $searchUrl = $server . '/search'; @@ -158,7 +159,7 @@ class Search extends BaseObject */ public static function getContactsFromLocalDirectory($search, $type = self::TYPE_ALL, $start = 0, $itemPage = 80) { - $config = self::getApp()->getConfig(); + $config = DI::app()->getConfig(); $diaspora = $config->get('system', 'diaspora_enabled') ? Protocol::DIASPORA : Protocol::DFRN; $ostatus = !$config->get('system', 'ostatus_disabled') ? Protocol::OSTATUS : Protocol::DFRN; diff --git a/src/Core/System.php b/src/Core/System.php index 7aba0653e1..cf6fd9b4a9 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -6,6 +6,7 @@ namespace Friendica\Core; use Friendica\App\BaseURL; use Friendica\BaseObject; +use Friendica\DI; use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Util\XML; @@ -43,7 +44,7 @@ class System extends BaseObject */ public static function removedBaseUrl(string $orig_url) { - return self::getApp()->removeBaseURL($orig_url); + return DI::app()->removeBaseURL($orig_url); } /** @@ -184,7 +185,7 @@ class System extends BaseObject if (is_bool($prefix) && !$prefix) { $prefix = ''; } elseif (empty($prefix)) { - $prefix = hash('crc32', self::getApp()->getHostName()); + $prefix = hash('crc32', DI::app()->getHostName()); } while (strlen($prefix) < ($size - 13)) { diff --git a/src/Core/Theme.php b/src/Core/Theme.php index 4f870687ce..7df985df35 100644 --- a/src/Core/Theme.php +++ b/src/Core/Theme.php @@ -7,6 +7,7 @@ namespace Friendica\Core; use Friendica\BaseObject; +use Friendica\DI; use Friendica\Model\Profile; use Friendica\Util\Strings; @@ -194,7 +195,7 @@ class Theme */ public static function getPathForFile($file) { - $a = BaseObject::getApp(); + $a = DI::app(); $theme = $a->getCurrentTheme(); @@ -232,7 +233,7 @@ class Theme return 'view/theme/' . $theme . '/style.css'; } - $a = BaseObject::getApp(); + $a = DI::app(); $query_params = []; diff --git a/src/Core/Worker.php b/src/Core/Worker.php index c64b0ebc6b..b9362dace5 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -7,6 +7,7 @@ namespace Friendica\Core; use Friendica\BaseObject; use Friendica\Core; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Process; use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; @@ -1232,11 +1233,11 @@ class Worker */ public static function defer() { - if (empty(BaseObject::getApp()->queue)) { + if (empty(DI::app()->queue)) { return false; } - $queue = BaseObject::getApp()->queue; + $queue = DI::app()->queue; $retrial = $queue['retrial']; $id = $queue['id']; diff --git a/src/DI.php b/src/DI.php new file mode 100644 index 0000000000..ef05b5cb07 --- /dev/null +++ b/src/DI.php @@ -0,0 +1,33 @@ +create(App::class, $arguments); + default: + return null; + } + } +} diff --git a/src/LegacyModule.php b/src/LegacyModule.php index 950f8faad2..9c22ec5d78 100644 --- a/src/LegacyModule.php +++ b/src/LegacyModule.php @@ -67,7 +67,7 @@ class LegacyModule extends BaseModule $function_name = static::$moduleName . '_' . $function_suffix; if (\function_exists($function_name)) { - $a = self::getApp(); + $a = DI::app(); return $function_name($a); } else { return parent::{$function_suffix}($parameters); diff --git a/src/Model/Attach.php b/src/Model/Attach.php index 0073a6ed3f..fce55f5106 100644 --- a/src/Model/Attach.php +++ b/src/Model/Attach.php @@ -11,6 +11,7 @@ use Friendica\Core\StorageManager; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\Database\DBStructure; +use Friendica\DI; use Friendica\Model\Storage\IStorage; use Friendica\Object\Image; use Friendica\Util\DateTimeFormat; @@ -31,7 +32,7 @@ class Attach extends BaseObject */ private static function getFields() { - $allfields = DBStructure::definition(self::getApp()->getBasePath(), false); + $allfields = DBStructure::definition(DI::app()->getBasePath(), false); $fields = array_keys($allfields['attach']['fields']); array_splice($fields, array_search('data', $fields), 1); return $fields; diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 1fd8426acd..c4f05b2dc9 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -16,6 +16,7 @@ use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Network\Probe; use Friendica\Object\Image; use Friendica\Protocol\Activity; @@ -1733,7 +1734,7 @@ class Contact extends BaseObject */ public static function getPostsFromUrl($contact_url, $thread_mode = false, $update = 0) { - $a = self::getApp(); + $a = DI::app(); $cid = self::getIdForURL($contact_url); diff --git a/src/Model/Item.php b/src/Model/Item.php index ebee91ffc2..9a86097ae8 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -21,6 +21,7 @@ use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Protocol\Activity; use Friendica\Protocol\ActivityPub; use Friendica\Protocol\Diaspora; @@ -2513,7 +2514,7 @@ class Item extends BaseObject $guid = System::createUUID(); } - return self::getApp()->getBaseURL() . '/objects/' . $guid; + return DI::app()->getBaseURL() . '/objects/' . $guid; } /** @@ -3474,7 +3475,7 @@ class Item extends BaseObject */ private static function addRedirToImageTags(array &$item) { - $app = self::getApp(); + $app = DI::app(); $matches = []; $cnt = preg_match_all('|\[img\](http[^\[]*?/photo/[a-fA-F0-9]+?(-[0-9]\.[\w]+?)?)\[\/img\]|', $item['body'], $matches, PREG_SET_ORDER); @@ -3509,7 +3510,7 @@ class Item extends BaseObject */ public static function prepareBody(array &$item, $attach = false, $is_preview = false) { - $a = self::getApp(); + $a = DI::app(); Hook::callAll('prepare_body_init', $item); // In order to provide theme developers more possibilities, event items @@ -3647,7 +3648,7 @@ class Item extends BaseObject */ public static function getPlink($item) { - $a = self::getApp(); + $a = DI::app(); if ($a->user['nickname'] != "") { $ret = [ diff --git a/src/Model/Nodeinfo.php b/src/Model/Nodeinfo.php index 60eba2713a..f6deb31bd5 100644 --- a/src/Model/Nodeinfo.php +++ b/src/Model/Nodeinfo.php @@ -5,6 +5,7 @@ namespace Friendica\Model; use Friendica\BaseObject; use Friendica\Core\Addon; use Friendica\Database\DBA; +use Friendica\DI; /** * Model interaction for the nodeinfo @@ -18,7 +19,7 @@ class Nodeinfo extends BaseObject */ public static function update() { - $app = self::getApp(); + $app = DI::app(); $config = $app->getConfig(); $logger = $app->getLogger(); diff --git a/src/Model/Notify.php b/src/Model/Notify.php index eef481ad8f..842f9509cd 100644 --- a/src/Model/Notify.php +++ b/src/Model/Notify.php @@ -12,6 +12,7 @@ use Friendica\Core\L10n\L10n; use Friendica\Core\Protocol; use Friendica\Core\System; use Friendica\Database\Database; +use Friendica\DI; use Friendica\Protocol\Activity; use Friendica\Util\DateTimeFormat; use Friendica\Util\Proxy as ProxyUtils; @@ -515,7 +516,7 @@ final class Notify extends BaseObject $ident = self::PERSONAL; $notifies = []; - $myurl = str_replace('http://', '', self::getApp()->contact['nurl']); + $myurl = str_replace('http://', '', DI::app()->contact['nurl']); $diasp_url = str_replace('/profile/', '/u/', $myurl); $condition = ["NOT `wall` AND `uid` = ? AND (`item`.`author-id` = ? OR `item`.`tag` REGEXP ? OR `item`.`tag` REGEXP ?)", @@ -669,7 +670,7 @@ final class Notify extends BaseObject // We have to distinguish between these two because they use different data. // Contact suggestions if ($intro['fid']) { - $return_addr = bin2hex(self::getApp()->user['nickname'] . '@' . + $return_addr = bin2hex(DI::app()->user['nickname'] . '@' . $this->baseUrl->getHostName() . (($this->baseUrl->getURLPath()) ? '/' . $this->baseUrl->getURLPath() : '')); diff --git a/src/Model/Photo.php b/src/Model/Photo.php index db3c4d429b..445e8a5e5c 100644 --- a/src/Model/Photo.php +++ b/src/Model/Photo.php @@ -15,6 +15,7 @@ use Friendica\Core\StorageManager; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\Database\DBStructure; +use Friendica\DI; use Friendica\Model\Storage\IStorage; use Friendica\Object\Image; use Friendica\Util\DateTimeFormat; @@ -202,7 +203,7 @@ class Photo extends BaseObject */ private static function getFields() { - $allfields = DBStructure::definition(self::getApp()->getBasePath(), false); + $allfields = DBStructure::definition(DI::app()->getBasePath(), false); $fields = array_keys($allfields["photo"]["fields"]); array_splice($fields, array_search("data", $fields), 1); return $fields; diff --git a/src/Module/Admin/Addons/Details.php b/src/Module/Admin/Addons/Details.php index a196e7834f..b7c9b68c28 100644 --- a/src/Module/Admin/Addons/Details.php +++ b/src/Module/Admin/Addons/Details.php @@ -6,6 +6,7 @@ use Friendica\Content\Text\Markdown; use Friendica\Core\Addon; use Friendica\Core\L10n; use Friendica\Core\Renderer; +use Friendica\DI; use Friendica\Module\BaseAdminModule; use Friendica\Util\Strings; @@ -15,7 +16,7 @@ class Details extends BaseAdminModule { parent::post($parameters); - $a = self::getApp(); + $a = DI::app(); if ($a->argc > 2) { // @TODO: Replace with parameter from router @@ -39,7 +40,7 @@ class Details extends BaseAdminModule { parent::content($parameters); - $a = self::getApp(); + $a = DI::app(); $addons_admin = Addon::getAdminList(); diff --git a/src/Module/Admin/Addons/Index.php b/src/Module/Admin/Addons/Index.php index f327f0dc92..237eb73255 100644 --- a/src/Module/Admin/Addons/Index.php +++ b/src/Module/Admin/Addons/Index.php @@ -5,6 +5,7 @@ namespace Friendica\Module\Admin\Addons; use Friendica\Core\Addon; use Friendica\Core\L10n; use Friendica\Core\Renderer; +use Friendica\DI; use Friendica\Module\BaseAdminModule; class Index extends BaseAdminModule @@ -13,7 +14,7 @@ class Index extends BaseAdminModule { parent::content($parameters); - $a = self::getApp(); + $a = DI::app(); // reload active themes if (!empty($_GET['action'])) { diff --git a/src/Module/Admin/Blocklist/Contact.php b/src/Module/Admin/Blocklist/Contact.php index 38ae233715..e21c0ed959 100644 --- a/src/Module/Admin/Blocklist/Contact.php +++ b/src/Module/Admin/Blocklist/Contact.php @@ -6,6 +6,7 @@ use Friendica\Content\Pager; use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Module\BaseAdminModule; use Friendica\Model; @@ -38,14 +39,14 @@ class Contact extends BaseAdminModule notice(L10n::tt('%s contact unblocked', '%s contacts unblocked', count($contacts))); } - self::getApp()->internalRedirect('admin/blocklist/contact'); + DI::app()->internalRedirect('admin/blocklist/contact'); } public static function content(array $parameters = []) { parent::content($parameters); - $a = self::getApp(); + $a = DI::app(); $condition = ['uid' => 0, 'blocked' => true]; diff --git a/src/Module/Admin/Blocklist/Server.php b/src/Module/Admin/Blocklist/Server.php index 53647e64ef..5b84e40653 100644 --- a/src/Module/Admin/Blocklist/Server.php +++ b/src/Module/Admin/Blocklist/Server.php @@ -5,6 +5,7 @@ namespace Friendica\Module\Admin\Blocklist; use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\Renderer; +use Friendica\DI; use Friendica\Module\BaseAdminModule; use Friendica\Util\Strings; @@ -47,14 +48,14 @@ class Server extends BaseAdminModule info(L10n::t('Site blocklist updated.') . EOL); } - self::getApp()->internalRedirect('admin/blocklist/server'); + DI::app()->internalRedirect('admin/blocklist/server'); } public static function content(array $parameters = []) { parent::content($parameters); - $a = self::getApp(); + $a = DI::app(); $blocklist = Config::get('system', 'blocklist'); $blocklistform = []; diff --git a/src/Module/Admin/DBSync.php b/src/Module/Admin/DBSync.php index 0d68a56481..7aeba4e1b1 100644 --- a/src/Module/Admin/DBSync.php +++ b/src/Module/Admin/DBSync.php @@ -8,6 +8,7 @@ use Friendica\Core\Renderer; use Friendica\Core\Update; use Friendica\Database\DBA; use Friendica\Database\DBStructure; +use Friendica\DI; use Friendica\Module\BaseAdminModule; class DBSync extends BaseAdminModule @@ -16,7 +17,7 @@ class DBSync extends BaseAdminModule { parent::content($parameters); - $a = self::getApp(); + $a = DI::app(); $o = ''; diff --git a/src/Module/Admin/Features.php b/src/Module/Admin/Features.php index 85683d238f..c9a5a9813d 100644 --- a/src/Module/Admin/Features.php +++ b/src/Module/Admin/Features.php @@ -6,6 +6,7 @@ use Friendica\Content\Feature; use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\Renderer; +use Friendica\DI; use Friendica\Module\BaseAdminModule; class Features extends BaseAdminModule @@ -39,7 +40,7 @@ class Features extends BaseAdminModule } } - self::getApp()->internalRedirect('admin/features'); + DI::app()->internalRedirect('admin/features'); } public static function content(array $parameters = []) diff --git a/src/Module/Admin/Item/Delete.php b/src/Module/Admin/Item/Delete.php index f5f4687cec..77849a9aa9 100644 --- a/src/Module/Admin/Item/Delete.php +++ b/src/Module/Admin/Item/Delete.php @@ -4,6 +4,7 @@ namespace Friendica\Module\Admin\Item; use Friendica\Core\L10n; use Friendica\Core\Renderer; +use Friendica\DI; use Friendica\Model\Item; use Friendica\Module\BaseAdminModule; use Friendica\Util\Strings; @@ -33,7 +34,7 @@ class Delete extends BaseAdminModule } info(L10n::t('Item marked for deletion.') . EOL); - self::getApp()->internalRedirect('admin/item/delete'); + DI::app()->internalRedirect('admin/item/delete'); } public static function content(array $parameters = []) diff --git a/src/Module/Admin/Item/Source.php b/src/Module/Admin/Item/Source.php index 9c41e60f47..610f61aec3 100644 --- a/src/Module/Admin/Item/Source.php +++ b/src/Module/Admin/Item/Source.php @@ -4,6 +4,7 @@ namespace Friendica\Module\Admin\Item; use Friendica\Core\L10n; use Friendica\Core\Renderer; +use Friendica\DI; use Friendica\Model; use Friendica\Module\BaseAdminModule; @@ -17,7 +18,7 @@ class Source extends BaseAdminModule { parent::content($parameters); - $a = self::getApp(); + $a = DI::app(); $guid = null; // @TODO: Replace with parameter from router diff --git a/src/Module/Admin/Logs/Settings.php b/src/Module/Admin/Logs/Settings.php index 42f3435f65..0617c1c217 100644 --- a/src/Module/Admin/Logs/Settings.php +++ b/src/Module/Admin/Logs/Settings.php @@ -5,6 +5,7 @@ namespace Friendica\Module\Admin\Logs; use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\Renderer; +use Friendica\DI; use Friendica\Module\BaseAdminModule; use Friendica\Util\Strings; use Psr\Log\LogLevel; @@ -34,14 +35,14 @@ class Settings extends BaseAdminModule } info(L10n::t("Log settings updated.")); - self::getApp()->internalRedirect('admin/logs'); + DI::app()->internalRedirect('admin/logs'); } public static function content(array $parameters = []) { parent::content($parameters); - $a = self::getApp(); + $a = DI::app(); $log_choices = [ LogLevel::ERROR => 'Error', diff --git a/src/Module/Admin/Queue.php b/src/Module/Admin/Queue.php index 9ce44ff15a..d538f396eb 100644 --- a/src/Module/Admin/Queue.php +++ b/src/Module/Admin/Queue.php @@ -5,6 +5,7 @@ namespace Friendica\Module\Admin; use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Module\BaseAdminModule; use Friendica\Util\Arrays; use Friendica\Util\DateTimeFormat; @@ -23,7 +24,7 @@ class Queue extends BaseAdminModule { parent::content($parameters); - $a = self::getApp(); + $a = DI::app(); // @TODO: Replace with parameter from router $deferred = $a->argc > 2 && $a->argv[2] == 'deferred'; diff --git a/src/Module/Admin/Site.php b/src/Module/Admin/Site.php index 4a02e98b82..abf9d95edb 100644 --- a/src/Module/Admin/Site.php +++ b/src/Module/Admin/Site.php @@ -10,6 +10,7 @@ use Friendica\Core\StorageManager; use Friendica\Core\Theme; use Friendica\Core\Worker; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Module\BaseAdminModule; use Friendica\Module\Register; use Friendica\Protocol\PortableContact; @@ -27,7 +28,7 @@ class Site extends BaseAdminModule self::checkFormSecurityTokenRedirectOnError('/admin/site', 'admin_site'); - $a = self::getApp(); + $a = DI::app(); if (!empty($_POST['republish_directory'])) { Worker::add(PRIORITY_LOW, 'Directory'); @@ -416,7 +417,7 @@ class Site extends BaseAdminModule { parent::content($parameters); - $a = self::getApp(); + $a = DI::app(); /* Installed langs */ $lang_choices = L10n::getAvailableLanguages(); diff --git a/src/Module/Admin/Summary.php b/src/Module/Admin/Summary.php index e10533ee94..4011fec1c7 100644 --- a/src/Module/Admin/Summary.php +++ b/src/Module/Admin/Summary.php @@ -10,6 +10,7 @@ use Friendica\Core\Renderer; use Friendica\Core\Update; use Friendica\Database\DBA; use Friendica\Database\DBStructure; +use Friendica\DI; use Friendica\Model\Register; use Friendica\Module\BaseAdminModule; use Friendica\Network\HTTPException\InternalServerErrorException; @@ -24,7 +25,7 @@ class Summary extends BaseAdminModule { parent::content($parameters); - $a = self::getApp(); + $a = DI::app(); // are there MyISAM tables in the DB? If so, trigger a warning message $warningtext = []; @@ -208,7 +209,7 @@ class Summary extends BaseAdminModule private static function checkSelfHostMeta() { // Fetch the host-meta to check if this really is a vital server - return Network::curl(self::getApp()->getBaseURL() . '/.well-known/host-meta')->isSuccess(); + return Network::curl(DI::app()->getBaseURL() . '/.well-known/host-meta')->isSuccess(); } } diff --git a/src/Module/Admin/Themes/Details.php b/src/Module/Admin/Themes/Details.php index 912adc4297..0e9fa08f52 100644 --- a/src/Module/Admin/Themes/Details.php +++ b/src/Module/Admin/Themes/Details.php @@ -6,6 +6,7 @@ use Friendica\Content\Text\Markdown; use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Core\Theme; +use Friendica\DI; use Friendica\Module\BaseAdminModule; use Friendica\Util\Strings; @@ -15,7 +16,7 @@ class Details extends BaseAdminModule { parent::post($parameters); - $a = self::getApp(); + $a = DI::app(); if ($a->argc > 2) { // @TODO: Replace with parameter from router @@ -43,7 +44,7 @@ class Details extends BaseAdminModule { parent::content($parameters); - $a = self::getApp(); + $a = DI::app(); if ($a->argc > 2) { // @TODO: Replace with parameter from router diff --git a/src/Module/Admin/Themes/Embed.php b/src/Module/Admin/Themes/Embed.php index 70a12dadd2..8a7b5c19ea 100644 --- a/src/Module/Admin/Themes/Embed.php +++ b/src/Module/Admin/Themes/Embed.php @@ -4,6 +4,7 @@ namespace Friendica\Module\Admin\Themes; use Friendica\Core\L10n; use Friendica\Core\Renderer; +use Friendica\DI; use Friendica\Module\BaseAdminModule; use Friendica\Util\Strings; @@ -11,7 +12,7 @@ class Embed extends BaseAdminModule { public static function init(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); if ($a->argc > 2) { // @TODO: Replace with parameter from router @@ -27,7 +28,7 @@ class Embed extends BaseAdminModule { parent::post($parameters); - $a = self::getApp(); + $a = DI::app(); if ($a->argc > 2) { // @TODO: Replace with parameter from router @@ -57,7 +58,7 @@ class Embed extends BaseAdminModule { parent::content($parameters); - $a = self::getApp(); + $a = DI::app(); if ($a->argc > 2) { // @TODO: Replace with parameter from router diff --git a/src/Module/Admin/Themes/Index.php b/src/Module/Admin/Themes/Index.php index 8f7843e293..db6c4bc60b 100644 --- a/src/Module/Admin/Themes/Index.php +++ b/src/Module/Admin/Themes/Index.php @@ -6,6 +6,7 @@ use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Core\Theme; +use Friendica\DI; use Friendica\Module\BaseAdminModule; use Friendica\Util\Strings; @@ -15,7 +16,7 @@ class Index extends BaseAdminModule { parent::content($parameters); - $a = self::getApp(); + $a = DI::app(); $allowed_themes = Theme::getAllowedList(); diff --git a/src/Module/Admin/Tos.php b/src/Module/Admin/Tos.php index 6fbdc21e8f..5c7d592253 100644 --- a/src/Module/Admin/Tos.php +++ b/src/Module/Admin/Tos.php @@ -5,6 +5,7 @@ namespace Friendica\Module\Admin; use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\Renderer; +use Friendica\DI; use Friendica\Module\BaseAdminModule; class Tos extends BaseAdminModule @@ -29,7 +30,7 @@ class Tos extends BaseAdminModule info(L10n::t('The Terms of Service settings have been updated.')); - self::getApp()->internalRedirect('admin/tos'); + DI::app()->internalRedirect('admin/tos'); } public static function content(array $parameters = []) diff --git a/src/Module/Admin/Users.php b/src/Module/Admin/Users.php index 84332c979f..e6162ae858 100644 --- a/src/Module/Admin/Users.php +++ b/src/Module/Admin/Users.php @@ -7,6 +7,7 @@ use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Register; use Friendica\Model\User; use Friendica\Module\BaseAdminModule; @@ -19,7 +20,7 @@ class Users extends BaseAdminModule { parent::post($parameters); - $a = self::getApp(); + $a = DI::app(); $pending = $_POST['pending'] ?? []; $users = $_POST['user'] ?? []; @@ -135,7 +136,7 @@ class Users extends BaseAdminModule { parent::content($parameters); - $a = self::getApp(); + $a = DI::app(); if ($a->argc > 3) { // @TODO: Replace with parameter from router diff --git a/src/Module/AllFriends.php b/src/Module/AllFriends.php index 0d9bf59858..2699990736 100644 --- a/src/Module/AllFriends.php +++ b/src/Module/AllFriends.php @@ -7,6 +7,7 @@ use Friendica\Content\ContactSelector; use Friendica\Content\Pager; use Friendica\Core\L10n; use Friendica\Core\Renderer; +use Friendica\DI; use Friendica\Model; use Friendica\Network\HTTPException; use Friendica\Util\Proxy as ProxyUtils; @@ -18,7 +19,7 @@ class AllFriends extends BaseModule { public static function content(array $parameters = []) { - $app = self::getApp(); + $app = DI::app(); if (!local_user()) { throw new HTTPException\ForbiddenException(); diff --git a/src/Module/Apps.php b/src/Module/Apps.php index bc099ce8bb..be0b60f6e1 100644 --- a/src/Module/Apps.php +++ b/src/Module/Apps.php @@ -7,6 +7,7 @@ use Friendica\Content\Nav; use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\Renderer; +use Friendica\DI; /** * Shows the App menu @@ -17,7 +18,7 @@ class Apps extends BaseModule { $privateaddons = Config::get('config', 'private_addons'); if ($privateaddons === "1" && !local_user()) { - self::getApp()->internalRedirect(); + DI::app()->internalRedirect(); } } diff --git a/src/Module/Attach.php b/src/Module/Attach.php index f67104015d..fab1be2d58 100644 --- a/src/Module/Attach.php +++ b/src/Module/Attach.php @@ -10,6 +10,7 @@ use Friendica\BaseModule; use Friendica\Core\L10n; use Friendica\Core\Logger; use Friendica\Core\System; +use Friendica\DI; use Friendica\Model\Attach as MAttach; /** @@ -22,7 +23,7 @@ class Attach extends BaseModule */ public static function rawContent(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); if ($a->argc != 2) { throw new \Friendica\Network\HTTPException\BadRequestException(); } diff --git a/src/Module/Base/Api.php b/src/Module/Base/Api.php index 08cf96158d..3a4e100897 100644 --- a/src/Module/Base/Api.php +++ b/src/Module/Base/Api.php @@ -5,6 +5,7 @@ namespace Friendica\Module\Base; use Friendica\App\Arguments; use Friendica\BaseModule; use Friendica\Core\L10n; +use Friendica\DI; use Friendica\Network\HTTPException; require_once __DIR__ . '/../../../include/api.php'; @@ -41,7 +42,7 @@ class Api extends BaseModule throw new HTTPException\UnauthorizedException(L10n::t('Permission denied.')); } - $a = self::getApp(); + $a = DI::app(); if (!empty($a->user['uid']) && $a->user['uid'] != api_user()) { throw new HTTPException\ForbiddenException(L10n::t('Permission denied.')); @@ -67,7 +68,7 @@ class Api extends BaseModule */ protected static function login() { - api_login(self::getApp()); + api_login(DI::app()); self::$current_user_id = api_user(); @@ -86,7 +87,7 @@ class Api extends BaseModule */ protected static function getUser($contact_id = null) { - return api_get_user(self::getApp(), $contact_id); + return api_get_user(DI::app(), $contact_id); } protected static function format($root_element, $data) diff --git a/src/Module/BaseAdminModule.php b/src/Module/BaseAdminModule.php index 01aa00d423..08db0a98c4 100644 --- a/src/Module/BaseAdminModule.php +++ b/src/Module/BaseAdminModule.php @@ -7,6 +7,7 @@ use Friendica\Core\Addon; use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Core\Session; +use Friendica\DI; use Friendica\Network\HTTPException\ForbiddenException; require_once 'boot.php'; @@ -50,7 +51,7 @@ abstract class BaseAdminModule extends BaseModule public static function content(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); if (!is_site_admin()) { notice(L10n::t('Please login to continue.')); diff --git a/src/Module/BaseSearchModule.php b/src/Module/BaseSearchModule.php index 96692b0b2d..7c6760a8d1 100644 --- a/src/Module/BaseSearchModule.php +++ b/src/Module/BaseSearchModule.php @@ -9,6 +9,7 @@ use Friendica\Content\Pager; use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Core\Search; +use Friendica\DI; use Friendica\Model; use Friendica\Network\HTTPException; use Friendica\Object\Search\ContactResult; @@ -33,7 +34,7 @@ class BaseSearchModule extends BaseModule */ public static function performContactSearch($search, $prefix = '') { - $a = self::getApp(); + $a = DI::app(); $config = $a->getConfig(); $type = Search::TYPE_ALL; @@ -97,7 +98,7 @@ class BaseSearchModule extends BaseModule return ''; } - $a = self::getApp(); + $a = DI::app(); $id = 0; $entries = []; diff --git a/src/Module/BaseSettingsModule.php b/src/Module/BaseSettingsModule.php index 4900de42e6..244dcdf17d 100644 --- a/src/Module/BaseSettingsModule.php +++ b/src/Module/BaseSettingsModule.php @@ -6,12 +6,13 @@ use Friendica\BaseModule; use Friendica\Content\Feature; use Friendica\Core\L10n; use Friendica\Core\Renderer; +use Friendica\DI; class BaseSettingsModule extends BaseModule { public static function content(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); $tpl = Renderer::getMarkupTemplate('settings/head.tpl'); $a->page['htmlhead'] .= Renderer::replaceMacros($tpl, [ diff --git a/src/Module/Bookmarklet.php b/src/Module/Bookmarklet.php index 2993c20a7b..bae0e7c4d4 100644 --- a/src/Module/Bookmarklet.php +++ b/src/Module/Bookmarklet.php @@ -5,6 +5,7 @@ namespace Friendica\Module; use Friendica\BaseModule; use Friendica\Core\ACL; use Friendica\Core\L10n; +use Friendica\DI; use Friendica\Module\Security\Login; use Friendica\Network\HTTPException; use Friendica\Util\Strings; @@ -19,7 +20,7 @@ class Bookmarklet extends BaseModule { $_GET['mode'] = 'minimal'; - $app = self::getApp(); + $app = DI::app(); $config = $app->getConfig(); if (!local_user()) { diff --git a/src/Module/Contact.php b/src/Module/Contact.php index 82b7e4b992..d366eaf0bd 100644 --- a/src/Module/Contact.php +++ b/src/Module/Contact.php @@ -17,6 +17,7 @@ use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model; use Friendica\Module\Security\Login; use Friendica\Network\HTTPException\BadRequestException; @@ -78,7 +79,7 @@ class Contact extends BaseModule public static function post(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); if (!local_user()) { return; @@ -247,7 +248,7 @@ class Contact extends BaseModule return Login::form($_SERVER['REQUEST_URI']); } - $a = self::getApp(); + $a = DI::app(); $nets = $_GET['nets'] ?? ''; $rel = $_GET['rel'] ?? ''; diff --git a/src/Module/Debug/Feed.php b/src/Module/Debug/Feed.php index c764c90003..48601d6bb3 100644 --- a/src/Module/Debug/Feed.php +++ b/src/Module/Debug/Feed.php @@ -5,6 +5,7 @@ namespace Friendica\Module\Debug; use Friendica\BaseModule; use Friendica\Core\L10n; use Friendica\Core\Renderer; +use Friendica\DI; use Friendica\Model; use Friendica\Protocol; use Friendica\Util\Network; @@ -18,7 +19,7 @@ class Feed extends BaseModule { if (!local_user()) { info(L10n::t('You must be logged in to use this module')); - self::getApp()->internalRedirect(); + DI::app()->internalRedirect(); } } diff --git a/src/Module/Debug/ItemBody.php b/src/Module/Debug/ItemBody.php index f166fb0a27..8212ce38b5 100644 --- a/src/Module/Debug/ItemBody.php +++ b/src/Module/Debug/ItemBody.php @@ -4,6 +4,7 @@ namespace Friendica\Module\Debug; use Friendica\BaseModule; use Friendica\Core\L10n; +use Friendica\DI; use Friendica\Model\Item; use Friendica\Network\HTTPException; @@ -18,7 +19,7 @@ class ItemBody extends BaseModule throw new HTTPException\UnauthorizedException(L10n::t('Access denied.')); } - $app = self::getApp(); + $app = DI::app(); // @TODO: Replace with parameter from router $itemId = (($app->argc > 1) ? intval($app->argv[1]) : 0); diff --git a/src/Module/Debug/Localtime.php b/src/Module/Debug/Localtime.php index 0d78f08d79..b762abdbc5 100644 --- a/src/Module/Debug/Localtime.php +++ b/src/Module/Debug/Localtime.php @@ -5,6 +5,7 @@ namespace Friendica\Module\Debug; use Friendica\BaseModule; use Friendica\Core\Installer; use Friendica\Core\L10n; +use Friendica\DI; use Friendica\Util\DateTimeFormat; use Friendica\Util\Temporal; @@ -17,13 +18,13 @@ class Localtime extends BaseModule $bd_format = L10n::t('l F d, Y \@ g:i A'); if (!empty($_POST['timezone'])) { - self::getApp()->data['mod-localtime'] = DateTimeFormat::convert($time, $_POST['timezone'], 'UTC', $bd_format); + DI::app()->data['mod-localtime'] = DateTimeFormat::convert($time, $_POST['timezone'], 'UTC', $bd_format); } } public static function content(array $parameters = []) { - $app = self::getApp(); + $app = DI::app(); $time = ($_REQUEST['time'] ?? '') ?: 'now'; diff --git a/src/Module/Delegation.php b/src/Module/Delegation.php index 7d2e686725..a255ad3841 100644 --- a/src/Module/Delegation.php +++ b/src/Module/Delegation.php @@ -9,6 +9,7 @@ use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Core\Session; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\User; use Friendica\Network\HTTPException\ForbiddenException; @@ -25,7 +26,7 @@ class Delegation extends BaseModule } $uid = local_user(); - $orig_record = self::getApp()->user; + $orig_record = DI::app()->user; if (Session::get('submanage')) { $user = User::getById(Session::get('submanage')); @@ -82,7 +83,7 @@ class Delegation extends BaseModule /** @var Authentication $authentication */ $authentication = self::getClass(Authentication::class); - $authentication->setForUser(self::getApp(), $user, true, true); + $authentication->setForUser(DI::app(), $user, true, true); if ($limited_id) { Session::set('submanage', $original_id); @@ -91,7 +92,7 @@ class Delegation extends BaseModule $ret = []; Hook::callAll('home_init', $ret); - self::getApp()->internalRedirect('profile/' . self::getApp()->user['nickname']); + DI::app()->internalRedirect('profile/' . DI::app()->user['nickname']); // NOTREACHED } @@ -101,7 +102,7 @@ class Delegation extends BaseModule throw new ForbiddenException(L10n::t('Permission denied.')); } - $identities = self::getApp()->identities; + $identities = DI::app()->identities; //getting additinal information for each identity foreach ($identities as $key => $identity) { @@ -112,7 +113,7 @@ class Delegation extends BaseModule $identities[$key]['thumb'] = $thumb['thumb']; - $identities[$key]['selected'] = ($identity['nickname'] === self::getApp()->user['nickname']); + $identities[$key]['selected'] = ($identity['nickname'] === DI::app()->user['nickname']); $condition = ["`uid` = ? AND `msg` != '' AND NOT (`type` IN (?, ?)) AND NOT `seen`", $identity['uid'], NOTIFY_INTRO, NOTIFY_MAIL]; $params = ['distinct' => true, 'expression' => 'parent']; diff --git a/src/Module/Diaspora/Fetch.php b/src/Module/Diaspora/Fetch.php index 0efe641ba6..9ed8fb109e 100644 --- a/src/Module/Diaspora/Fetch.php +++ b/src/Module/Diaspora/Fetch.php @@ -5,6 +5,7 @@ namespace Friendica\Module\Diaspora; use Friendica\BaseModule; use Friendica\Core\Protocol; use Friendica\Core\System; +use Friendica\DI; use Friendica\Model\Item; use Friendica\Model\User; use Friendica\Network\HTTPException; @@ -19,7 +20,7 @@ class Fetch extends BaseModule { public static function rawContent(array $parameters = []) { - $app = self::getApp(); + $app = DI::app(); // @TODO: Replace with parameter from router if (($app->argc != 3) || (!in_array($app->argv[1], ["post", "status_message", "reshare"]))) { diff --git a/src/Module/Directory.php b/src/Module/Directory.php index f24c066507..e38810e8ec 100644 --- a/src/Module/Directory.php +++ b/src/Module/Directory.php @@ -10,6 +10,7 @@ use Friendica\Core\Hook; use Friendica\Core\L10n; use Friendica\Core\Session; use Friendica\Core\Renderer; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Profile; use Friendica\Network\HTTPException; @@ -23,7 +24,7 @@ class Directory extends BaseModule { public static function content(array $parameters = []) { - $app = self::getApp(); + $app = DI::app(); $config = $app->getConfig(); if (($config->get('system', 'block_public') && !Session::isAuthenticated()) || diff --git a/src/Module/Feed.php b/src/Module/Feed.php index ba21537627..58140d835b 100644 --- a/src/Module/Feed.php +++ b/src/Module/Feed.php @@ -3,6 +3,7 @@ namespace Friendica\Module; use Friendica\BaseModule; +use Friendica\DI; use Friendica\Protocol\OStatus; /** @@ -25,7 +26,7 @@ class Feed extends BaseModule { public static function content(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); $last_update = $_GET['last_update'] ?? ''; $nocache = !empty($_GET['nocache']) && local_user(); diff --git a/src/Module/Filer/RemoveTag.php b/src/Module/Filer/RemoveTag.php index 0246f1db36..65fd6cdf36 100644 --- a/src/Module/Filer/RemoveTag.php +++ b/src/Module/Filer/RemoveTag.php @@ -3,6 +3,7 @@ namespace Friendica\Module\Filer; use Friendica\BaseModule; +use Friendica\DI; use Friendica\Model\FileTag; use Friendica\Network\HTTPException; use Friendica\Util\XML; @@ -18,7 +19,7 @@ class RemoveTag extends BaseModule throw new HTTPException\ForbiddenException(); } - $app = self::getApp(); + $app = DI::app(); $logger = $app->getLogger(); $item_id = (($app->argc > 1) ? intval($app->argv[1]) : 0); diff --git a/src/Module/Filer/SaveTag.php b/src/Module/Filer/SaveTag.php index 7f0da83bce..1e19cdff19 100644 --- a/src/Module/Filer/SaveTag.php +++ b/src/Module/Filer/SaveTag.php @@ -6,6 +6,7 @@ use Friendica\BaseModule; use Friendica\Core\L10n; use Friendica\Core\PConfig; use Friendica\Core\Renderer; +use Friendica\DI; use Friendica\Model; use Friendica\Util\XML; @@ -18,13 +19,13 @@ class SaveTag extends BaseModule { if (!local_user()) { info(L10n::t('You must be logged in to use this module')); - self::getApp()->internalRedirect(); + DI::app()->internalRedirect(); } } public static function rawContent(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); $logger = $a->getLogger(); $term = XML::unescape(trim($_GET['term'] ?? '')); diff --git a/src/Module/FollowConfirm.php b/src/Module/FollowConfirm.php index 5e9ab0481c..a19f127376 100644 --- a/src/Module/FollowConfirm.php +++ b/src/Module/FollowConfirm.php @@ -4,6 +4,7 @@ namespace Friendica\Module; use Friendica\BaseModule; use Friendica\Core\L10n; use Friendica\Model\Introduction; +use Friendica\DI; /** * Process follow request confirmations @@ -12,7 +13,7 @@ class FollowConfirm extends BaseModule { public static function post(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); $uid = local_user(); if (!$uid) { diff --git a/src/Module/Followers.php b/src/Module/Followers.php index c2096cd052..0907f8ba5c 100644 --- a/src/Module/Followers.php +++ b/src/Module/Followers.php @@ -6,6 +6,7 @@ namespace Friendica\Module; use Friendica\BaseModule; use Friendica\Core\System; +use Friendica\DI; use Friendica\Model\User; use Friendica\Protocol\ActivityPub; @@ -16,7 +17,7 @@ class Followers extends BaseModule { public static function rawContent(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); // @TODO: Replace with parameter from router if (empty($a->argv[1])) { diff --git a/src/Module/Following.php b/src/Module/Following.php index 8eaa1835c2..739971df99 100644 --- a/src/Module/Following.php +++ b/src/Module/Following.php @@ -6,6 +6,7 @@ namespace Friendica\Module; use Friendica\BaseModule; use Friendica\Core\System; +use Friendica\DI; use Friendica\Model\User; use Friendica\Protocol\ActivityPub; @@ -16,7 +17,7 @@ class Following extends BaseModule { public static function rawContent(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); // @TODO: Replace with parameter from router if (empty($a->argv[1])) { diff --git a/src/Module/Friendica.php b/src/Module/Friendica.php index ee8b220611..2eb2940ed3 100644 --- a/src/Module/Friendica.php +++ b/src/Module/Friendica.php @@ -7,6 +7,7 @@ use Friendica\Core\Addon; use Friendica\Core\Hook; use Friendica\Core\L10n; use Friendica\Core\Renderer; +use Friendica\DI; use Friendica\Model\User; /** @@ -17,7 +18,7 @@ class Friendica extends BaseModule { public static function content(array $parameters = []) { - $app = self::getApp(); + $app = DI::app(); $config = $app->getConfig(); $visibleAddonList = Addon::getVisibleList(); @@ -90,7 +91,7 @@ class Friendica extends BaseModule public static function rawContent(array $parameters = []) { - $app = self::getApp(); + $app = DI::app(); // @TODO: Replace with parameter from router if ($app->argc <= 1 || ($app->argv[1] !== 'json')) { diff --git a/src/Module/Group.php b/src/Module/Group.php index 5699d2d30b..e7e1978986 100644 --- a/src/Module/Group.php +++ b/src/Module/Group.php @@ -12,6 +12,7 @@ use Friendica\Core\PConfig; use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model; use Friendica\Util\Strings; @@ -21,7 +22,7 @@ class Group extends BaseModule { public static function post(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); if ($a->isAjax()) { self::ajaxPost(); @@ -71,7 +72,7 @@ class Group extends BaseModule public static function ajaxPost() { try { - $a = self::getApp(); + $a = DI::app(); if (!local_user()) { throw new \Exception(L10n::t('Permission denied.'), 403); @@ -134,7 +135,7 @@ class Group extends BaseModule throw new \Friendica\Network\HTTPException\ForbiddenException(); } - $a = self::getApp(); + $a = DI::app(); $a->page['aside'] = Model\Group::sidebarWidget('contact', 'group', 'extended', (($a->argc > 1) ? $a->argv[1] : 'everyone')); diff --git a/src/Module/Help.php b/src/Module/Help.php index 58cc95affd..0ff4cc68b0 100644 --- a/src/Module/Help.php +++ b/src/Module/Help.php @@ -6,6 +6,7 @@ use Friendica\BaseModule; use Friendica\Content\Nav; use Friendica\Content\Text\Markdown; use Friendica\Core\L10n; +use Friendica\DI; use Friendica\Network\HTTPException; use Friendica\Util\Strings; @@ -21,7 +22,7 @@ class Help extends BaseModule $text = ''; $filename = ''; - $a = self::getApp(); + $a = DI::app(); $config = $a->getConfig(); $lang = $config->get('system', 'language'); diff --git a/src/Module/Home.php b/src/Module/Home.php index 8fdb613f9b..eb122b0527 100644 --- a/src/Module/Home.php +++ b/src/Module/Home.php @@ -6,6 +6,7 @@ use Friendica\BaseModule; use Friendica\Core\Hook; use Friendica\Core\L10n; use Friendica\Core\Renderer; +use Friendica\DI; use Friendica\Module\Security\Login; /** @@ -15,7 +16,7 @@ class Home extends BaseModule { public static function content(array $parameters = []) { - $app = self::getApp(); + $app = DI::app(); $config = $app->getConfig(); // currently no returned data is used diff --git a/src/Module/Inbox.php b/src/Module/Inbox.php index 8ab169567e..d6a33606df 100644 --- a/src/Module/Inbox.php +++ b/src/Module/Inbox.php @@ -10,6 +10,7 @@ use Friendica\Core\Config; use Friendica\Core\Logger; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Protocol\ActivityPub; use Friendica\Util\HTTPSignature; use Friendica\Util\Network; @@ -21,7 +22,7 @@ class Inbox extends BaseModule { public static function rawContent(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); $postdata = Network::postdata(); diff --git a/src/Module/Install.php b/src/Module/Install.php index 71547ad51e..107f83e77d 100644 --- a/src/Module/Install.php +++ b/src/Module/Install.php @@ -8,6 +8,7 @@ use Friendica\Core; use Friendica\Core\Config\Cache\ConfigCache; use Friendica\Core\L10n; use Friendica\Core\Renderer; +use Friendica\DI; use Friendica\Network\HTTPException; use Friendica\Util\BasePath; use Friendica\Util\Strings; @@ -48,7 +49,7 @@ class Install extends BaseModule public static function init(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); if (!$a->getMode()->isInstall()) { throw new HTTPException\ForbiddenException(); @@ -78,7 +79,7 @@ class Install extends BaseModule public static function post(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); $configCache = $a->getConfigCache(); switch (self::$currentWizardStep) { @@ -151,7 +152,7 @@ class Install extends BaseModule public static function content(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); $configCache = $a->getConfigCache(); $output = ''; diff --git a/src/Module/Invite.php b/src/Module/Invite.php index cd616001be..9261ea703c 100644 --- a/src/Module/Invite.php +++ b/src/Module/Invite.php @@ -6,6 +6,7 @@ use Friendica\BaseModule; use Friendica\Core\L10n; use Friendica\Core\PConfig; use Friendica\Core\Renderer; +use Friendica\DI; use Friendica\Model; use Friendica\Network\HTTPException; use Friendica\Protocol\Email; @@ -24,7 +25,7 @@ class Invite extends BaseModule self::checkFormSecurityTokenRedirectOnError('/', 'send_invite'); - $app = self::getApp(); + $app = DI::app(); $config = $app->getConfig(); $max_invites = intval($config->get('system', 'max_invites')); @@ -110,7 +111,7 @@ class Invite extends BaseModule throw new HTTPException\ForbiddenException(L10n::t('Permission denied.')); } - $app = self::getApp(); + $app = DI::app(); $config = $app->getConfig(); $inviteOnly = false; diff --git a/src/Module/Item/Compose.php b/src/Module/Item/Compose.php index ded41fe392..78c4710a36 100644 --- a/src/Module/Item/Compose.php +++ b/src/Module/Item/Compose.php @@ -12,6 +12,7 @@ use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\Core\Theme; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\FileTag; use Friendica\Model\Group; @@ -29,7 +30,7 @@ class Compose extends BaseModule if (!empty($_REQUEST['body'])) { $_REQUEST['return'] = 'network'; require_once 'mod/item.php'; - item_post(self::getApp()); + item_post(DI::app()); } else { notice(L10n::t('Please enter a post body.')); } @@ -41,7 +42,7 @@ class Compose extends BaseModule return Login::form('compose', false); } - $a = self::getApp(); + $a = DI::app(); if ($a->getCurrentTheme() !== 'frio') { throw new NotImplementedException(L10n::t('This feature is only available with the frio theme.')); diff --git a/src/Module/Item/Ignore.php b/src/Module/Item/Ignore.php index e67f2113cd..75b2a7bd35 100644 --- a/src/Module/Item/Ignore.php +++ b/src/Module/Item/Ignore.php @@ -8,6 +8,7 @@ use Friendica\Core\L10n\L10n; use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Database\Database; +use Friendica\DI; use Friendica\Model\Item; use Friendica\Network\HTTPException; @@ -69,7 +70,7 @@ class Ignore extends BaseModule $rand = "?$rand"; } - self::getApp()->internalRedirect($return_path . $rand); + DI::app()->internalRedirect($return_path . $rand); } // the json doesn't really matter, it will either be 0 or 1 diff --git a/src/Module/Like.php b/src/Module/Like.php index 1c98cbc38c..74a0b8d859 100644 --- a/src/Module/Like.php +++ b/src/Module/Like.php @@ -3,6 +3,7 @@ namespace Friendica\Module; use Friendica\BaseModule; +use Friendica\DI; use Friendica\Model\Item; use Friendica\Core\Session; use Friendica\Network\HTTPException; @@ -25,7 +26,7 @@ class Like extends BaseModule $verb = 'like'; } - $app = self::getApp(); + $app = DI::app(); // @TODO: Replace with parameter from router $itemId = (($app->argc > 1) ? Strings::escapeTags(trim($app->argv[1])) : 0); diff --git a/src/Module/Magic.php b/src/Module/Magic.php index 0f610d123c..d34f7e8744 100644 --- a/src/Module/Magic.php +++ b/src/Module/Magic.php @@ -8,6 +8,7 @@ use Friendica\BaseModule; use Friendica\Core\Logger; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Util\HTTPSignature; use Friendica\Util\Network; @@ -22,7 +23,7 @@ class Magic extends BaseModule { public static function init(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); $ret = ['success' => false, 'url' => '', 'message' => '']; Logger::log('magic mdule: invoked', Logger::DEBUG); @@ -48,7 +49,7 @@ class Magic extends BaseModule $contact = DBA::selectFirst('contact', ['id', 'nurl', 'url'], ['id' => $cid]); // Redirect if the contact is already authenticated on this site. - if (!empty($a->contact) && array_key_exists('id', $a->contact) && strpos($contact['nurl'], Strings::normaliseLink(self::getApp()->getBaseURL())) !== false) { + if (!empty($a->contact) && array_key_exists('id', $a->contact) && strpos($contact['nurl'], Strings::normaliseLink(DI::app()->getBaseURL())) !== false) { if ($test) { $ret['success'] = true; $ret['message'] .= 'Local site - you are already authenticated.' . EOL; diff --git a/src/Module/Maintenance.php b/src/Module/Maintenance.php index 056bde7325..35a6df6295 100644 --- a/src/Module/Maintenance.php +++ b/src/Module/Maintenance.php @@ -5,6 +5,7 @@ namespace Friendica\Module; use Friendica\BaseModule; use Friendica\Core\L10n; use Friendica\Core\System; +use Friendica\DI; use Friendica\Network\HTTPException; use Friendica\Util\Strings; @@ -16,7 +17,7 @@ class Maintenance extends BaseModule { public static function content(array $parameters = []) { - $config = self::getApp()->getConfig(); + $config = DI::app()->getConfig(); $reason = $config->get('system', 'maintenance_reason'); diff --git a/src/Module/Manifest.php b/src/Module/Manifest.php index 9e09740594..de1dfc9150 100644 --- a/src/Module/Manifest.php +++ b/src/Module/Manifest.php @@ -4,12 +4,13 @@ namespace Friendica\Module; use Friendica\BaseModule; use Friendica\Core\Renderer; +use Friendica\DI; class Manifest extends BaseModule { public static function rawContent(array $parameters = []) { - $app = self::getApp(); + $app = DI::app(); $config = $app->getConfig(); $tpl = Renderer::getMarkupTemplate('manifest.tpl'); diff --git a/src/Module/NodeInfo.php b/src/Module/NodeInfo.php index 8e3692e3d3..5c5b573b22 100644 --- a/src/Module/NodeInfo.php +++ b/src/Module/NodeInfo.php @@ -6,6 +6,7 @@ use Friendica\App; use Friendica\BaseModule; use Friendica\Core\Addon; use Friendica\Core\System; +use Friendica\DI; /** * Standardized way of exposing metadata about a server running one of the distributed social networks. @@ -15,7 +16,7 @@ class NodeInfo extends BaseModule { public static function rawContent(array $parameters = []) { - $app = self::getApp(); + $app = DI::app(); if ($parameters['version'] == '1.0') { self::printNodeInfo1($app); diff --git a/src/Module/Notifications/Notify.php b/src/Module/Notifications/Notify.php index 721a89a694..d95d9c0d8e 100644 --- a/src/Module/Notifications/Notify.php +++ b/src/Module/Notifications/Notify.php @@ -6,6 +6,7 @@ use Friendica\BaseModule; use Friendica\BaseObject; use Friendica\Core\L10n; use Friendica\Core\System; +use Friendica\DI; use Friendica\Model\Notify as ModelNotify; use Friendica\Network\HTTPException; @@ -23,7 +24,7 @@ class Notify extends BaseModule public static function rawContent(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); // @TODO: Replace with parameter from router if ($a->argc > 2 && $a->argv[1] === 'mark' && $a->argv[2] === 'all') { @@ -47,7 +48,7 @@ class Notify extends BaseModule */ public static function content(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); // @TODO: Replace with parameter from router if ($a->argc > 2 && $a->argv[1] === 'view' && intval($a->argv[2])) { diff --git a/src/Module/Objects.php b/src/Module/Objects.php index df57636926..4817811a34 100644 --- a/src/Module/Objects.php +++ b/src/Module/Objects.php @@ -7,6 +7,7 @@ namespace Friendica\Module; use Friendica\BaseModule; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Item; use Friendica\Protocol\ActivityPub; @@ -17,7 +18,7 @@ class Objects extends BaseModule { public static function rawContent(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); if (empty($a->argv[1])) { throw new \Friendica\Network\HTTPException\NotFoundException(); diff --git a/src/Module/Oembed.php b/src/Module/Oembed.php index f9d9284281..38e209e84d 100644 --- a/src/Module/Oembed.php +++ b/src/Module/Oembed.php @@ -4,6 +4,7 @@ namespace Friendica\Module; use Friendica\BaseModule; use Friendica\Content; +use Friendica\DI; use Friendica\Util\Strings; /** @@ -19,7 +20,7 @@ class Oembed extends BaseModule { public static function content(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); // Unused form: /oembed/b2h?url=... if ($a->argv[1] == 'b2h') { diff --git a/src/Module/OpenSearch.php b/src/Module/OpenSearch.php index 309db6af95..acab0f5ed4 100644 --- a/src/Module/OpenSearch.php +++ b/src/Module/OpenSearch.php @@ -5,6 +5,7 @@ namespace Friendica\Module; use DOMDocument; use DOMElement; use Friendica\BaseModule; +use Friendica\DI; use Friendica\Util\XML; /** @@ -20,8 +21,8 @@ class OpenSearch extends BaseModule { header('Content-type: application/opensearchdescription+xml'); - $hostname = self::getApp()->getHostName(); - $baseUrl = self::getApp()->getBaseURL(); + $hostname = DI::app()->getHostName(); + $baseUrl = DI::app()->getBaseURL(); /** @var DOMDocument $xml */ $xml = null; diff --git a/src/Module/Outbox.php b/src/Module/Outbox.php index c2024151e5..ee667cc4da 100644 --- a/src/Module/Outbox.php +++ b/src/Module/Outbox.php @@ -6,6 +6,7 @@ namespace Friendica\Module; use Friendica\BaseModule; use Friendica\Core\System; +use Friendica\DI; use Friendica\Model\User; use Friendica\Protocol\ActivityPub; @@ -16,7 +17,7 @@ class Outbox extends BaseModule { public static function rawContent(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); // @TODO: Replace with parameter from router if (empty($a->argv[1])) { diff --git a/src/Module/Photo.php b/src/Module/Photo.php index 9987c38f51..0c2baeac40 100644 --- a/src/Module/Photo.php +++ b/src/Module/Photo.php @@ -9,6 +9,7 @@ use Friendica\BaseModule; use Friendica\Core\L10n; use Friendica\Core\Logger; use Friendica\Core\System; +use Friendica\DI; use Friendica\Model\Photo as MPhoto; use Friendica\Object\Image; @@ -25,7 +26,7 @@ class Photo extends BaseModule */ public static function init(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); // @TODO: Replace with parameter from router if ($a->argc <= 1 || $a->argc > 4) { throw new \Friendica\Network\HTTPException\BadRequestException(); diff --git a/src/Module/Pinned.php b/src/Module/Pinned.php index e4c0d2b0e7..1bd25f2722 100644 --- a/src/Module/Pinned.php +++ b/src/Module/Pinned.php @@ -3,6 +3,7 @@ namespace Friendica\Module; use Friendica\BaseModule; +use Friendica\DI; use Friendica\Model\Item; /** @@ -30,7 +31,7 @@ class Pinned extends BaseModule $returnPath = $_REQUEST['return'] ?? ''; if (!empty($returnPath)) { $rand = '_=' . time() . (strpos($returnPath, '?') ? '&' : '?') . 'rand'; - self::getApp()->internalRedirect($returnPath . $rand); + DI::app()->internalRedirect($returnPath . $rand); } // the json doesn't really matter, it will either be 0 or 1 diff --git a/src/Module/Profile.php b/src/Module/Profile.php index d399ba8ddf..eb8becfff5 100644 --- a/src/Module/Profile.php +++ b/src/Module/Profile.php @@ -14,6 +14,7 @@ use Friendica\Core\PConfig; use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Contact as ContactModel; use Friendica\Model\Group; use Friendica\Model\Item; @@ -36,7 +37,7 @@ class Profile extends BaseModule public static function init(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); // @TODO: Replace with parameter from router if ($a->argc < 2) { @@ -78,7 +79,7 @@ class Profile extends BaseModule public static function content(array $parameters = [], $update = 0) { - $a = self::getApp(); + $a = DI::app(); if (!$update) { ProfileModel::load($a, self::$which, self::$profile); diff --git a/src/Module/Profile/Contacts.php b/src/Module/Profile/Contacts.php index 9a96590ac3..9d26f1bbef 100644 --- a/src/Module/Profile/Contacts.php +++ b/src/Module/Profile/Contacts.php @@ -12,6 +12,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\Profile; use Friendica\Util\Proxy as ProxyUtils; @@ -24,7 +25,7 @@ class Contacts extends BaseModule throw new \Friendica\Network\HTTPException\NotFoundException(L10n::t('User not found.')); } - $a = self::getApp(); + $a = DI::app(); //@TODO: Get value from router parameters $nickname = $a->argv[1]; diff --git a/src/Module/Proxy.php b/src/Module/Proxy.php index fbf4b8bd5c..ed7cabfefb 100644 --- a/src/Module/Proxy.php +++ b/src/Module/Proxy.php @@ -9,6 +9,7 @@ use Friendica\BaseModule; use Friendica\Core\L10n; use Friendica\Core\System; use Friendica\Core\Logger; +use Friendica\DI; use Friendica\Model\Photo; use Friendica\Object\Image; use Friendica\Util\HTTPSignature; @@ -33,7 +34,7 @@ class Proxy extends BaseModule public static function init(array $parameters = []) { // Set application instance here - $a = self::getApp(); + $a = DI::app(); /* * Pictures are stored in one of the following ways: @@ -156,7 +157,7 @@ class Proxy extends BaseModule */ private static function getRequestInfo() { - $a = self::getApp(); + $a = DI::app(); $size = 1024; $sizetype = ''; @@ -230,7 +231,7 @@ class Proxy extends BaseModule */ private static function setupDirectCache() { - $a = self::getApp(); + $a = DI::app(); $basepath = $a->getBasePath(); // If the cache path isn't there, try to create it diff --git a/src/Module/PublicRSAKey.php b/src/Module/PublicRSAKey.php index f652811b54..5e90d90725 100644 --- a/src/Module/PublicRSAKey.php +++ b/src/Module/PublicRSAKey.php @@ -4,6 +4,7 @@ namespace Friendica\Module; use ASN_BASE; use Friendica\BaseModule; +use Friendica\DI; use Friendica\Model\User; use Friendica\Network\HTTPException\BadRequestException; @@ -14,7 +15,7 @@ class PublicRSAKey extends BaseModule { public static function rawContent(array $parameters = []) { - $app = self::getApp(); + $app = DI::app(); // @TODO: Replace with parameter from router if ($app->argc !== 2) { diff --git a/src/Module/RandomProfile.php b/src/Module/RandomProfile.php index c5b31afeef..f595ae98ed 100644 --- a/src/Module/RandomProfile.php +++ b/src/Module/RandomProfile.php @@ -3,6 +3,7 @@ namespace Friendica\Module; use Friendica\BaseModule; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\GContact; @@ -13,7 +14,7 @@ class RandomProfile extends BaseModule { public static function content(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); $contactUrl = GContact::getRandomUrl(); diff --git a/src/Module/ReallySimpleDiscovery.php b/src/Module/ReallySimpleDiscovery.php index 7cf0db6c7b..43fdcf102c 100644 --- a/src/Module/ReallySimpleDiscovery.php +++ b/src/Module/ReallySimpleDiscovery.php @@ -3,6 +3,7 @@ namespace Friendica\Module; use Friendica\BaseModule; +use Friendica\DI; use Friendica\Util\XML; /** @@ -15,7 +16,7 @@ class ReallySimpleDiscovery extends BaseModule { header('Content-Type: text/xml'); - $app = self::getApp(); + $app = DI::app(); $xml = null; echo XML::fromArray([ 'rsd' => [ diff --git a/src/Module/Register.php b/src/Module/Register.php index 3b43970197..df7a028166 100644 --- a/src/Module/Register.php +++ b/src/Module/Register.php @@ -14,6 +14,7 @@ use Friendica\Core\PConfig; use Friendica\Core\Renderer; use Friendica\Core\Worker; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model; use Friendica\Util\Strings; @@ -123,7 +124,7 @@ class Register extends BaseModule '$ask_password' => $ask_password, '$password1' => ['password1', L10n::t('New Password:'), '', L10n::t('Leave empty for an auto generated password.')], '$password2' => ['confirm', L10n::t('Confirm:'), '', ''], - '$nickdesc' => L10n::t('Choose a profile nickname. This must begin with a text character. Your profile address on this site will then be "nickname@%s".', self::getApp()->getHostName()), + '$nickdesc' => L10n::t('Choose a profile nickname. This must begin with a text character. Your profile address on this site will then be "nickname@%s".', DI::app()->getHostName()), '$nicklabel' => L10n::t('Choose a nickname: '), '$photo' => $photo, '$publish' => $profile_publish, @@ -131,7 +132,7 @@ class Register extends BaseModule '$username' => $username, '$email' => $email, '$nickname' => $nickname, - '$sitename' => self::getApp()->getHostName(), + '$sitename' => DI::app()->getHostName(), '$importh' => L10n::t('Import'), '$importt' => L10n::t('Import your profile to this friendica instance'), '$showtoslink' => Config::get('system', 'tosdisplay'), @@ -156,7 +157,7 @@ class Register extends BaseModule { BaseModule::checkFormSecurityTokenRedirectOnError('/register', 'register'); - $a = self::getApp(); + $a = DI::app(); $arr = ['post' => $_POST]; Hook::callAll('register_post', $arr); diff --git a/src/Module/Search/Directory.php b/src/Module/Search/Directory.php index f9988c0049..df73437c6e 100644 --- a/src/Module/Search/Directory.php +++ b/src/Module/Search/Directory.php @@ -4,6 +4,7 @@ namespace Friendica\Module\Search; use Friendica\Content\Widget; use Friendica\Core\L10n; +use Friendica\DI; use Friendica\Module\BaseSearchModule; use Friendica\Module\Security\Login; use Friendica\Util\Strings; @@ -22,7 +23,7 @@ class Directory extends BaseSearchModule $search = Strings::escapeTags(trim(rawurldecode($_REQUEST['search'] ?? ''))); - $a = self::getApp(); + $a = DI::app(); if (empty($a->page['aside'])) { $a->page['aside'] = ''; diff --git a/src/Module/Search/Index.php b/src/Module/Search/Index.php index 23b134b455..4e8a4c63c5 100644 --- a/src/Module/Search/Index.php +++ b/src/Module/Search/Index.php @@ -16,6 +16,7 @@ use Friendica\Core\Logger; use Friendica\Core\Renderer; use Friendica\Core\Session; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Item; use Friendica\Model\Term; @@ -68,7 +69,7 @@ class Index extends BaseSearchModule } if (local_user()) { - self::getApp()->page['aside'] .= Widget\SavedSearches::getHTML('search?q=' . urlencode($search), $search); + DI::app()->page['aside'] .= Widget\SavedSearches::getHTML('search?q=' . urlencode($search), $search); } Nav::setSelected('search'); @@ -190,7 +191,7 @@ class Index extends BaseSearchModule Logger::info('Start Conversation.', ['q' => $search]); - $o .= conversation(self::getApp(), $r, $pager, 'search', false, false, 'commented', local_user()); + $o .= conversation(DI::app(), $r, $pager, 'search', false, false, 'commented', local_user()); $o .= $pager->renderMinimal(count($r)); diff --git a/src/Module/Search/Saved.php b/src/Module/Search/Saved.php index 88668272de..80f84a927c 100644 --- a/src/Module/Search/Saved.php +++ b/src/Module/Search/Saved.php @@ -6,6 +6,7 @@ use Friendica\App\Arguments; use Friendica\BaseModule; use Friendica\Core\L10n; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Util\Strings; class Saved extends BaseModule @@ -39,6 +40,6 @@ class Saved extends BaseModule } } - self::getApp()->internalRedirect($return_url); + DI::app()->internalRedirect($return_url); } } diff --git a/src/Module/Security/Login.php b/src/Module/Security/Login.php index 311cbdd9bb..5de46903db 100644 --- a/src/Module/Security/Login.php +++ b/src/Module/Security/Login.php @@ -13,6 +13,7 @@ use Friendica\Core\Hook; use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Core\Session; +use Friendica\DI; use Friendica\Module\Register; use Friendica\Util\Strings; @@ -25,7 +26,7 @@ class Login extends BaseModule { public static function content(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); if (local_user()) { $a->internalRedirect(); @@ -57,7 +58,7 @@ class Login extends BaseModule /** @var Authentication $authentication */ $authentication = self::getClass(Authentication::class); $authentication->withPassword( - self::getApp(), + DI::app(), trim($_POST['username']), trim($_POST['password']), !empty($_POST['remember']) @@ -81,7 +82,7 @@ class Login extends BaseModule */ public static function form($return_path = null, $register = false, $hiddens = []) { - $a = self::getApp(); + $a = DI::app(); $o = ''; $noid = Config::get('system', 'no_openid'); @@ -133,7 +134,7 @@ class Login extends BaseModule $o .= Renderer::replaceMacros( $tpl, [ - '$dest_url' => self::getApp()->getBaseURL(true) . '/login', + '$dest_url' => DI::app()->getBaseURL(true) . '/login', '$logout' => L10n::t('Logout'), '$login' => L10n::t('Login'), diff --git a/src/Module/Security/Logout.php b/src/Module/Security/Logout.php index 062d55687b..c0a0761087 100644 --- a/src/Module/Security/Logout.php +++ b/src/Module/Security/Logout.php @@ -12,6 +12,7 @@ use Friendica\Core\Hook; use Friendica\Core\L10n; use Friendica\Core\Session; use Friendica\Core\System; +use Friendica\DI; use Friendica\Model\Profile; /** @@ -39,7 +40,7 @@ class Logout extends BaseModule System::externalRedirect($visitor_home); } else { info(L10n::t('Logged out.')); - self::getApp()->internalRedirect(); + DI::app()->internalRedirect(); } } } diff --git a/src/Module/Security/TwoFactor/Recovery.php b/src/Module/Security/TwoFactor/Recovery.php index 90e1488ed9..b0f88fcfb7 100644 --- a/src/Module/Security/TwoFactor/Recovery.php +++ b/src/Module/Security/TwoFactor/Recovery.php @@ -7,6 +7,7 @@ use Friendica\App\Authentication; use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Core\Session; +use Friendica\DI; use Friendica\Model\TwoFactor\RecoveryCode; /** @@ -32,7 +33,7 @@ class Recovery extends BaseModule if (($_POST['action'] ?? '') == 'recover') { self::checkFormSecurityTokenRedirectOnError('2fa', 'twofactor_recovery'); - $a = self::getApp(); + $a = DI::app(); $recovery_code = $_POST['recovery_code'] ?? ''; @@ -54,12 +55,12 @@ class Recovery extends BaseModule public static function content(array $parameters = []) { if (!local_user()) { - self::getApp()->internalRedirect(); + DI::app()->internalRedirect(); } // Already authenticated with 2FA token if (Session::get('2fa')) { - self::getApp()->internalRedirect(); + DI::app()->internalRedirect(); } return Renderer::replaceMacros(Renderer::getMarkupTemplate('twofactor/recovery.tpl'), [ diff --git a/src/Module/Security/TwoFactor/Verify.php b/src/Module/Security/TwoFactor/Verify.php index 10327aea59..08545b061e 100644 --- a/src/Module/Security/TwoFactor/Verify.php +++ b/src/Module/Security/TwoFactor/Verify.php @@ -8,6 +8,7 @@ use Friendica\Core\L10n; use Friendica\Core\PConfig; use Friendica\Core\Renderer; use Friendica\Core\Session; +use Friendica\DI; use PragmaRX\Google2FA\Google2FA; /** @@ -28,7 +29,7 @@ class Verify extends BaseModule if (($_POST['action'] ?? '') == 'verify') { self::checkFormSecurityTokenRedirectOnError('2fa', 'twofactor_verify'); - $a = self::getApp(); + $a = DI::app(); $code = $_POST['verify_code'] ?? ''; @@ -51,12 +52,12 @@ class Verify extends BaseModule public static function content(array $parameters = []) { if (!local_user()) { - self::getApp()->internalRedirect(); + DI::app()->internalRedirect(); } // Already authenticated with 2FA token if (Session::get('2fa')) { - self::getApp()->internalRedirect(); + DI::app()->internalRedirect(); } return Renderer::replaceMacros(Renderer::getMarkupTemplate('twofactor/verify.tpl'), [ diff --git a/src/Module/Settings/Delegation.php b/src/Module/Settings/Delegation.php index e3c2b8d34c..78730c3d63 100644 --- a/src/Module/Settings/Delegation.php +++ b/src/Module/Settings/Delegation.php @@ -10,6 +10,7 @@ use Friendica\Core\Renderer; use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\User; use Friendica\Module\BaseSettingsModule; use Friendica\Network\HTTPException; @@ -22,7 +23,7 @@ class Delegation extends BaseSettingsModule { public static function post(array $parameters = []) { - if (!local_user() || !empty(self::getApp()->user['uid']) && self::getApp()->user['uid'] != local_user()) { + if (!local_user() || !empty(DI::app()->user['uid']) && DI::app()->user['uid'] != local_user()) { throw new HTTPException\ForbiddenException(L10n::t('Permission denied.')); } @@ -64,7 +65,7 @@ class Delegation extends BaseSettingsModule if ($action === 'add' && $user_id) { if (Session::get('submanage')) { notice(L10n::t('Delegated administrators can view but not change delegation permissions.')); - self::getApp()->internalRedirect('settings/delegation'); + DI::app()->internalRedirect('settings/delegation'); } $user = User::getById($user_id, ['nickname']); @@ -80,17 +81,17 @@ class Delegation extends BaseSettingsModule notice(L10n::t('Delegate user not found.')); } - self::getApp()->internalRedirect('settings/delegation'); + DI::app()->internalRedirect('settings/delegation'); } if ($action === 'remove' && $user_id) { if (Session::get('submanage')) { notice(L10n::t('Delegated administrators can view but not change delegation permissions.')); - self::getApp()->internalRedirect('settings/delegation'); + DI::app()->internalRedirect('settings/delegation'); } DBA::delete('manage', ['uid' => $user_id, 'mid' => local_user()]); - self::getApp()->internalRedirect('settings/delegation'); + DI::app()->internalRedirect('settings/delegation'); } // find everybody that currently has delegated management to this account/page diff --git a/src/Module/Settings/TwoFactor/AppSpecific.php b/src/Module/Settings/TwoFactor/AppSpecific.php index fe7423c5d2..1823b56f0d 100644 --- a/src/Module/Settings/TwoFactor/AppSpecific.php +++ b/src/Module/Settings/TwoFactor/AppSpecific.php @@ -7,6 +7,7 @@ namespace Friendica\Module\Settings\TwoFactor; use Friendica\Core\L10n; use Friendica\Core\PConfig; use Friendica\Core\Renderer; +use Friendica\DI; use Friendica\Model\TwoFactor\AppSpecificPassword; use Friendica\Module\BaseSettingsModule; use Friendica\Module\Security\Login; @@ -29,12 +30,12 @@ class AppSpecific extends BaseSettingsModule $verified = PConfig::get(local_user(), '2fa', 'verified'); if (!$verified) { - self::getApp()->internalRedirect('settings/2fa'); + DI::app()->internalRedirect('settings/2fa'); } if (!self::checkFormSecurityToken('settings_2fa_password', 't')) { notice(L10n::t('Please enter your password to access this page.')); - self::getApp()->internalRedirect('settings/2fa'); + DI::app()->internalRedirect('settings/2fa'); } } @@ -52,10 +53,10 @@ class AppSpecific extends BaseSettingsModule $description = $_POST['description'] ?? ''; if (empty($description)) { notice(L10n::t('App-specific password generation failed: The description is empty.')); - self::getApp()->internalRedirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password')); + DI::app()->internalRedirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password')); } elseif (AppSpecificPassword::checkDuplicateForUser(local_user(), $description)) { notice(L10n::t('App-specific password generation failed: This description already exists.')); - self::getApp()->internalRedirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password')); + DI::app()->internalRedirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password')); } else { self::$appSpecificPassword = AppSpecificPassword::generateForUser(local_user(), $_POST['description'] ?? ''); notice(L10n::t('New app-specific password generated.')); @@ -65,7 +66,7 @@ class AppSpecific extends BaseSettingsModule case 'revoke_all' : AppSpecificPassword::deleteAllForUser(local_user()); notice(L10n::t('App-specific passwords successfully revoked.')); - self::getApp()->internalRedirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password')); + DI::app()->internalRedirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password')); break; } } @@ -77,7 +78,7 @@ class AppSpecific extends BaseSettingsModule notice(L10n::t('App-specific password successfully revoked.')); } - self::getApp()->internalRedirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password')); + DI::app()->internalRedirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password')); } } diff --git a/src/Module/Settings/TwoFactor/Index.php b/src/Module/Settings/TwoFactor/Index.php index 03c866ce89..9e822e89ee 100644 --- a/src/Module/Settings/TwoFactor/Index.php +++ b/src/Module/Settings/TwoFactor/Index.php @@ -8,6 +8,7 @@ use Friendica\Core\L10n; use Friendica\Core\PConfig; use Friendica\Core\Renderer; use Friendica\Core\Session; +use Friendica\DI; use Friendica\Model\TwoFactor\AppSpecificPassword; use Friendica\Model\TwoFactor\RecoveryCode; use Friendica\Model\User; @@ -38,7 +39,7 @@ class Index extends BaseSettingsModule PConfig::set(local_user(), '2fa', 'secret', $Google2FA->generateSecretKey(32)); - self::getApp()->internalRedirect('settings/2fa/recovery?t=' . self::getFormSecurityToken('settings_2fa_password')); + DI::app()->internalRedirect('settings/2fa/recovery?t=' . self::getFormSecurityToken('settings_2fa_password')); } break; case 'disable': @@ -49,22 +50,22 @@ class Index extends BaseSettingsModule Session::remove('2fa'); notice(L10n::t('Two-factor authentication successfully disabled.')); - self::getApp()->internalRedirect('settings/2fa'); + DI::app()->internalRedirect('settings/2fa'); } break; case 'recovery': if ($has_secret) { - self::getApp()->internalRedirect('settings/2fa/recovery?t=' . self::getFormSecurityToken('settings_2fa_password')); + DI::app()->internalRedirect('settings/2fa/recovery?t=' . self::getFormSecurityToken('settings_2fa_password')); } break; case 'app_specific': if ($has_secret) { - self::getApp()->internalRedirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password')); + DI::app()->internalRedirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password')); } break; case 'configure': if (!$verified) { - self::getApp()->internalRedirect('settings/2fa/verify?t=' . self::getFormSecurityToken('settings_2fa_password')); + DI::app()->internalRedirect('settings/2fa/verify?t=' . self::getFormSecurityToken('settings_2fa_password')); } break; } diff --git a/src/Module/Settings/TwoFactor/Recovery.php b/src/Module/Settings/TwoFactor/Recovery.php index 8bd40bec98..28f839644c 100644 --- a/src/Module/Settings/TwoFactor/Recovery.php +++ b/src/Module/Settings/TwoFactor/Recovery.php @@ -7,6 +7,7 @@ namespace Friendica\Module\Settings\TwoFactor; use Friendica\Core\L10n; use Friendica\Core\PConfig; use Friendica\Core\Renderer; +use Friendica\DI; use Friendica\Model\TwoFactor\RecoveryCode; use Friendica\Module\BaseSettingsModule; use Friendica\Module\Security\Login; @@ -27,12 +28,12 @@ class Recovery extends BaseSettingsModule $secret = PConfig::get(local_user(), '2fa', 'secret'); if (!$secret) { - self::getApp()->internalRedirect('settings/2fa'); + DI::app()->internalRedirect('settings/2fa'); } if (!self::checkFormSecurityToken('settings_2fa_password', 't')) { notice(L10n::t('Please enter your password to access this page.')); - self::getApp()->internalRedirect('settings/2fa'); + DI::app()->internalRedirect('settings/2fa'); } } @@ -48,7 +49,7 @@ class Recovery extends BaseSettingsModule if ($_POST['action'] == 'regenerate') { RecoveryCode::regenerateForUser(local_user()); notice(L10n::t('New recovery codes successfully generated.')); - self::getApp()->internalRedirect('settings/2fa/recovery?t=' . self::getFormSecurityToken('settings_2fa_password')); + DI::app()->internalRedirect('settings/2fa/recovery?t=' . self::getFormSecurityToken('settings_2fa_password')); } } } diff --git a/src/Module/Settings/TwoFactor/Verify.php b/src/Module/Settings/TwoFactor/Verify.php index 28ee999d14..b478632620 100644 --- a/src/Module/Settings/TwoFactor/Verify.php +++ b/src/Module/Settings/TwoFactor/Verify.php @@ -13,6 +13,7 @@ use Friendica\Core\L10n; use Friendica\Core\PConfig; use Friendica\Core\Renderer; use Friendica\Core\Session; +use Friendica\DI; use Friendica\Module\BaseSettingsModule; use Friendica\Module\Security\Login; use PragmaRX\Google2FA\Google2FA; @@ -34,12 +35,12 @@ class Verify extends BaseSettingsModule $verified = PConfig::get(local_user(), '2fa', 'verified'); if ($secret && $verified) { - self::getApp()->internalRedirect('settings/2fa'); + DI::app()->internalRedirect('settings/2fa'); } if (!self::checkFormSecurityToken('settings_2fa_password', 't')) { notice(L10n::t('Please enter your password to access this page.')); - self::getApp()->internalRedirect('settings/2fa'); + DI::app()->internalRedirect('settings/2fa'); } } @@ -62,7 +63,7 @@ class Verify extends BaseSettingsModule notice(L10n::t('Two-factor authentication successfully activated.')); - self::getApp()->internalRedirect('settings/2fa'); + DI::app()->internalRedirect('settings/2fa'); } else { notice(L10n::t('Invalid code, please retry.')); } diff --git a/src/Module/Settings/UserExport.php b/src/Module/Settings/UserExport.php index 19722a18e2..643a5998e9 100644 --- a/src/Module/Settings/UserExport.php +++ b/src/Module/Settings/UserExport.php @@ -14,6 +14,7 @@ use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\Database\DBStructure; +use Friendica\DI; use Friendica\Module\BaseSettingsModule; /** @@ -65,18 +66,18 @@ class UserExport extends BaseSettingsModule if ($args->getArgc() == 3) { // @TODO Replace with router-provided arguments $action = $args->get(2); - $user = self::getApp()->user; + $user = DI::app()->user; switch ($action) { case "backup": header("Content-type: application/json"); header('Content-Disposition: attachment; filename="' . $user['nickname'] . '.' . $action . '"'); - self::exportAll(self::getApp()); + self::exportAll(DI::app()); exit(); break; case "account": header("Content-type: application/json"); header('Content-Disposition: attachment; filename="' . $user['nickname'] . '.' . $action . '"'); - self::exportAccount(self::getApp()); + self::exportAccount(DI::app()); exit(); break; case "contact": @@ -92,7 +93,7 @@ class UserExport extends BaseSettingsModule } private static function exportMultiRow(string $query) { - $dbStructure = DBStructure::definition(self::getApp()->getBasePath(), false); + $dbStructure = DBStructure::definition(DI::app()->getBasePath(), false); preg_match("/\s+from\s+`?([a-z\d_]+)`?/i", $query, $match); $table = $match[1]; @@ -119,7 +120,7 @@ class UserExport extends BaseSettingsModule private static function exportRow(string $query) { - $dbStructure = DBStructure::definition(self::getApp()->getBasePath(), false); + $dbStructure = DBStructure::definition(DI::app()->getBasePath(), false); preg_match("/\s+from\s+`?([a-z\d_]+)`?/i", $query, $match); $table = $match[1]; diff --git a/src/Module/Smilies.php b/src/Module/Smilies.php index a808ce820c..963cc8c344 100644 --- a/src/Module/Smilies.php +++ b/src/Module/Smilies.php @@ -6,6 +6,7 @@ use Friendica\BaseModule; use Friendica\Content; use Friendica\Core\Renderer; use Friendica\Core\System; +use Friendica\DI; /** * Prints the possible Smilies of this node @@ -14,7 +15,7 @@ class Smilies extends BaseModule { public static function rawContent(array $parameters = []) { - $app = self::getApp(); + $app = DI::app(); if (!empty($app->argv[1]) && ($app->argv[1] === "json")) { $smilies = Content\Smilies::getList(); diff --git a/src/Module/Starred.php b/src/Module/Starred.php index c1fa4c3b8b..d6ec19ea73 100644 --- a/src/Module/Starred.php +++ b/src/Module/Starred.php @@ -3,6 +3,7 @@ namespace Friendica\Module; use Friendica\BaseModule; +use Friendica\DI; use Friendica\Model\Item; /** @@ -35,7 +36,7 @@ class Starred extends BaseModule $returnPath = $_REQUEST['return'] ?? ''; if (!empty($returnPath)) { $rand = '_=' . time() . (strpos($returnPath, '?') ? '&' : '?') . 'rand'; - self::getApp()->internalRedirect($returnPath . $rand); + DI::app()->internalRedirect($returnPath . $rand); } // the json doesn't really matter, it will either be 0 or 1 diff --git a/src/Module/Statistics.php b/src/Module/Statistics.php index 6e599ac9b1..1fe129011a 100644 --- a/src/Module/Statistics.php +++ b/src/Module/Statistics.php @@ -5,12 +5,13 @@ namespace Friendica\Module; use Friendica\BaseModule; use Friendica\Core\Addon; use Friendica\Core\System; +use Friendica\DI; class Statistics extends BaseModule { public static function init(array $parameters = []) { - $config = self::getApp()->getConfig(); + $config = DI::app()->getConfig(); if (!$config->get("system", "nodeinfo")) { throw new \Friendica\Network\HTTPException\NotFoundException(); @@ -19,8 +20,8 @@ class Statistics extends BaseModule public static function rawContent(array $parameters = []) { - $config = self::getApp()->getConfig(); - $logger = self::getApp()->getLogger(); + $config = DI::app()->getConfig(); + $logger = DI::app()->getLogger(); $registration_open = intval($config->get('config', 'register_policy')) !== Register::CLOSED diff --git a/src/Module/Theme.php b/src/Module/Theme.php index e9ce8d396f..cc8f914528 100644 --- a/src/Module/Theme.php +++ b/src/Module/Theme.php @@ -3,6 +3,7 @@ namespace Friendica\Module; use Friendica\BaseModule; +use Friendica\DI; use Friendica\Util\Strings; /** @@ -14,7 +15,7 @@ class Theme extends BaseModule { header("Content-Type: text/css"); - $a = self::getApp(); + $a = DI::app(); if ($a->argc == 4) { $theme = $a->argv[2]; diff --git a/src/Module/ToggleMobile.php b/src/Module/ToggleMobile.php index 0efc2e54b5..71b2de7b65 100644 --- a/src/Module/ToggleMobile.php +++ b/src/Module/ToggleMobile.php @@ -3,6 +3,7 @@ namespace Friendica\Module; use Friendica\BaseModule; +use Friendica\DI; /** * Toggles the mobile view (on/off) @@ -11,7 +12,7 @@ class ToggleMobile extends BaseModule { public static function content(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); if (isset($_GET['off'])) { $_SESSION['show-mobile'] = false; diff --git a/src/Module/Tos.php b/src/Module/Tos.php index ea29a5e072..7adce79174 100644 --- a/src/Module/Tos.php +++ b/src/Module/Tos.php @@ -14,6 +14,7 @@ use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\Content\Text\BBCode; +use Friendica\DI; class Tos extends BaseModule { @@ -50,7 +51,7 @@ class Tos extends BaseModule public static function init(array $parameters = []) { if (strlen(Config::get('system','singleuser'))) { - self::getApp()->internalRedirect('profile/' . Config::get('system','singleuser')); + DI::app()->internalRedirect('profile/' . Config::get('system','singleuser')); } } diff --git a/src/Module/Welcome.php b/src/Module/Welcome.php index f69991e496..e62c5a62db 100644 --- a/src/Module/Welcome.php +++ b/src/Module/Welcome.php @@ -5,6 +5,7 @@ namespace Friendica\Module; use Friendica\BaseModule; use Friendica\Core\L10n; use Friendica\Core\Renderer; +use Friendica\DI; /** * Prints the welcome page for new users @@ -13,7 +14,7 @@ class Welcome extends BaseModule { public static function content(array $parameters = []) { - $config = self::getApp()->getConfig(); + $config = DI::app()->getConfig(); $mail_disabled = ((function_exists('imap_open') && (!$config->get('system', 'imap_disabled')))); diff --git a/src/Module/WellKnown/HostMeta.php b/src/Module/WellKnown/HostMeta.php index cb344b695e..3b03567d71 100644 --- a/src/Module/WellKnown/HostMeta.php +++ b/src/Module/WellKnown/HostMeta.php @@ -4,6 +4,7 @@ namespace Friendica\Module\WellKnown; use Friendica\BaseModule; use Friendica\Core\Renderer; +use Friendica\DI; use Friendica\Protocol\Salmon; use Friendica\Util\Crypto; @@ -15,7 +16,7 @@ class HostMeta extends BaseModule { public static function rawContent(array $parameters = []) { - $app = self::getApp(); + $app = DI::app(); $config = $app->getConfig(); header('Content-type: text/xml'); diff --git a/src/Module/WellKnown/NodeInfo.php b/src/Module/WellKnown/NodeInfo.php index 7d87252edd..4f44e81d9c 100644 --- a/src/Module/WellKnown/NodeInfo.php +++ b/src/Module/WellKnown/NodeInfo.php @@ -4,6 +4,7 @@ namespace Friendica\Module\WellKnown; use Friendica\App; use Friendica\BaseModule; +use Friendica\DI; /** * Standardized way of exposing metadata about a server running one of the distributed social networks. @@ -13,7 +14,7 @@ class NodeInfo extends BaseModule { public static function rawContent(array $parameters = []) { - $app = self::getApp(); + $app = DI::app(); self::printWellKnown($app); } diff --git a/src/Module/WellKnown/XSocialRelay.php b/src/Module/WellKnown/XSocialRelay.php index 5d8f4e817c..2ddac3836d 100644 --- a/src/Module/WellKnown/XSocialRelay.php +++ b/src/Module/WellKnown/XSocialRelay.php @@ -3,6 +3,7 @@ namespace Friendica\Module\WellKnown; use Friendica\BaseModule; +use Friendica\DI; use Friendica\Model\Search; /** @@ -13,7 +14,7 @@ class XSocialRelay extends BaseModule { public static function rawContent(array $parameters = []) { - $app = self::getApp(); + $app = DI::app(); $config = $app->getConfig(); $subscribe = $config->get('system', 'relay_subscribe', false); diff --git a/src/Module/Xrd.php b/src/Module/Xrd.php index 79e0883a87..63b293daf4 100644 --- a/src/Module/Xrd.php +++ b/src/Module/Xrd.php @@ -6,6 +6,7 @@ use Friendica\BaseModule; use Friendica\Core\Hook; use Friendica\Core\Renderer; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Photo; use Friendica\Model\User; use Friendica\Protocol\ActivityNamespace; @@ -19,7 +20,7 @@ class Xrd extends BaseModule { public static function rawContent(array $parameters = []) { - $app = self::getApp(); + $app = DI::app(); // @TODO: Replace with parameter from router if ($app->argv[0] == 'xrd') { diff --git a/src/Network/FKOAuth1.php b/src/Network/FKOAuth1.php index a3dde38d26..da68410626 100644 --- a/src/Network/FKOAuth1.php +++ b/src/Network/FKOAuth1.php @@ -9,6 +9,7 @@ use Friendica\App\Authentication; use Friendica\Core\Logger; use Friendica\Core\Session; use Friendica\Database\DBA; +use Friendica\DI; use OAuthServer; use OAuthSignatureMethod_HMAC_SHA1; use OAuthSignatureMethod_PLAINTEXT; @@ -37,7 +38,7 @@ class FKOAuth1 extends OAuthServer public function loginUser($uid) { Logger::log("FKOAuth1::loginUser $uid"); - $a = BaseObject::getApp(); + $a = DI::app(); $record = DBA::selectFirst('user', [], ['uid' => $uid, 'blocked' => 0, 'account_expired' => 0, 'account_removed' => 0, 'verified' => 1]); if (!DBA::isResult($record)) { diff --git a/src/Object/Post.php b/src/Object/Post.php index 259de94c0f..7697346390 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -18,6 +18,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\Item; use Friendica\Model\Term; @@ -121,7 +122,7 @@ class Post extends BaseObject */ public function getTemplateData(array $conv_responses, $thread_level = 1) { - $a = self::getApp(); + $a = DI::app(); $item = $this->getData(); $edited = false; @@ -815,7 +816,7 @@ class Post extends BaseObject */ private function getDefaultText() { - $a = self::getApp(); + $a = DI::app(); if (!local_user()) { return ''; @@ -862,7 +863,7 @@ class Post extends BaseObject */ private function getCommentBox($indent) { - $a = self::getApp(); + $a = DI::app(); $comment_box = ''; $conv = $this->getThread(); @@ -945,7 +946,7 @@ class Post extends BaseObject */ protected function checkWallToWall() { - $a = self::getApp(); + $a = DI::app(); $conv = $this->getThread(); $this->wall_to_wall = false; diff --git a/src/Object/Thread.php b/src/Object/Thread.php index 4eda1f8f7e..35f155ee1c 100644 --- a/src/Object/Thread.php +++ b/src/Object/Thread.php @@ -7,6 +7,7 @@ namespace Friendica\Object; use Friendica\BaseObject; use Friendica\Core\Logger; use Friendica\Core\Protocol; +use Friendica\DI; use Friendica\Protocol\Activity; use Friendica\Util\Security; @@ -52,7 +53,7 @@ class Thread extends BaseObject return; } - $a = self::getApp(); + $a = DI::app(); switch ($mode) { case 'network': diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 2afd54e47a..9bae638511 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -14,6 +14,7 @@ use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\APContact; use Friendica\Model\Contact; use Friendica\Model\Conversation; @@ -204,7 +205,7 @@ class Transmitter { return ['type' => 'Service', 'name' => FRIENDICA_PLATFORM . " '" . FRIENDICA_CODENAME . "' " . FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION, - 'url' => BaseObject::getApp()->getBaseURL()]; + 'url' => DI::app()->getBaseURL()]; } /** diff --git a/src/Util/Images.php b/src/Util/Images.php index c69c944c0e..ec9179147c 100644 --- a/src/Util/Images.php +++ b/src/Util/Images.php @@ -6,6 +6,7 @@ use Friendica\BaseObject; use Friendica\Core\Cache; use Friendica\Core\Logger; use Friendica\Core\System; +use Friendica\DI; use Imagick; /** @@ -165,7 +166,7 @@ class Images $stamp1 = microtime(true); file_put_contents($tempfile, $img_str); - BaseObject::getApp()->getProfiler()->saveTimestamp($stamp1, "file", System::callstack()); + DI::app()->getProfiler()->saveTimestamp($stamp1, "file", System::callstack()); $data = getimagesize($tempfile); unlink($tempfile); diff --git a/src/Util/Proxy.php b/src/Util/Proxy.php index 9309887409..0c9c053d0a 100644 --- a/src/Util/Proxy.php +++ b/src/Util/Proxy.php @@ -5,6 +5,7 @@ namespace Friendica\Util; use Friendica\BaseObject; use Friendica\Core\Config; use Friendica\Core\System; +use Friendica\DI; /** * @brief Proxy utilities class @@ -63,7 +64,7 @@ class Proxy public static function proxifyUrl($url, $writemode = false, $size = '') { // Get application instance - $a = BaseObject::getApp(); + $a = DI::app(); // Trim URL first $url = trim($url); diff --git a/src/Worker/Cron.php b/src/Worker/Cron.php index 6928cb8d79..1a72db53f5 100644 --- a/src/Worker/Cron.php +++ b/src/Worker/Cron.php @@ -12,6 +12,7 @@ use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Core\Worker; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Util\DateTimeFormat; @@ -19,7 +20,7 @@ class Cron { public static function execute() { - $a = BaseObject::getApp(); + $a = DI::app(); $last = Config::get('system', 'last_cron'); diff --git a/src/Worker/CronJobs.php b/src/Worker/CronJobs.php index 311ec59a53..6c7154957f 100644 --- a/src/Worker/CronJobs.php +++ b/src/Worker/CronJobs.php @@ -14,6 +14,7 @@ use Friendica\Core\StorageManager; use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\Database\PostUpdate; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\GContact; use Friendica\Model\GServer; @@ -29,7 +30,7 @@ class CronJobs { public static function execute($command = '') { - $a = BaseObject::getApp(); + $a = DI::app(); // No parameter set? So return if ($command == '') { diff --git a/src/Worker/DBUpdate.php b/src/Worker/DBUpdate.php index 001df25a81..84159eb433 100644 --- a/src/Worker/DBUpdate.php +++ b/src/Worker/DBUpdate.php @@ -8,6 +8,7 @@ namespace Friendica\Worker; use Friendica\BaseObject; use Friendica\Core\Config; use Friendica\Core\Update; +use Friendica\DI; class DBUpdate extends BaseObject { @@ -15,7 +16,7 @@ class DBUpdate extends BaseObject { // Just in case the last update wasn't failed if (Config::get('system', 'update', Update::SUCCESS, true) != Update::FAILED) { - Update::run(self::getApp()->getBasePath()); + Update::run(DI::app()->getBasePath()); } } } diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index c364ce5e51..aebc74b185 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -11,6 +11,7 @@ use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model; use Friendica\Protocol\DFRN; use Friendica\Protocol\Diaspora; @@ -140,7 +141,7 @@ class Delivery extends BaseObject // if $parent['wall'] == 1 we will already have the parent message in our array // and we will relay the whole lot. - $localhost = self::getApp()->getHostName(); + $localhost = DI::app()->getHostName(); if (strpos($localhost, ':')) { $localhost = substr($localhost, 0, strpos($localhost, ':')); } @@ -548,7 +549,7 @@ class Delivery extends BaseObject $headers = 'From: ' . Email::encodeHeader($local_user['username'],'UTF-8') . ' <' . $local_user['email'] . '>' . "\n"; } } else { - $headers = 'From: '. Email::encodeHeader($local_user['username'], 'UTF-8') . ' getHostName() . '>' . "\n"; + $headers = 'From: '. Email::encodeHeader($local_user['username'], 'UTF-8') . ' getHostName() . '>' . "\n"; } $headers .= 'Message-Id: <' . Email::iri2msgid($target_item['uri']) . '>' . "\n"; diff --git a/src/Worker/Expire.php b/src/Worker/Expire.php index cb6bdbacbc..16a68f6487 100644 --- a/src/Worker/Expire.php +++ b/src/Worker/Expire.php @@ -12,13 +12,14 @@ use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\Core\Worker; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Item; class Expire { public static function execute($param = '', $hook_function = '') { - $a = BaseObject::getApp(); + $a = DI::app(); Hook::loadHooks(); diff --git a/src/Worker/ForkHook.php b/src/Worker/ForkHook.php index 586d1496e6..002cad9853 100644 --- a/src/Worker/ForkHook.php +++ b/src/Worker/ForkHook.php @@ -6,12 +6,13 @@ namespace Friendica\Worker; use Friendica\Core\Hook; +use Friendica\DI; Class ForkHook { public static function execute($name, $hook, $data) { - $a = \Friendica\BaseObject::getApp(); + $a = DI::app(); Hook::callSingle($a, $name, $hook, $data); } diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 19bd518856..91de60ef61 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -11,6 +11,7 @@ use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Core\Worker; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\APContact; use Friendica\Model\Contact; use Friendica\Model\Conversation; @@ -41,7 +42,7 @@ class Notifier { public static function execute($cmd, $target_id) { - $a = BaseObject::getApp(); + $a = DI::app(); Logger::info('Invoked', ['cmd' => $cmd, 'target' => $target_id]); diff --git a/src/Worker/ProfileUpdate.php b/src/Worker/ProfileUpdate.php index 808d47299f..b5ae51bd4b 100644 --- a/src/Worker/ProfileUpdate.php +++ b/src/Worker/ProfileUpdate.php @@ -9,6 +9,7 @@ namespace Friendica\Worker; use Friendica\BaseObject; use Friendica\Core\Logger; use Friendica\Core\Worker; +use Friendica\DI; use Friendica\Protocol\Diaspora; use Friendica\Protocol\ActivityPub; @@ -18,7 +19,7 @@ class ProfileUpdate { return; } - $a = BaseObject::getApp(); + $a = DI::app(); $inboxes = ActivityPub\Transmitter::fetchTargetInboxesforUser($uid); diff --git a/tests/include/ApiTest.php b/tests/include/ApiTest.php index c54135faee..4c9db07089 100644 --- a/tests/include/ApiTest.php +++ b/tests/include/ApiTest.php @@ -15,6 +15,7 @@ use Friendica\Core\Session; use Friendica\Core\Session\ISession; use Friendica\Core\System; use Friendica\Database\Database; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Network\HTTPException; use Friendica\Test\Util\Database\StaticDatabase; @@ -87,7 +88,7 @@ class ApiTest extends DatabaseTest $this->loadFixture(__DIR__ . '/../datasets/api.fixture.php', $dba); /** @var App app */ - $this->app = BaseObject::getApp(); + $this->app = DI::app(); $this->app->argc = 1; $this->app->argv = ['home']; diff --git a/tests/src/BaseObjectTest.php b/tests/src/BaseObjectTest.php deleted file mode 100644 index 6935214527..0000000000 --- a/tests/src/BaseObjectTest.php +++ /dev/null @@ -1,36 +0,0 @@ - Date: Sun, 15 Dec 2019 23:28:01 +0100 Subject: [PATCH 02/34] Replace BaseObject class with DI::* calls --- bin/auth_ejabberd.php | 3 +- bin/daemon.php | 2 +- bin/worker.php | 3 +- boot.php | 1 - include/api.php | 16 +--- include/conversation.php | 19 ++-- include/items.php | 5 -- index.php | 2 +- mod/dfrn_poll.php | 7 +- mod/events.php | 5 +- mod/item.php | 10 +-- mod/lockview.php | 6 +- mod/network.php | 12 +-- mod/notifications.php | 4 +- mod/photos.php | 12 +-- mod/settings.php | 7 +- src/App/Module.php | 4 +- src/BaseModule.php | 2 +- src/BaseObject.php | 58 ------------ src/Content/Text/BBCode.php | 3 +- src/Content/Text/Markdown.php | 3 +- src/Core/ACL.php | 3 +- src/Core/Addon.php | 3 +- src/Core/Cache.php | 15 ++-- src/Core/Config.php | 13 ++- src/Core/Console.php | 2 +- src/Core/Hook.php | 3 +- src/Core/L10n.php | 18 ++-- src/Core/Lock.php | 13 ++- src/Core/Logger.php | 38 +++++--- src/Core/PConfig.php | 13 ++- src/Core/Renderer.php | 3 +- src/Core/Search.php | 3 +- src/Core/Session.php | 29 +++--- src/Core/System.php | 7 +- src/Core/Theme.php | 1 - src/Core/Worker.php | 1 - src/DI.php | 89 +++++++++++++++++++ src/Database/DBA.php | 78 ++++++++-------- src/Model/APContact.php | 3 +- src/Model/Attach.php | 3 +- src/Model/Contact.php | 4 +- src/Model/Event.php | 3 +- src/Model/Group.php | 3 +- src/Model/Item.php | 10 +-- src/Model/ItemContent.php | 3 +- src/Model/ItemURI.php | 3 +- src/Model/Nodeinfo.php | 3 +- src/Model/Notify.php | 3 +- src/Model/PermissionSet.php | 3 +- src/Model/Photo.php | 3 +- src/Model/Process.php | 3 +- src/Model/Search.php | 3 +- src/Model/TwoFactor/AppSpecificPassword.php | 3 +- src/Model/TwoFactor/RecoveryCode.php | 3 +- src/Module/Admin/Summary.php | 3 +- src/Module/Api/Mastodon/FollowRequests.php | 5 +- src/Module/Base/Api.php | 8 +- src/Module/BaseSearchModule.php | 3 +- src/Module/Delegation.php | 5 +- src/Module/Diaspora/Receive.php | 15 ++-- src/Module/Item/Compose.php | 3 +- src/Module/Item/Ignore.php | 9 +- src/Module/Notifications/Notify.php | 9 +- src/Module/Profile.php | 5 +- src/Module/Register.php | 2 +- src/Module/Search/Index.php | 4 +- src/Module/Search/Saved.php | 6 +- src/Module/Security/Login.php | 9 +- src/Module/Security/TwoFactor/Recovery.php | 5 +- src/Module/Security/TwoFactor/Verify.php | 4 +- src/Module/Settings/Delegation.php | 3 +- src/Module/Settings/UserExport.php | 2 +- src/Network/FKOAuth1.php | 7 +- src/Object/Post.php | 12 +-- src/Object/Thread.php | 3 +- src/Protocol/ActivityPub/Transmitter.php | 1 - src/Protocol/DFRN.php | 7 +- src/Util/Images.php | 1 - src/Util/Proxy.php | 1 - src/Util/Security.php | 3 +- src/Worker/APDelivery.php | 3 +- src/Worker/Cron.php | 1 - src/Worker/CronJobs.php | 1 - src/Worker/DBUpdate.php | 3 +- src/Worker/Delivery.php | 3 +- src/Worker/Expire.php | 1 - src/Worker/Notifier.php | 4 +- src/Worker/OnePoll.php | 2 - src/Worker/ProfileUpdate.php | 1 - tests/Util/AppMockTrait.php | 4 +- tests/include/ApiTest.php | 6 +- .../AutomaticInstallationConsoleTest.php | 4 +- tests/src/Core/InstallerTest.php | 5 +- tests/src/Core/Lock/SemaphoreLockTest.php | 4 +- tests/src/Database/DBATest.php | 4 +- tests/src/Database/DBStructureTest.php | 4 +- tests/src/Network/CurlResultTest.php | 4 +- 98 files changed, 321 insertions(+), 440 deletions(-) delete mode 100644 src/BaseObject.php diff --git a/bin/auth_ejabberd.php b/bin/auth_ejabberd.php index 5ccdd0174b..13dc6eeba0 100755 --- a/bin/auth_ejabberd.php +++ b/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); diff --git a/bin/daemon.php b/bin/daemon.php index b3166145b8..039a40cf06 100755 --- a/bin/daemon.php +++ b/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()) { diff --git a/bin/worker.php b/bin/worker.php index 1de90d8cae..e156170490 100755 --- a/bin/worker.php +++ b/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 diff --git a/boot.php b/boot.php index 2dcc15f7d3..ecf83854ff 100644 --- a/boot.php +++ b/boot.php @@ -18,7 +18,6 @@ */ use Friendica\App; -use Friendica\BaseObject; use Friendica\Core\Config; use Friendica\Core\PConfig; use Friendica\Core\Protocol; diff --git a/include/api.php b/include/api.php index 916051f06c..363a0b9700 100644 --- a/include/api.php +++ b/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"); diff --git a/include/conversation.php b/include/conversation.php index b27cfe0c81..9e22c958b5 100644 --- a/include/conversation.php +++ b/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); diff --git a/include/items.php b/include/items.php index a449571ff7..5ae8558d81 100644 --- a/include/items.php +++ b/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'; diff --git a/index.php b/index.php index a7eee2a331..b558e86c8e 100644 --- a/index.php +++ b/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(); diff --git a/mod/dfrn_poll.php b/mod/dfrn_poll.php index 0641b9177b..7ebca9effa 100644 --- a/mod/dfrn_poll.php +++ b/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'; diff --git a/mod/events.php b/mod/events.php index 6547a9b9ce..1a8eccde11 100644 --- a/mod/events.php +++ b/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'] ?? ''); diff --git a/mod/item.php b/mod/item.php index 93da70e40e..e20fb99521 100644 --- a/mod/item.php +++ b/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); diff --git a/mod/lockview.php b/mod/lockview.php index 9f9dcfea42..fc9fed3066 100644 --- a/mod/lockview.php +++ b/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']); diff --git a/mod/network.php b/mod/network.php index 5d8656cd35..0376203401 100644 --- a/mod/network.php +++ b/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 { diff --git a/mod/notifications.php b/mod/notifications.php index 502a2397de..51b4d80873 100644 --- a/mod/notifications.php +++ b/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 diff --git a/mod/photos.php b/mod/photos.php index 1d7ce7b3de..a3d81c041d 100644 --- a/mod/photos.php +++ b/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)) && diff --git a/mod/settings.php b/mod/settings.php index ad83b68210..b126defcba 100644 --- a/mod/settings.php +++ b/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']) : ''; diff --git a/src/App/Module.php b/src/App/Module.php index a8648d0aa0..39111c9501 100644 --- a/src/App/Module.php +++ b/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; diff --git a/src/BaseModule.php b/src/BaseModule.php index be53289e52..3d6a3f691f 100644 --- a/src/BaseModule.php +++ b/src/BaseModule.php @@ -14,7 +14,7 @@ use Friendica\Core\Logger; * * @author Hypolite Petovan */ -abstract class BaseModule extends BaseObject +abstract class BaseModule { /** * @brief Initialization method common to both content() and post() diff --git a/src/BaseObject.php b/src/BaseObject.php deleted file mode 100644 index 742b2c8598..0000000000 --- a/src/BaseObject.php +++ /dev/null @@ -1,58 +0,0 @@ -create($name); - } else { - throw new InternalServerErrorException('Class \'' . $name . '\' isn\'t valid.'); - } - } -} diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 037ea901af..2619dc92cc 100644 --- a/src/Content/Text/BBCode.php +++ b/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 diff --git a/src/Content/Text/Markdown.php b/src/Content/Text/Markdown.php index cca64b0ab2..004f01beed 100644 --- a/src/Content/Text/Markdown.php +++ b/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 */ -class Markdown extends BaseObject +class Markdown { /** * Converts a Markdown string into HTML. The hardwrap parameter maximizes diff --git a/src/Core/ACL.php b/src/Core/ACL.php index 6134828658..d48ef3fa51 100644 --- a/src/Core/ACL.php +++ b/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 */ -class ACL extends BaseObject +class ACL { /** * Returns a select input tag with all the contact of the local user diff --git a/src/Core/Addon.php b/src/Core/Addon.php index b1c1ad2e60..59e1ec7b96 100644 --- a/src/Core/Addon.php +++ b/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 diff --git a/src/Core/Cache.php b/src/Core/Cache.php index 7a952ff8a1..d0a04b9ec1 100644 --- a/src/Core/Cache.php +++ b/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); } } diff --git a/src/Core/Config.php b/src/Core/Config.php index cec7a460e7..6864cb78d6 100644 --- a/src/Core/Config.php +++ b/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); } } diff --git a/src/Core/Console.php b/src/Core/Console.php index 2ca568c2da..16fc90c4eb 100644 --- a/src/Core/Console.php +++ b/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]); diff --git a/src/Core/Hook.php b/src/Core/Hook.php index 959ed9fa16..b8ad0fb8bd 100644 --- a/src/Core/Hook.php +++ b/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 diff --git a/src/Core/L10n.php b/src/Core/L10n.php index b27228cf80..d1a6204ef3 100644 --- a/src/Core/L10n.php +++ b/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(); } } diff --git a/src/Core/Lock.php b/src/Core/Lock.php index ef62bc8f76..e25feac2ec 100644 --- a/src/Core/Lock.php +++ b/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(); } } diff --git a/src/Core/Logger.php b/src/Core/Logger.php index e8d95fa857..0ce2a6e675 100644 --- a/src/Core/Logger.php +++ b/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); } } diff --git a/src/Core/PConfig.php b/src/Core/PConfig.php index e96935c4e6..06b0140097 100644 --- a/src/Core/PConfig.php +++ b/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); } } diff --git a/src/Core/Renderer.php b/src/Core/Renderer.php index ce90d78dee..c687a67283 100644 --- a/src/Core/Renderer.php +++ b/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') diff --git a/src/Core/Search.php b/src/Core/Search.php index ff1a8a317c..c1c80091f0 100644 --- a/src/Core/Search.php +++ b/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'; diff --git a/src/Core/Session.php b/src/Core/Session.php index 0557ce81b7..d0c8581d31 100644 --- a/src/Core/Session.php +++ b/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 */ -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(); $session->set('remote', []); @@ -117,8 +113,7 @@ class Session extends BaseObject */ public static function isAuthenticated() { - /** @var ISession $session */ - $session = self::getClass(ISession::class); + $session = DI::session(); return $session->get('authenticated', false); } diff --git a/src/Core/System.php b/src/Core/System.php index cf6fd9b4a9..367e055c93 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -4,8 +4,6 @@ */ namespace Friendica\Core; -use Friendica\App\BaseURL; -use Friendica\BaseObject; use Friendica\DI; use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Util\XML; @@ -20,18 +18,17 @@ use Friendica\Util\XML; /** * @brief System methods */ -class System extends BaseObject +class System { /** * @brief Retrieves the Friendica instance base URL * * @param bool $ssl Whether to append http or https under BaseURL::SSL_POLICY_SELFSIGN * @return string Friendica server base URL - * @throws InternalServerErrorException */ public static function baseUrl($ssl = false) { - return self::getClass(BaseURL::class)->get($ssl); + return DI::baseUrl()->get($ssl); } /** diff --git a/src/Core/Theme.php b/src/Core/Theme.php index 7df985df35..dea3e20e64 100644 --- a/src/Core/Theme.php +++ b/src/Core/Theme.php @@ -6,7 +6,6 @@ namespace Friendica\Core; -use Friendica\BaseObject; use Friendica\DI; use Friendica\Model\Profile; use Friendica\Util\Strings; diff --git a/src/Core/Worker.php b/src/Core/Worker.php index b9362dace5..b451b11ca5 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -4,7 +4,6 @@ */ namespace Friendica\Core; -use Friendica\BaseObject; use Friendica\Core; use Friendica\Database\DBA; use Friendica\DI; diff --git a/src/DI.php b/src/DI.php index ef05b5cb07..efd29f9c0c 100644 --- a/src/DI.php +++ b/src/DI.php @@ -3,6 +3,22 @@ namespace Friendica; use Dice\Dice; +use Friendica\Core\Cache\ICache; +use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\PConfiguration; +use Friendica\Core\L10n\L10n; +use Friendica\Core\Lock\ILock; +use Friendica\Core\Session\ISession; +use Friendica\Database\Database; +use Friendica\Model\Notify; +use Friendica\Protocol\Activity; +use Friendica\Util\ACLFormatter; +use Friendica\Content\Item as ContentItem; +use Friendica\Content\Text\BBCode\Video as BBCodeVideo; +use Friendica\Util\DateTimeFormat; +use Friendica\Util\FileSystem; +use Friendica\Util\Logger\WorkerLogger; +use Psr\Log\LoggerInterface; /** * This class is capable of getting all dynamic created classes @@ -10,6 +26,31 @@ use Dice\Dice; * There has to be a "method" phpDoc for each new class, containing result class for a proper matching * * @method static App app() + * @method static ACLFormatter aclFormatter() + * @method static Notify notify() + * @method static Activity activity() + * @method static ContentItem contentItem() + * @method static BBCodeVideo bbCodeVideo() + * @method static DateTimeFormat dtFormat() + * @method static ICache cache() + * @method static Configuration config() + * @method static PConfiguration pConfig() + * @method static ILock lock() + * @method static L10n l10n() + * @method static LoggerInterface logger() + * @method static LoggerInterface devLogger() + * @method static LoggerInterface workerLogger() + * @method static ISession session() + * @method static App\Authentication auth() + * @method static App\Arguments args() + * @method static App\BaseURL baseUrl() + * @method static App\Mode mode() + * @method static App\Module module() + * @method static App\Page page() + * @method static App\Router router() + * @method static Database dba() + * @method static FileSystem fs() + * */ class DI { @@ -26,6 +67,54 @@ class DI switch ($name) { case 'app': return self::$dice->create(App::class, $arguments); + case 'aclFormatter': + return self::$dice->create(ACLFormatter::class, $arguments); + case 'auth': + return self::$dice->create(App\Authentication::class, $arguments); + case 'args': + return self::$dice->create(App\Arguments::class, $arguments); + case 'baseUrl': + return self::$dice->create(App\BaseURL::class, $arguments); + case 'mode': + return self::$dice->create(App\Mode::class, $arguments); + case 'module': + return self::$dice->create(App\Module::class, $arguments); + case 'page': + return self::$dice->create(App\Page::class, $arguments); + case 'router': + return self::$dice->create(App\Router::class, $arguments); + case 'notify': + return self::$dice->create(Notify::class, $arguments); + case 'activity': + return self::$dice->create(Activity::class, $arguments); + case 'contentItem': + return self::$dice->create(ContentItem::class, $arguments); + case 'bbCodeVideo': + return self::$dice->create(BBCodeVideo::class, $arguments); + case 'dtFormat': + return self::$dice->create(DateTimeFormat::class, $arguments); + case 'cache': + return self::$dice->create(ICache::class, $arguments); + case 'config': + return self::$dice->create(Configuration::class, $arguments); + case 'pConfig': + return self::$dice->create(PConfiguration::class, $arguments); + case 'lock': + return self::$dice->create(ILock::class, $arguments); + case 'l10n': + return self::$dice->create(L10n::class, $arguments); + case 'logger': + return self::$dice->create(LoggerInterface::class, $arguments); + case 'devLogger': + return self::$dice->create('$devLogger', $arguments); + case 'workerLogger': + return self::$dice->create(WorkerLogger::class, $arguments); + case 'session': + return self::$dice->create(ISession::class, $arguments); + case 'dba': + return self::$dice->create(Database::class, $arguments); + case 'fs': + return self::$dice->create(FileSystem::class, $arguments); default: return null; } diff --git a/src/Database/DBA.php b/src/Database/DBA.php index 593ca0e507..1cf10ba4ad 100644 --- a/src/Database/DBA.php +++ b/src/Database/DBA.php @@ -2,7 +2,7 @@ namespace Friendica\Database; -use Friendica\BaseObject; +use Friendica\DI; use mysqli; use mysqli_result; use mysqli_stmt; @@ -14,7 +14,7 @@ use PDOStatement; * * This class is for the low level database stuff that does driver specific things. */ -class DBA extends BaseObject +class DBA { /** * Lowest possible date value @@ -27,7 +27,7 @@ class DBA extends BaseObject public static function connect() { - return self::getClass(Database::class)->connect(); + return DI::dba()->connect(); } /** @@ -35,7 +35,7 @@ class DBA extends BaseObject */ public static function disconnect() { - self::getClass(Database::class)->disconnect(); + DI::dba()->disconnect(); } /** @@ -43,7 +43,7 @@ class DBA extends BaseObject */ public static function reconnect() { - return self::getClass(Database::class)->reconnect(); + return DI::dba()->reconnect(); } /** @@ -52,7 +52,7 @@ class DBA extends BaseObject */ public static function getConnection() { - return self::getClass(Database::class)->getConnection(); + return DI::dba()->getConnection(); } /** @@ -65,7 +65,7 @@ class DBA extends BaseObject */ public static function serverInfo() { - return self::getClass(Database::class)->serverInfo(); + return DI::dba()->serverInfo(); } /** @@ -76,17 +76,17 @@ class DBA extends BaseObject */ public static function databaseName() { - return self::getClass(Database::class)->databaseName(); + return DI::dba()->databaseName(); } public static function escape($str) { - return self::getClass(Database::class)->escape($str); + return DI::dba()->escape($str); } public static function connected() { - return self::getClass(Database::class)->connected(); + return DI::dba()->connected(); } /** @@ -102,7 +102,7 @@ class DBA extends BaseObject */ public static function anyValueFallback($sql) { - return self::getClass(Database::class)->anyValueFallback($sql); + return DI::dba()->anyValueFallback($sql); } /** @@ -158,7 +158,7 @@ class DBA extends BaseObject { $params = self::getParam(func_get_args()); - return self::getClass(Database::class)->p($sql, $params); + return DI::dba()->p($sql, $params); } /** @@ -174,7 +174,7 @@ class DBA extends BaseObject $params = self::getParam(func_get_args()); - return self::getClass(Database::class)->e($sql, $params); + return DI::dba()->e($sql, $params); } /** @@ -188,7 +188,7 @@ class DBA extends BaseObject */ public static function exists($table, $condition) { - return self::getClass(Database::class)->exists($table, $condition); + return DI::dba()->exists($table, $condition); } /** @@ -205,7 +205,7 @@ class DBA extends BaseObject { $params = self::getParam(func_get_args()); - return self::getClass(Database::class)->fetchFirst($sql, $params); + return DI::dba()->fetchFirst($sql, $params); } /** @@ -215,7 +215,7 @@ class DBA extends BaseObject */ public static function affectedRows() { - return self::getClass(Database::class)->affectedRows(); + return DI::dba()->affectedRows(); } /** @@ -226,7 +226,7 @@ class DBA extends BaseObject */ public static function columnCount($stmt) { - return self::getClass(Database::class)->columnCount($stmt); + return DI::dba()->columnCount($stmt); } /** * @brief Returns the number of rows of a statement @@ -236,7 +236,7 @@ class DBA extends BaseObject */ public static function numRows($stmt) { - return self::getClass(Database::class)->numRows($stmt); + return DI::dba()->numRows($stmt); } /** @@ -247,7 +247,7 @@ class DBA extends BaseObject */ public static function fetch($stmt) { - return self::getClass(Database::class)->fetch($stmt); + return DI::dba()->fetch($stmt); } /** @@ -262,7 +262,7 @@ class DBA extends BaseObject */ public static function insert($table, $param, $on_duplicate_update = false) { - return self::getClass(Database::class)->insert($table, $param, $on_duplicate_update); + return DI::dba()->insert($table, $param, $on_duplicate_update); } /** @@ -272,7 +272,7 @@ class DBA extends BaseObject */ public static function lastInsertId() { - return self::getClass(Database::class)->lastInsertId(); + return DI::dba()->lastInsertId(); } /** @@ -287,7 +287,7 @@ class DBA extends BaseObject */ public static function lock($table) { - return self::getClass(Database::class)->lock($table); + return DI::dba()->lock($table); } /** @@ -298,7 +298,7 @@ class DBA extends BaseObject */ public static function unlock() { - return self::getClass(Database::class)->unlock(); + return DI::dba()->unlock(); } /** @@ -308,7 +308,7 @@ class DBA extends BaseObject */ public static function transaction() { - return self::getClass(Database::class)->transaction(); + return DI::dba()->transaction(); } /** @@ -318,7 +318,7 @@ class DBA extends BaseObject */ public static function commit() { - return self::getClass(Database::class)->commit(); + return DI::dba()->commit(); } /** @@ -328,7 +328,7 @@ class DBA extends BaseObject */ public static function rollback() { - return self::getClass(Database::class)->rollback(); + return DI::dba()->rollback(); } /** @@ -345,7 +345,7 @@ class DBA extends BaseObject */ public static function delete($table, array $conditions, array $options = []) { - return self::getClass(Database::class)->delete($table, $conditions, $options); + return DI::dba()->delete($table, $conditions, $options); } /** @@ -379,7 +379,7 @@ class DBA extends BaseObject */ public static function update($table, $fields, $condition, $old_fields = []) { - return self::getClass(Database::class)->update($table, $fields, $condition, $old_fields); + return DI::dba()->update($table, $fields, $condition, $old_fields); } /** @@ -396,7 +396,7 @@ class DBA extends BaseObject */ public static function selectFirst($table, array $fields = [], array $condition = [], $params = []) { - return self::getClass(Database::class)->selectFirst($table, $fields, $condition, $params); + return DI::dba()->selectFirst($table, $fields, $condition, $params); } /** @@ -413,7 +413,7 @@ class DBA extends BaseObject */ public static function selectToArray($table, array $fields = [], array $condition = [], array $params = []) { - return self::getClass(Database::class)->selectToArray($table, $fields, $condition, $params); + return DI::dba()->selectToArray($table, $fields, $condition, $params); } /** @@ -441,7 +441,7 @@ class DBA extends BaseObject */ public static function select($table, array $fields = [], array $condition = [], array $params = []) { - return self::getClass(Database::class)->select($table, $fields, $condition, $params); + return DI::dba()->select($table, $fields, $condition, $params); } /** @@ -465,7 +465,7 @@ class DBA extends BaseObject */ public static function count($table, array $condition = [], array $params = []) { - return self::getClass(Database::class)->count($table, $condition, $params); + return DI::dba()->count($table, $condition, $params); } /** @@ -639,7 +639,7 @@ class DBA extends BaseObject */ public static function toArray($stmt, $do_close = true) { - return self::getClass(Database::class)->toArray($stmt, $do_close); + return DI::dba()->toArray($stmt, $do_close); } /** @@ -649,7 +649,7 @@ class DBA extends BaseObject */ public static function errorNo() { - return self::getClass(Database::class)->errorNo(); + return DI::dba()->errorNo(); } /** @@ -659,7 +659,7 @@ class DBA extends BaseObject */ public static function errorMessage() { - return self::getClass(Database::class)->errorMessage(); + return DI::dba()->errorMessage(); } /** @@ -670,7 +670,7 @@ class DBA extends BaseObject */ public static function close($stmt) { - return self::getClass(Database::class)->close($stmt); + return DI::dba()->close($stmt); } /** @@ -683,7 +683,7 @@ class DBA extends BaseObject */ public static function processlist() { - return self::getClass(Database::class)->processlist(); + return DI::dba()->processlist(); } /** @@ -695,7 +695,7 @@ class DBA extends BaseObject */ public static function isResult($array) { - return self::getClass(Database::class)->isResult($array); + return DI::dba()->isResult($array); } /** @@ -707,6 +707,6 @@ class DBA extends BaseObject */ public static function escapeArray(&$arr, $add_quotation = false) { - return self::getClass(Database::class)->escapeArray($arr, $add_quotation); + DI::dba()->escapeArray($arr, $add_quotation); } } diff --git a/src/Model/APContact.php b/src/Model/APContact.php index c535034487..067be58746 100644 --- a/src/Model/APContact.php +++ b/src/Model/APContact.php @@ -6,7 +6,6 @@ namespace Friendica\Model; -use Friendica\BaseObject; use Friendica\Content\Text\HTML; use Friendica\Core\Logger; use Friendica\Core\Config; @@ -17,7 +16,7 @@ use Friendica\Util\JsonLD; use Friendica\Util\DateTimeFormat; use Friendica\Util\Strings; -class APContact extends BaseObject +class APContact { /** * Resolves the profile url from the address by using webfinger diff --git a/src/Model/Attach.php b/src/Model/Attach.php index fce55f5106..c1d5c033bd 100644 --- a/src/Model/Attach.php +++ b/src/Model/Attach.php @@ -6,7 +6,6 @@ */ namespace Friendica\Model; -use Friendica\BaseObject; use Friendica\Core\StorageManager; use Friendica\Core\System; use Friendica\Database\DBA; @@ -21,7 +20,7 @@ use Friendica\Util\Security; /** * Class to handle attach dabatase table */ -class Attach extends BaseObject +class Attach { /** diff --git a/src/Model/Contact.php b/src/Model/Contact.php index c4f05b2dc9..577f3da1df 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -5,7 +5,6 @@ namespace Friendica\Model; use Friendica\App\BaseURL; -use Friendica\BaseObject; use Friendica\Content\Pager; use Friendica\Core\Config; use Friendica\Core\Hook; @@ -18,7 +17,6 @@ use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Network\Probe; -use Friendica\Object\Image; use Friendica\Protocol\Activity; use Friendica\Protocol\ActivityPub; use Friendica\Protocol\DFRN; @@ -33,7 +31,7 @@ use Friendica\Util\Strings; /** * @brief functions for interacting with a contact */ -class Contact extends BaseObject +class Contact { /** * @deprecated since version 2019.03 diff --git a/src/Model/Event.php b/src/Model/Event.php index 7b6f31baa4..0374c6bb7c 100644 --- a/src/Model/Event.php +++ b/src/Model/Event.php @@ -5,7 +5,6 @@ namespace Friendica\Model; -use Friendica\BaseObject; use Friendica\Content\Text\BBCode; use Friendica\Core\Hook; use Friendica\Core\L10n; @@ -23,7 +22,7 @@ use Friendica\Util\XML; /** * @brief functions for interacting with the event database table */ -class Event extends BaseObject +class Event { public static function getHTML(array $event, $simple = false) diff --git a/src/Model/Group.php b/src/Model/Group.php index 3be2a80e56..c984f0032e 100644 --- a/src/Model/Group.php +++ b/src/Model/Group.php @@ -6,7 +6,6 @@ namespace Friendica\Model; use Friendica\BaseModule; -use Friendica\BaseObject; use Friendica\Core\L10n; use Friendica\Core\Logger; use Friendica\Core\Protocol; @@ -16,7 +15,7 @@ use Friendica\Database\DBA; /** * @brief functions for interacting with the group database table */ -class Group extends BaseObject +class Group { const FOLLOWERS = '~'; const MUTUALS = '&'; diff --git a/src/Model/Item.php b/src/Model/Item.php index 9a86097ae8..f955337179 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -6,7 +6,6 @@ namespace Friendica\Model; -use Friendica\BaseObject; use Friendica\Content\Text\BBCode; use Friendica\Content\Text\HTML; use Friendica\Core\Config; @@ -26,7 +25,6 @@ use Friendica\Protocol\Activity; use Friendica\Protocol\ActivityPub; use Friendica\Protocol\Diaspora; use Friendica\Protocol\OStatus; -use Friendica\Util\ACLFormatter; use Friendica\Util\DateTimeFormat; use Friendica\Util\Map; use Friendica\Util\Network; @@ -36,7 +34,7 @@ use Friendica\Util\XML; use Friendica\Worker\Delivery; use Text_LanguageDetect; -class Item extends BaseObject +class Item { // Posting types, inspired by https://www.w3.org/TR/activitystreams-vocabulary/#object-types const PT_ARTICLE = 0; @@ -1442,8 +1440,7 @@ class Item extends BaseObject $item['parent-uri'] = $item['thr-parent']; } - /** @var Activity $activity */ - $activity = self::getClass(Activity::class); + $activity = DI::activity(); if (isset($item['gravity'])) { $item['gravity'] = intval($item['gravity']); @@ -2980,8 +2977,7 @@ class Item extends BaseObject */ public static function enumeratePermissions(array $obj, bool $check_dead = false) { - /** @var ACLFormatter $aclFormater */ - $aclFormater = self::getClass(ACLFormatter::class); + $aclFormater = DI::aclFormatter(); $allow_people = $aclFormater->expand($obj['allow_cid']); $allow_groups = Group::expand($obj['uid'], $aclFormater->expand($obj['allow_gid']), $check_dead); diff --git a/src/Model/ItemContent.php b/src/Model/ItemContent.php index 68b42af928..136323385c 100644 --- a/src/Model/ItemContent.php +++ b/src/Model/ItemContent.php @@ -6,12 +6,11 @@ namespace Friendica\Model; -use Friendica\BaseObject; use Friendica\Content\Text; use Friendica\Core\PConfig; use Friendica\Core\Protocol; -class ItemContent extends BaseObject +class ItemContent { /** * @brief Convert a message into plaintext for connectors to other networks diff --git a/src/Model/ItemURI.php b/src/Model/ItemURI.php index 8e39ebd1cb..7e27858a3b 100644 --- a/src/Model/ItemURI.php +++ b/src/Model/ItemURI.php @@ -6,10 +6,9 @@ namespace Friendica\Model; -use Friendica\BaseObject; use Friendica\Database\DBA; -class ItemURI extends BaseObject +class ItemURI { /** * @brief Insert an item-uri record and return its id diff --git a/src/Model/Nodeinfo.php b/src/Model/Nodeinfo.php index f6deb31bd5..29fa00aa19 100644 --- a/src/Model/Nodeinfo.php +++ b/src/Model/Nodeinfo.php @@ -2,7 +2,6 @@ namespace Friendica\Model; -use Friendica\BaseObject; use Friendica\Core\Addon; use Friendica\Database\DBA; use Friendica\DI; @@ -10,7 +9,7 @@ use Friendica\DI; /** * Model interaction for the nodeinfo */ -class Nodeinfo extends BaseObject +class Nodeinfo { /** * Updates the info about the current node diff --git a/src/Model/Notify.php b/src/Model/Notify.php index 842f9509cd..160d261b16 100644 --- a/src/Model/Notify.php +++ b/src/Model/Notify.php @@ -4,7 +4,6 @@ namespace Friendica\Model; use Exception; use Friendica\App; -use Friendica\BaseObject; use Friendica\Content\Text\BBCode; use Friendica\Content\Text\HTML; use Friendica\Core\Config\PConfiguration; @@ -26,7 +25,7 @@ use Friendica\Network\HTTPException; * @brief Methods for read and write notifications from/to database * or for formatting notifications */ -final class Notify extends BaseObject +final class Notify { /** @var int The default limit of notifies per page */ const DEFAULT_PAGE_LIMIT = 80; diff --git a/src/Model/PermissionSet.php b/src/Model/PermissionSet.php index c9a0697ebc..081ef21d85 100644 --- a/src/Model/PermissionSet.php +++ b/src/Model/PermissionSet.php @@ -4,13 +4,12 @@ */ namespace Friendica\Model; -use Friendica\BaseObject; use Friendica\Database\DBA; /** * @brief functions for interacting with the permission set of an object (item, photo, event, ...) */ -class PermissionSet extends BaseObject +class PermissionSet { /** * Fetch the id of a given permission set. Generate a new one when needed diff --git a/src/Model/Photo.php b/src/Model/Photo.php index 445e8a5e5c..af17cc395e 100644 --- a/src/Model/Photo.php +++ b/src/Model/Photo.php @@ -6,7 +6,6 @@ */ namespace Friendica\Model; -use Friendica\BaseObject; use Friendica\Core\Cache; use Friendica\Core\Config; use Friendica\Core\L10n; @@ -29,7 +28,7 @@ require_once "include/dba.php"; /** * Class to handle photo dabatase table */ -class Photo extends BaseObject +class Photo { /** * @brief Select rows from the photo table and returns them as array diff --git a/src/Model/Process.php b/src/Model/Process.php index f70b12ba7c..7c9f886dfa 100644 --- a/src/Model/Process.php +++ b/src/Model/Process.php @@ -4,14 +4,13 @@ */ namespace Friendica\Model; -use Friendica\BaseObject; use Friendica\Database\DBA; use Friendica\Util\DateTimeFormat; /** * @brief functions for interacting with a process */ -class Process extends BaseObject +class Process { /** * Insert a new process row. If the pid parameter is omitted, we use the current pid diff --git a/src/Model/Search.php b/src/Model/Search.php index 5829ff91d0..2c8349364c 100644 --- a/src/Model/Search.php +++ b/src/Model/Search.php @@ -2,13 +2,12 @@ namespace Friendica\Model; -use Friendica\BaseObject; use Friendica\Database\DBA; /** * Model for DB specific logic for the search entity */ -class Search extends BaseObject +class Search { /** * Returns the list of user defined tags (e.g. #Friendica) diff --git a/src/Model/TwoFactor/AppSpecificPassword.php b/src/Model/TwoFactor/AppSpecificPassword.php index 41b1e3bac4..f1ea9af916 100644 --- a/src/Model/TwoFactor/AppSpecificPassword.php +++ b/src/Model/TwoFactor/AppSpecificPassword.php @@ -2,7 +2,6 @@ namespace Friendica\Model\TwoFactor; -use Friendica\BaseObject; use Friendica\Database\DBA; use Friendica\Model\User; use Friendica\Util\DateTimeFormat; @@ -14,7 +13,7 @@ use PragmaRX\Random\Random; * * @package Friendica\Model */ -class AppSpecificPassword extends BaseObject +class AppSpecificPassword { public static function countForUser($uid) { diff --git a/src/Model/TwoFactor/RecoveryCode.php b/src/Model/TwoFactor/RecoveryCode.php index 676b538378..1690e04f9b 100644 --- a/src/Model/TwoFactor/RecoveryCode.php +++ b/src/Model/TwoFactor/RecoveryCode.php @@ -2,7 +2,6 @@ namespace Friendica\Model\TwoFactor; -use Friendica\BaseObject; use Friendica\Database\DBA; use Friendica\Util\DateTimeFormat; use PragmaRX\Random\Random; @@ -13,7 +12,7 @@ use PragmaRX\Recovery\Recovery; * * @package Friendica\Model */ -class RecoveryCode extends BaseObject +class RecoveryCode { /** * Returns the number of code the provided users can still use to replace a TOTP code diff --git a/src/Module/Admin/Summary.php b/src/Module/Admin/Summary.php index 4011fec1c7..25097d533e 100644 --- a/src/Module/Admin/Summary.php +++ b/src/Module/Admin/Summary.php @@ -81,8 +81,7 @@ class Summary extends BaseAdminModule if (Config::get('system', 'debugging')) { $file = Config::get('system', 'logfile'); - /** @var FileSystem $fileSystem */ - $fileSystem = self::getClass(FileSystem::class); + $fileSystem = DI::fs(); try { $stream = $fileSystem->createStream($file); diff --git a/src/Module/Api/Mastodon/FollowRequests.php b/src/Module/Api/Mastodon/FollowRequests.php index 739400eb77..a8d6cb52ea 100644 --- a/src/Module/Api/Mastodon/FollowRequests.php +++ b/src/Module/Api/Mastodon/FollowRequests.php @@ -3,10 +3,10 @@ namespace Friendica\Module\Api\Mastodon; use Friendica\Api\Mastodon; -use Friendica\App\BaseURL; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\Model\APContact; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Introduction; use Friendica\Module\Base\Api; @@ -104,8 +104,7 @@ class FollowRequests extends Api $base_query['limit'] = $limit; } - /** @var BaseURL $BaseURL */ - $BaseURL = self::getClass(BaseURL::class); + $BaseURL = DI::baseUrl(); $links = []; if ($count > $limit) { diff --git a/src/Module/Base/Api.php b/src/Module/Base/Api.php index 3a4e100897..b4cb39e15f 100644 --- a/src/Module/Base/Api.php +++ b/src/Module/Base/Api.php @@ -23,15 +23,15 @@ class Api extends BaseModule public static function init(array $parameters = []) { - $Arguments = self::getClass(Arguments::class); + $arguments = DI::args(); - if (substr($Arguments->getQueryString(), -4) === '.xml') { + if (substr($arguments->getQueryString(), -4) === '.xml') { self::$format = 'xml'; } - if (substr($Arguments->getQueryString(), -4) === '.rss') { + if (substr($arguments->getQueryString(), -4) === '.rss') { self::$format = 'rss'; } - if (substr($Arguments->getQueryString(), -4) === '.atom') { + if (substr($arguments->getQueryString(), -4) === '.atom') { self::$format = 'atom'; } } diff --git a/src/Module/BaseSearchModule.php b/src/Module/BaseSearchModule.php index 7c6760a8d1..0fa3eb5d63 100644 --- a/src/Module/BaseSearchModule.php +++ b/src/Module/BaseSearchModule.php @@ -65,8 +65,7 @@ class BaseSearchModule extends BaseModule $header = L10n::t('Forum Search - %s', $search); } - /** @var Arguments $args */ - $args = self::getClass(Arguments::class); + $args = DI::args(); $pager = new Pager($args->getQueryString()); if ($localSearch && empty($results)) { diff --git a/src/Module/Delegation.php b/src/Module/Delegation.php index a255ad3841..32d02a00e9 100644 --- a/src/Module/Delegation.php +++ b/src/Module/Delegation.php @@ -3,7 +3,6 @@ namespace Friendica\Module; use Friendica\BaseModule; -use Friendica\App\Authentication; use Friendica\Core\Hook; use Friendica\Core\L10n; use Friendica\Core\Renderer; @@ -81,9 +80,7 @@ class Delegation extends BaseModule Session::clear(); - /** @var Authentication $authentication */ - $authentication = self::getClass(Authentication::class); - $authentication->setForUser(DI::app(), $user, true, true); + DI::auth()->setForUser(DI::app(), $user, true, true); if ($limited_id) { Session::set('submanage', $original_id); diff --git a/src/Module/Diaspora/Receive.php b/src/Module/Diaspora/Receive.php index 72b060a848..4b6bb2a52e 100644 --- a/src/Module/Diaspora/Receive.php +++ b/src/Module/Diaspora/Receive.php @@ -6,6 +6,7 @@ use Friendica\App; use Friendica\BaseModule; use Friendica\Core\Config\Configuration; use Friendica\Core\L10n\L10n; +use Friendica\DI; use Friendica\Model\User; use Friendica\Network\HTTPException; use Friendica\Protocol\Diaspora; @@ -23,24 +24,18 @@ class Receive extends BaseModule public static function init(array $parameters = []) { - /** @var LoggerInterface $logger */ - self::$logger = self::getClass(LoggerInterface::class); + self::$logger = DI::logger(); } public static function post(array $parameters = []) { - /** @var Configuration $config */ - $config = self::getClass(Configuration::class); - - $enabled = $config->get('system', 'diaspora_enabled', false); + $enabled = DI::config()->get('system', 'diaspora_enabled', false); if (!$enabled) { self::$logger->info('Diaspora disabled.'); - $l10n = self::getClass(L10n::class); - throw new HTTPException\ForbiddenException($l10n->t('Access denied.')); + throw new HTTPException\ForbiddenException(DI::l10n()->t('Access denied.')); } - /** @var App\Arguments $args */ - $args = self::getClass(App\Arguments::class); + $args = DI::args(); $type = $args->get(1); diff --git a/src/Module/Item/Compose.php b/src/Module/Item/Compose.php index 78c4710a36..7a26c93cf0 100644 --- a/src/Module/Item/Compose.php +++ b/src/Module/Item/Compose.php @@ -63,8 +63,7 @@ class Compose extends BaseModule $user = User::getById(local_user(), ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'hidewall', 'default-location']); - /** @var ACLFormatter $aclFormatter */ - $aclFormatter = self::getClass(ACLFormatter::class); + $aclFormatter = DI::aclFormatter(); $contact_allow_list = $aclFormatter->expand($user['allow_cid']); $group_allow_list = $aclFormatter->expand($user['allow_gid']); diff --git a/src/Module/Item/Ignore.php b/src/Module/Item/Ignore.php index 75b2a7bd35..f59ba229c1 100644 --- a/src/Module/Item/Ignore.php +++ b/src/Module/Item/Ignore.php @@ -19,17 +19,14 @@ class Ignore extends BaseModule { public static function rawContent(array $parameters = []) { - /** @var L10n $l10n */ - $l10n = self::getClass(L10n::class); + $l10n = DI::l10n(); if (!Session::isAuthenticated()) { throw new HttpException\ForbiddenException($l10n->t('Access denied.')); } - /** @var App\Arguments $args */ - $args = self::getClass(App\Arguments::class); - /** @var Database $dba */ - $dba = self::getClass(Database::class); + $args = DI::args(); + $dba = DI::dba(); $message_id = intval($args->get(2)); diff --git a/src/Module/Notifications/Notify.php b/src/Module/Notifications/Notify.php index d95d9c0d8e..5200c59114 100644 --- a/src/Module/Notifications/Notify.php +++ b/src/Module/Notifications/Notify.php @@ -3,11 +3,9 @@ namespace Friendica\Module\Notifications; use Friendica\BaseModule; -use Friendica\BaseObject; use Friendica\Core\L10n; use Friendica\Core\System; use Friendica\DI; -use Friendica\Model\Notify as ModelNotify; use Friendica\Network\HTTPException; /** @@ -28,9 +26,7 @@ class Notify extends BaseModule // @TODO: Replace with parameter from router if ($a->argc > 2 && $a->argv[1] === 'mark' && $a->argv[2] === 'all') { - /** @var ModelNotify $notificationsManager */ - $notificationsManager = self::getClass(ModelNotify::class); - $success = $notificationsManager->setAllSeen(); + $success = DI::notify()->setAllSeen(); header('Content-type: application/json; charset=utf-8'); echo json_encode([ @@ -52,8 +48,7 @@ class Notify extends BaseModule // @TODO: Replace with parameter from router if ($a->argc > 2 && $a->argv[1] === 'view' && intval($a->argv[2])) { - /** @var ModelNotify $notificationsManager */ - $notificationsManager = BaseObject::getClass(ModelNotify::class); + $notificationsManager = DI::notify(); // @TODO: Replace with parameter from router $note = $notificationsManager->getByID($a->argv[2]); if (!empty($note)) { diff --git a/src/Module/Profile.php b/src/Module/Profile.php index eb8becfff5..0515d22e18 100644 --- a/src/Module/Profile.php +++ b/src/Module/Profile.php @@ -133,12 +133,9 @@ class Profile extends BaseModule $category = $datequery = $datequery2 = ''; - /** @var DateTimeFormat $dtFormat */ - $dtFormat = self::getClass(DateTimeFormat::class); - if ($a->argc > 2) { for ($x = 2; $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 { diff --git a/src/Module/Register.php b/src/Module/Register.php index df7a028166..d079c5c420 100644 --- a/src/Module/Register.php +++ b/src/Module/Register.php @@ -209,7 +209,7 @@ class Register extends BaseModule $user = $result['user']; - $base_url = self::getClass(BaseURL::class)->get(); + $base_url = DI::baseUrl()->get(); if ($netpublish && intval(Config::get('config', 'register_policy')) !== self::APPROVE) { $url = $base_url . '/profile/' . $user['nickname']; diff --git a/src/Module/Search/Index.php b/src/Module/Search/Index.php index 4e8a4c63c5..c53c6439c9 100644 --- a/src/Module/Search/Index.php +++ b/src/Module/Search/Index.php @@ -126,9 +126,7 @@ class Index extends BaseSearchModule // OR your own posts if you are a logged in member // No items will be shown if the member has a blocked profile wall. - /** @var Arguments $args */ - $args = self::getClass(Arguments::class); - $pager = new Pager($args->getQueryString()); + $pager = new Pager(DI::args()->getQueryString()); if ($tag) { Logger::info('Start tag search.', ['q' => $search]); diff --git a/src/Module/Search/Saved.php b/src/Module/Search/Saved.php index 80f84a927c..c2d60bc5a3 100644 --- a/src/Module/Search/Saved.php +++ b/src/Module/Search/Saved.php @@ -2,7 +2,6 @@ namespace Friendica\Module\Search; -use Friendica\App\Arguments; use Friendica\BaseModule; use Friendica\Core\L10n; use Friendica\Database\DBA; @@ -13,10 +12,7 @@ class Saved extends BaseModule { public static function init(array $parameters = []) { - /** @var Arguments $args */ - $args = self::getClass(Arguments::class); - - $action = $args->get(2, 'none'); + $action = DI::args()->get(2, 'none'); $search = Strings::escapeTags(trim(rawurldecode($_GET['term'] ?? ''))); $return_url = $_GET['return_url'] ?? 'search?q=' . urlencode($search); diff --git a/src/Module/Security/Login.php b/src/Module/Security/Login.php index 5de46903db..dc129e8f66 100644 --- a/src/Module/Security/Login.php +++ b/src/Module/Security/Login.php @@ -7,7 +7,6 @@ namespace Friendica\Module\Security; use Friendica\BaseModule; -use Friendica\App\Authentication; use Friendica\Core\Config; use Friendica\Core\Hook; use Friendica\Core\L10n; @@ -49,15 +48,11 @@ class Login extends BaseModule ) { $openid_url = trim(($_POST['openid_url'] ?? '') ?: $_POST['username']); - /** @var Authentication $authentication */ - $authentication = self::getClass(Authentication::class); - $authentication->withOpenId($openid_url, !empty($_POST['remember'])); + DI::auth()->withOpenId($openid_url, !empty($_POST['remember'])); } if (!empty($_POST['auth-params']) && $_POST['auth-params'] === 'login') { - /** @var Authentication $authentication */ - $authentication = self::getClass(Authentication::class); - $authentication->withPassword( + DI::auth()->withPassword( DI::app(), trim($_POST['username']), trim($_POST['password']), diff --git a/src/Module/Security/TwoFactor/Recovery.php b/src/Module/Security/TwoFactor/Recovery.php index b0f88fcfb7..9a6beb13ad 100644 --- a/src/Module/Security/TwoFactor/Recovery.php +++ b/src/Module/Security/TwoFactor/Recovery.php @@ -42,10 +42,7 @@ class Recovery extends BaseModule Session::set('2fa', true); notice(L10n::t('Remaining recovery codes: %d', RecoveryCode::countValidForUser(local_user()))); - // Resume normal login workflow - /** @var Authentication $authentication */ - $authentication = self::getClass(Authentication::class); - $authentication->setForUser($a, $a->user, true, true); + DI::auth()->setForUser($a, $a->user, true, true); } else { notice(L10n::t('Invalid code, please retry.')); } diff --git a/src/Module/Security/TwoFactor/Verify.php b/src/Module/Security/TwoFactor/Verify.php index 08545b061e..ff494d7ca0 100644 --- a/src/Module/Security/TwoFactor/Verify.php +++ b/src/Module/Security/TwoFactor/Verify.php @@ -40,9 +40,7 @@ class Verify extends BaseModule Session::set('2fa', $code); // Resume normal login workflow - /** @var Authentication $authentication */ - $authentication = self::getClass(Authentication::class); - $authentication->setForUser($a, $a->user, true, true); + DI::auth()->setForUser($a, $a->user, true, true); } else { self::$errors[] = L10n::t('Invalid code, please retry.'); } diff --git a/src/Module/Settings/Delegation.php b/src/Module/Settings/Delegation.php index 78730c3d63..43d4857463 100644 --- a/src/Module/Settings/Delegation.php +++ b/src/Module/Settings/Delegation.php @@ -55,8 +55,7 @@ class Delegation extends BaseSettingsModule throw new HTTPException\ForbiddenException(L10n::t('Permission denied.')); } - /** @var Arguments $args */ - $args = self::getClass(Arguments::class); + $args = DI::args(); // @TODO Replace with router-provided arguments $action = $args->get(2); diff --git a/src/Module/Settings/UserExport.php b/src/Module/Settings/UserExport.php index 643a5998e9..6c06f1133c 100644 --- a/src/Module/Settings/UserExport.php +++ b/src/Module/Settings/UserExport.php @@ -62,7 +62,7 @@ class UserExport extends BaseSettingsModule **/ public static function rawContent(array $parameters = []) { - $args = self::getClass(Arguments::class); + $args = DI::args(); if ($args->getArgc() == 3) { // @TODO Replace with router-provided arguments $action = $args->get(2); diff --git a/src/Network/FKOAuth1.php b/src/Network/FKOAuth1.php index da68410626..26b5637a62 100644 --- a/src/Network/FKOAuth1.php +++ b/src/Network/FKOAuth1.php @@ -4,10 +4,7 @@ */ namespace Friendica\Network; -use Friendica\BaseObject; -use Friendica\App\Authentication; use Friendica\Core\Logger; -use Friendica\Core\Session; use Friendica\Database\DBA; use Friendica\DI; use OAuthServer; @@ -47,8 +44,6 @@ class FKOAuth1 extends OAuthServer die('This api requires login'); } - /** @var Authentication $authentication */ - $authentication = BaseObject::getClass(Authentication::class); - $authentication->setForUser($a, $record, true); + DI::auth()->setForUser($a, $record, true); } } diff --git a/src/Object/Post.php b/src/Object/Post.php index 7697346390..e5a66a562f 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -4,10 +4,8 @@ */ namespace Friendica\Object; -use Friendica\BaseObject; use Friendica\Content\ContactSelector; use Friendica\Content\Feature; -use Friendica\Content\Item as ContentItem; use Friendica\Core\Addon; use Friendica\Core\Config; use Friendica\Core\Hook; @@ -33,7 +31,7 @@ use Friendica\Util\Temporal; /** * An item */ -class Post extends BaseObject +class Post { private $data = []; private $template = null; @@ -344,10 +342,7 @@ class Post extends BaseObject $body = Item::prepareBody($item, true); - /** @var ContentItem $contItem */ - $contItem = self::getClass(ContentItem::class); - - list($categories, $folders) = $contItem->determineCategoriesTerms($item); + list($categories, $folders) = DI::contentItem()->determineCategoriesTerms($item); $body_e = $body; $text_e = strip_tags($body); @@ -551,8 +546,7 @@ class Post extends BaseObject return false; } - /** @var Activity $activity */ - $activity = self::getClass(Activity::class); + $activity = DI::activity(); /* * Only add what will be displayed diff --git a/src/Object/Thread.php b/src/Object/Thread.php index 35f155ee1c..f88dee2c41 100644 --- a/src/Object/Thread.php +++ b/src/Object/Thread.php @@ -4,7 +4,6 @@ */ namespace Friendica\Object; -use Friendica\BaseObject; use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\DI; @@ -16,7 +15,7 @@ use Friendica\Util\Security; * * We should think about making this a SPL Iterator */ -class Thread extends BaseObject +class Thread { private $parents = []; private $mode = null; diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 9bae638511..398ee3ae8f 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -4,7 +4,6 @@ */ namespace Friendica\Protocol\ActivityPub; -use Friendica\BaseObject; use Friendica\Content\Feature; use Friendica\Content\Text\BBCode; use Friendica\Content\Text\Plaintext; diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index f7a8f69390..c20f069567 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -11,7 +11,6 @@ namespace Friendica\Protocol; use DOMDocument; use DOMXPath; use Friendica\App\BaseURL; -use Friendica\BaseObject; use Friendica\Content\OEmbed; use Friendica\Content\Text\BBCode; use Friendica\Content\Text\HTML; @@ -21,6 +20,7 @@ use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Conversation; use Friendica\Model\Event; @@ -31,8 +31,6 @@ use Friendica\Model\PermissionSet; use Friendica\Model\Profile; use Friendica\Model\User; use Friendica\Network\Probe; -use Friendica\Object\Image; -use Friendica\Protocol\ActivityNamespace; use Friendica\Util\Crypto; use Friendica\Util\DateTimeFormat; use Friendica\Util\Images; @@ -2181,8 +2179,7 @@ class DFRN // The functions below are partly used by ostatus.php as well - where we have this variable $contact = Contact::selectFirst([], ['id' => $importer['id']]); - /** @var Activity $activity */ - $activity = BaseObject::getClass(Activity::class); + $activity = DI::activity(); // Big question: Do we need these functions? They were part of the "consume_feed" function. // This function once was responsible for DFRN and OStatus. diff --git a/src/Util/Images.php b/src/Util/Images.php index ec9179147c..7f31dd4383 100644 --- a/src/Util/Images.php +++ b/src/Util/Images.php @@ -2,7 +2,6 @@ namespace Friendica\Util; -use Friendica\BaseObject; use Friendica\Core\Cache; use Friendica\Core\Logger; use Friendica\Core\System; diff --git a/src/Util/Proxy.php b/src/Util/Proxy.php index 0c9c053d0a..dab08b18bb 100644 --- a/src/Util/Proxy.php +++ b/src/Util/Proxy.php @@ -2,7 +2,6 @@ namespace Friendica\Util; -use Friendica\BaseObject; use Friendica\Core\Config; use Friendica\Core\System; use Friendica\DI; diff --git a/src/Util/Security.php b/src/Util/Security.php index 043c59d84f..a269ca88c1 100644 --- a/src/Util/Security.php +++ b/src/Util/Security.php @@ -5,7 +5,6 @@ namespace Friendica\Util; -use Friendica\BaseObject; use Friendica\Database\DBA; use Friendica\Model\Contact; use Friendica\Model\Group; @@ -15,7 +14,7 @@ use Friendica\Core\Session; /** * Secures that User is allow to do requests */ -class Security extends BaseObject +class Security { public static function canWriteToUserWall($owner) { diff --git a/src/Worker/APDelivery.php b/src/Worker/APDelivery.php index 812db57013..7ac1dfacaf 100644 --- a/src/Worker/APDelivery.php +++ b/src/Worker/APDelivery.php @@ -4,14 +4,13 @@ */ namespace Friendica\Worker; -use Friendica\BaseObject; use Friendica\Core\Logger; use Friendica\Core\Worker; use Friendica\Model\ItemDeliveryData; use Friendica\Protocol\ActivityPub; use Friendica\Util\HTTPSignature; -class APDelivery extends BaseObject +class APDelivery { /** * @brief Delivers ActivityPub messages diff --git a/src/Worker/Cron.php b/src/Worker/Cron.php index 1a72db53f5..f0c85f6686 100644 --- a/src/Worker/Cron.php +++ b/src/Worker/Cron.php @@ -4,7 +4,6 @@ */ namespace Friendica\Worker; -use Friendica\BaseObject; use Friendica\Core\Addon; use Friendica\Core\Config; use Friendica\Core\Hook; diff --git a/src/Worker/CronJobs.php b/src/Worker/CronJobs.php index 6c7154957f..e8553ed1c1 100644 --- a/src/Worker/CronJobs.php +++ b/src/Worker/CronJobs.php @@ -5,7 +5,6 @@ namespace Friendica\Worker; use Friendica\App; -use Friendica\BaseObject; use Friendica\Core\Cache; use Friendica\Core\Config; use Friendica\Core\Logger; diff --git a/src/Worker/DBUpdate.php b/src/Worker/DBUpdate.php index 84159eb433..5f7dfcb796 100644 --- a/src/Worker/DBUpdate.php +++ b/src/Worker/DBUpdate.php @@ -5,12 +5,11 @@ */ namespace Friendica\Worker; -use Friendica\BaseObject; use Friendica\Core\Config; use Friendica\Core\Update; use Friendica\DI; -class DBUpdate extends BaseObject +class DBUpdate { public static function execute() { diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index aebc74b185..ef5a7b9f20 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -4,7 +4,6 @@ */ namespace Friendica\Worker; -use Friendica\BaseObject; use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\Logger; @@ -21,7 +20,7 @@ use Friendica\Util\Strings; use Friendica\Util\Network; use Friendica\Core\Worker; -class Delivery extends BaseObject +class Delivery { const MAIL = 'mail'; const SUGGESTION = 'suggest'; diff --git a/src/Worker/Expire.php b/src/Worker/Expire.php index 16a68f6487..4abb6a2267 100644 --- a/src/Worker/Expire.php +++ b/src/Worker/Expire.php @@ -6,7 +6,6 @@ namespace Friendica\Worker; -use Friendica\BaseObject; use Friendica\Core\Config; use Friendica\Core\Hook; use Friendica\Core\Logger; diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 91de60ef61..d6bf0ef484 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -4,7 +4,6 @@ */ namespace Friendica\Worker; -use Friendica\BaseObject; use Friendica\Core\Config; use Friendica\Core\Hook; use Friendica\Core\Logger; @@ -279,8 +278,7 @@ class Notifier $public_message = false; // private recipients, not public } - /** @var ACLFormatter $aclFormatter */ - $aclFormatter = BaseObject::getClass(ACLFormatter::class); + $aclFormatter = DI::aclFormatter(); $allow_people = $aclFormatter->expand($parent['allow_cid']); $allow_groups = Group::expand($uid, $aclFormatter->expand($parent['allow_gid']),true); diff --git a/src/Worker/OnePoll.php b/src/Worker/OnePoll.php index f2ba89adf7..107bd34246 100644 --- a/src/Worker/OnePoll.php +++ b/src/Worker/OnePoll.php @@ -4,8 +4,6 @@ */ namespace Friendica\Worker; -use Friendica\BaseObject; -use Friendica\Content\Text\BBCode; use Friendica\Core\Config; use Friendica\Core\Logger; use Friendica\Core\PConfig; diff --git a/src/Worker/ProfileUpdate.php b/src/Worker/ProfileUpdate.php index b5ae51bd4b..8bc45ee33a 100644 --- a/src/Worker/ProfileUpdate.php +++ b/src/Worker/ProfileUpdate.php @@ -6,7 +6,6 @@ namespace Friendica\Worker; -use Friendica\BaseObject; use Friendica\Core\Logger; use Friendica\Core\Worker; use Friendica\DI; diff --git a/tests/Util/AppMockTrait.php b/tests/Util/AppMockTrait.php index f9b026979c..f9a9cb25de 100644 --- a/tests/Util/AppMockTrait.php +++ b/tests/Util/AppMockTrait.php @@ -4,8 +4,8 @@ namespace Friendica\Test\Util; use Dice\Dice; use Friendica\App; -use Friendica\BaseObject; use Friendica\Core\Config; +use Friendica\DI; use Friendica\Render\FriendicaSmartyEngine; use Friendica\Util\Profiler; use Mockery\MockInterface; @@ -109,7 +109,7 @@ trait AppMockTrait return $this->configMock->get('system', 'url'); }); - BaseObject::setDependencyInjection($this->dice); + DI::init($this->dice); if ($raw) { return; diff --git a/tests/include/ApiTest.php b/tests/include/ApiTest.php index 4c9db07089..dcd98fcce9 100644 --- a/tests/include/ApiTest.php +++ b/tests/include/ApiTest.php @@ -7,7 +7,6 @@ namespace Friendica\Test; use Dice\Dice; use Friendica\App; -use Friendica\BaseObject; use Friendica\Core\Config\Configuration; use Friendica\Core\Config\PConfiguration; use Friendica\Core\Protocol; @@ -65,7 +64,7 @@ class ApiTest extends DatabaseTest ->addRules(include __DIR__ . '/../../static/dependencies.config.php') ->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true]) ->addRule(ISession::class, ['instanceOf' => Session\Memory::class, 'shared' => true, 'call' => null]); - BaseObject::setDependencyInjection($this->dice); + DI::init($this->dice); /** @var Database $dba */ $dba = $this->dice->create(Database::class); @@ -116,8 +115,7 @@ class ApiTest extends DatabaseTest // User ID that we know is not in the database $this->wrongUserId = 666; - /** @var ISession $session */ - $session = BaseObject::getClass(ISession::class); + $session = DI::session(); $session->start(); // Most API require login so we force the session diff --git a/tests/src/Console/AutomaticInstallationConsoleTest.php b/tests/src/Console/AutomaticInstallationConsoleTest.php index 774db31746..050a5f4420 100644 --- a/tests/src/Console/AutomaticInstallationConsoleTest.php +++ b/tests/src/Console/AutomaticInstallationConsoleTest.php @@ -4,13 +4,13 @@ namespace Friendica\Test\src\Console; use Dice\Dice; use Friendica\App; -use Friendica\BaseObject; use Friendica\Console\AutomaticInstallation; use Friendica\Core\Config\Cache\ConfigCache; use Friendica\Core\Installer; use Friendica\Core\L10n\L10n; use Friendica\Core\Logger; use Friendica\Database\Database; +use Friendica\DI; use Friendica\Test\Util\DBAMockTrait; use Friendica\Test\Util\DBStructureMockTrait; use Friendica\Test\Util\RendererMockTrait; @@ -77,7 +77,7 @@ class AutomaticInstallationConsoleTest extends ConsoleTest ->with(L10n::class) ->andReturn($l10nMock); - BaseObject::setDependencyInjection($this->dice); + DI::init($this->dice); $this->configCache = new ConfigCache(); $this->configCache->set('system', 'basepath', $this->root->url()); diff --git a/tests/src/Core/InstallerTest.php b/tests/src/Core/InstallerTest.php index 3b41e4739c..b2ef92b450 100644 --- a/tests/src/Core/InstallerTest.php +++ b/tests/src/Core/InstallerTest.php @@ -4,10 +4,9 @@ namespace Friendica\Core; use Dice\Dice; -use Friendica\BaseObject; use Friendica\Core\Config\Cache\ConfigCache; +use Friendica\DI; use Friendica\Network\CurlResult; -use Friendica\Object\Image; use Friendica\Test\MockedTest; use Friendica\Test\Util\VFSTrait; use Friendica\Util\Network; @@ -38,7 +37,7 @@ class InstallerTest extends MockedTest ->with(\Friendica\Core\L10n\L10n::class) ->andReturn($this->l10nMock); - BaseObject::setDependencyInjection($dice); + DI::init($dice); } private function mockL10nT(string $text, $times = null) diff --git a/tests/src/Core/Lock/SemaphoreLockTest.php b/tests/src/Core/Lock/SemaphoreLockTest.php index a2291b2c24..8a4baa4fa9 100644 --- a/tests/src/Core/Lock/SemaphoreLockTest.php +++ b/tests/src/Core/Lock/SemaphoreLockTest.php @@ -4,9 +4,9 @@ namespace Friendica\Test\src\Core\Lock; use Dice\Dice; use Friendica\App; -use Friendica\BaseObject; use Friendica\Core\Config\Configuration; use Friendica\Core\Lock\SemaphoreLock; +use Friendica\DI; class SemaphoreLockTest extends LockTest { @@ -26,7 +26,7 @@ class SemaphoreLockTest extends LockTest $dice->shouldReceive('create')->with(Configuration::class)->andReturn($configMock); // @todo Because "get_temppath()" is using static methods, we have to initialize the BaseObject - BaseObject::setDependencyInjection($dice); + DI::init($dice); parent::setUp(); } diff --git a/tests/src/Database/DBATest.php b/tests/src/Database/DBATest.php index 9b2a2f122b..15d438b679 100644 --- a/tests/src/Database/DBATest.php +++ b/tests/src/Database/DBATest.php @@ -2,10 +2,10 @@ namespace Friendica\Test\src\Database; use Dice\Dice; -use Friendica\BaseObject; use Friendica\Core\Config; use Friendica\Database\Database; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Test\DatabaseTest; use Friendica\Test\Util\Database\StaticDatabase; @@ -18,7 +18,7 @@ class DBATest extends DatabaseTest $dice = (new Dice()) ->addRules(include __DIR__ . '/../../../static/dependencies.config.php') ->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true]); - BaseObject::setDependencyInjection($dice); + DI::init($dice); // Default config Config::set('config', 'hostname', 'localhost'); diff --git a/tests/src/Database/DBStructureTest.php b/tests/src/Database/DBStructureTest.php index 38c621d4c8..b3f9fb208f 100644 --- a/tests/src/Database/DBStructureTest.php +++ b/tests/src/Database/DBStructureTest.php @@ -3,9 +3,9 @@ namespace Friendica\Test\src\Database; use Dice\Dice; -use Friendica\BaseObject; use Friendica\Database\Database; use Friendica\Database\DBStructure; +use Friendica\DI; use Friendica\Test\DatabaseTest; use Friendica\Test\Util\Database\StaticDatabase; @@ -18,7 +18,7 @@ class DBStructureTest extends DatabaseTest $dice = (new Dice()) ->addRules(include __DIR__ . '/../../../static/dependencies.config.php') ->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true]); - BaseObject::setDependencyInjection($dice); + DI::init($dice); } /** diff --git a/tests/src/Network/CurlResultTest.php b/tests/src/Network/CurlResultTest.php index 03e415a99b..7f2754a0e5 100644 --- a/tests/src/Network/CurlResultTest.php +++ b/tests/src/Network/CurlResultTest.php @@ -3,7 +3,7 @@ namespace Friendica\Test\src\Network; use Dice\Dice; -use Friendica\BaseObject; +use Friendica\DI; use Friendica\Network\CurlResult; use Mockery\MockInterface; use PHPUnit\Framework\TestCase; @@ -26,7 +26,7 @@ class CurlResultTest extends TestCase ->with(LoggerInterface::class) ->andReturn($logger); - BaseObject::setDependencyInjection($dice); + DI::init($dice); } /** From 2bb9e46be365bb60d82e00adf59b9c8e4515458d Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Sun, 15 Dec 2019 23:37:49 +0100 Subject: [PATCH 03/34] Optimize DI class (introduce method-mapping constant) --- mod/notifications.php | 1 + src/DI.php | 90 +++++++++++++++---------------------------- 2 files changed, 33 insertions(+), 58 deletions(-) diff --git a/mod/notifications.php b/mod/notifications.php index 51b4d80873..e083e3b44c 100644 --- a/mod/notifications.php +++ b/mod/notifications.php @@ -15,6 +15,7 @@ use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Module\Security\Login; +use Friendica\Model\Contact; use Friendica\Model\Introduction; use Friendica\Model\Notify; diff --git a/src/DI.php b/src/DI.php index efd29f9c0c..6b86bddb56 100644 --- a/src/DI.php +++ b/src/DI.php @@ -13,8 +13,7 @@ use Friendica\Database\Database; use Friendica\Model\Notify; use Friendica\Protocol\Activity; use Friendica\Util\ACLFormatter; -use Friendica\Content\Item as ContentItem; -use Friendica\Content\Text\BBCode\Video as BBCodeVideo; +use Friendica\Content; use Friendica\Util\DateTimeFormat; use Friendica\Util\FileSystem; use Friendica\Util\Logger\WorkerLogger; @@ -29,8 +28,8 @@ use Psr\Log\LoggerInterface; * @method static ACLFormatter aclFormatter() * @method static Notify notify() * @method static Activity activity() - * @method static ContentItem contentItem() - * @method static BBCodeVideo bbCodeVideo() + * @method static Content\Item contentItem() + * @method static Content\Text\BBCode\Video bbCodeVideo() * @method static DateTimeFormat dtFormat() * @method static ICache cache() * @method static Configuration config() @@ -54,6 +53,34 @@ use Psr\Log\LoggerInterface; */ class DI { + const CLASS_MAPPING = [ + 'app' => App::class, + 'aclFormatter' => ACLFormatter::class, + 'auth' => App\Authentication::class, + 'args' => App\Arguments::class, + 'baseUrl' => App\BaseURL::class, + 'mode' => App\Mode::class, + 'module' => App\Module::class, + 'page' => App\Page::class, + 'router' => App\Router::class, + 'notify' => Notify::class, + 'activity' => Activity::class, + 'contentItem' => Content\Item::class, + 'bbCodeVideo' => Content\Text\BBCode\Video::class, + 'dtFormat' => DateTimeFormat::class, + 'cache' => ICache::class, + 'config' => Configuration::class, + 'pConfig' => PConfiguration::class, + 'l10n' => L10n::class, + 'lock' => ILock::class, + 'logger' => LoggerInterface::class, + 'workerLogger' => WorkerLogger::class, + 'devLogger' => '$devLogger', + 'session' => ISession::class, + 'dba' => Database::class, + 'fs' => FileSystem::class, + ]; + /** @var Dice */ private static $dice; @@ -64,59 +91,6 @@ class DI public static function __callStatic($name, $arguments) { - switch ($name) { - case 'app': - return self::$dice->create(App::class, $arguments); - case 'aclFormatter': - return self::$dice->create(ACLFormatter::class, $arguments); - case 'auth': - return self::$dice->create(App\Authentication::class, $arguments); - case 'args': - return self::$dice->create(App\Arguments::class, $arguments); - case 'baseUrl': - return self::$dice->create(App\BaseURL::class, $arguments); - case 'mode': - return self::$dice->create(App\Mode::class, $arguments); - case 'module': - return self::$dice->create(App\Module::class, $arguments); - case 'page': - return self::$dice->create(App\Page::class, $arguments); - case 'router': - return self::$dice->create(App\Router::class, $arguments); - case 'notify': - return self::$dice->create(Notify::class, $arguments); - case 'activity': - return self::$dice->create(Activity::class, $arguments); - case 'contentItem': - return self::$dice->create(ContentItem::class, $arguments); - case 'bbCodeVideo': - return self::$dice->create(BBCodeVideo::class, $arguments); - case 'dtFormat': - return self::$dice->create(DateTimeFormat::class, $arguments); - case 'cache': - return self::$dice->create(ICache::class, $arguments); - case 'config': - return self::$dice->create(Configuration::class, $arguments); - case 'pConfig': - return self::$dice->create(PConfiguration::class, $arguments); - case 'lock': - return self::$dice->create(ILock::class, $arguments); - case 'l10n': - return self::$dice->create(L10n::class, $arguments); - case 'logger': - return self::$dice->create(LoggerInterface::class, $arguments); - case 'devLogger': - return self::$dice->create('$devLogger', $arguments); - case 'workerLogger': - return self::$dice->create(WorkerLogger::class, $arguments); - case 'session': - return self::$dice->create(ISession::class, $arguments); - case 'dba': - return self::$dice->create(Database::class, $arguments); - case 'fs': - return self::$dice->create(FileSystem::class, $arguments); - default: - return null; - } + return self::$dice->create(self::CLASS_MAPPING[$name], $arguments); } } From fceb4f3823c13675ffd2db8bea64af6aa7fc5406 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Sun, 15 Dec 2019 23:44:33 +0100 Subject: [PATCH 04/34] Refactor dynamic App::getConfig() to static DI::config() --- src/App.php | 10 ------- src/Core/Search.php | 5 ++-- src/Core/Worker.php | 2 +- src/Model/Nodeinfo.php | 2 +- src/Module/Admin/Summary.php | 2 +- src/Module/BaseSearchModule.php | 2 +- src/Module/Bookmarklet.php | 2 +- src/Module/Directory.php | 2 +- src/Module/Friendica.php | 4 +-- src/Module/Help.php | 2 +- src/Module/Home.php | 2 +- src/Module/Invite.php | 4 +-- src/Module/Maintenance.php | 4 +-- src/Module/Manifest.php | 3 +-- src/Module/NodeInfo.php | 38 +++++++++------------------ src/Module/Register.php | 2 +- src/Module/Security/Login.php | 2 +- src/Module/Statistics.php | 10 +++---- src/Module/Welcome.php | 2 +- src/Module/WellKnown/HostMeta.php | 2 +- src/Module/WellKnown/XSocialRelay.php | 2 +- 21 files changed, 38 insertions(+), 66 deletions(-) diff --git a/src/App.php b/src/App.php index 3ea7d05f0c..6f1045ada5 100644 --- a/src/App.php +++ b/src/App.php @@ -144,16 +144,6 @@ class App return $this->config->getCache(); } - /** - * Returns the current config of this node - * - * @return Configuration - */ - public function getConfig() - { - return $this->config; - } - /** * The basepath of this app * diff --git a/src/Core/Search.php b/src/Core/Search.php index c1c80091f0..ab06a51a7d 100644 --- a/src/Core/Search.php +++ b/src/Core/Search.php @@ -92,8 +92,7 @@ class Search */ public static function getContactsFromGlobalDirectory($search, $type = self::TYPE_ALL, $page = 1) { - $config = DI::app()->getConfig(); - $server = $config->get('system', 'directory', self::DEFAULT_DIRECTORY); + $server = DI::config()->get('system', 'directory', self::DEFAULT_DIRECTORY); $searchUrl = $server . '/search'; @@ -158,7 +157,7 @@ class Search */ public static function getContactsFromLocalDirectory($search, $type = self::TYPE_ALL, $start = 0, $itemPage = 80) { - $config = DI::app()->getConfig(); + $config = DI::config(); $diaspora = $config->get('system', 'diaspora_enabled') ? Protocol::DIASPORA : Protocol::DFRN; $ostatus = !$config->get('system', 'ostatus_disabled') ? Protocol::OSTATUS : Protocol::DFRN; diff --git a/src/Core/Worker.php b/src/Core/Worker.php index b451b11ca5..a87fef0771 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -1086,7 +1086,7 @@ class Worker $args = ['no_cron' => !$do_cron]; $a = get_app(); - $process = new Core\Process($a->getLogger(), $a->getMode(), $a->getConfig(), $a->getBasePath()); + $process = new Core\Process($a->getLogger(), $a->getMode(), DI::config(), $a->getBasePath()); $process->run($command, $args); // after spawning we have to remove the flag. diff --git a/src/Model/Nodeinfo.php b/src/Model/Nodeinfo.php index 29fa00aa19..58a9e45447 100644 --- a/src/Model/Nodeinfo.php +++ b/src/Model/Nodeinfo.php @@ -19,7 +19,7 @@ class Nodeinfo public static function update() { $app = DI::app(); - $config = $app->getConfig(); + $config = DI::config(); $logger = $app->getLogger(); // If the addon 'statistics_json' is enabled then disable it and activate nodeinfo. diff --git a/src/Module/Admin/Summary.php b/src/Module/Admin/Summary.php index 25097d533e..60b35289c9 100644 --- a/src/Module/Admin/Summary.php +++ b/src/Module/Admin/Summary.php @@ -115,7 +115,7 @@ class Summary extends BaseAdminModule $configCache = new Config\Cache\ConfigCache(); $configLoader->setupCache($configCache); $confBasepath = $configCache->get('system', 'basepath'); - $currBasepath = $a->getConfig()->get('system', 'basepath'); + $currBasepath = DI::config()->get('system', 'basepath'); if ($confBasepath !== $currBasepath || !is_dir($currBasepath)) { if (is_dir($confBasepath) && Config::set('system', 'basepath', $confBasepath)) { $a->getLogger()->info('Friendica\'s system.basepath was updated successfully.', [ diff --git a/src/Module/BaseSearchModule.php b/src/Module/BaseSearchModule.php index 0fa3eb5d63..efedca92af 100644 --- a/src/Module/BaseSearchModule.php +++ b/src/Module/BaseSearchModule.php @@ -35,7 +35,7 @@ class BaseSearchModule extends BaseModule public static function performContactSearch($search, $prefix = '') { $a = DI::app(); - $config = $a->getConfig(); + $config = DI::config(); $type = Search::TYPE_ALL; diff --git a/src/Module/Bookmarklet.php b/src/Module/Bookmarklet.php index bae0e7c4d4..93f790a37d 100644 --- a/src/Module/Bookmarklet.php +++ b/src/Module/Bookmarklet.php @@ -21,7 +21,7 @@ class Bookmarklet extends BaseModule $_GET['mode'] = 'minimal'; $app = DI::app(); - $config = $app->getConfig(); + $config = DI::config(); if (!local_user()) { $output = '

' . L10n::t('Login') . '

'; diff --git a/src/Module/Directory.php b/src/Module/Directory.php index e38810e8ec..4ad9438fb9 100644 --- a/src/Module/Directory.php +++ b/src/Module/Directory.php @@ -25,7 +25,7 @@ class Directory extends BaseModule public static function content(array $parameters = []) { $app = DI::app(); - $config = $app->getConfig(); + $config = DI::config(); if (($config->get('system', 'block_public') && !Session::isAuthenticated()) || ($config->get('system', 'block_local_dir') && !Session::isAuthenticated())) { diff --git a/src/Module/Friendica.php b/src/Module/Friendica.php index 2eb2940ed3..4f33fea43a 100644 --- a/src/Module/Friendica.php +++ b/src/Module/Friendica.php @@ -19,7 +19,7 @@ class Friendica extends BaseModule public static function content(array $parameters = []) { $app = DI::app(); - $config = $app->getConfig(); + $config = DI::config(); $visibleAddonList = Addon::getVisibleList(); if (!empty($visibleAddonList)) { @@ -98,7 +98,7 @@ class Friendica extends BaseModule return; } - $config = $app->getConfig(); + $config = DI::config(); $register_policies = [ Register::CLOSED => 'REGISTER_CLOSED', diff --git a/src/Module/Help.php b/src/Module/Help.php index 0ff4cc68b0..7c1ecd7465 100644 --- a/src/Module/Help.php +++ b/src/Module/Help.php @@ -23,7 +23,7 @@ class Help extends BaseModule $filename = ''; $a = DI::app(); - $config = $a->getConfig(); + $config = DI::config(); $lang = $config->get('system', 'language'); // @TODO: Replace with parameter from router diff --git a/src/Module/Home.php b/src/Module/Home.php index eb122b0527..f5032f7c30 100644 --- a/src/Module/Home.php +++ b/src/Module/Home.php @@ -17,7 +17,7 @@ class Home extends BaseModule public static function content(array $parameters = []) { $app = DI::app(); - $config = $app->getConfig(); + $config = DI::config(); // currently no returned data is used $ret = []; diff --git a/src/Module/Invite.php b/src/Module/Invite.php index 9261ea703c..52d9bbcea3 100644 --- a/src/Module/Invite.php +++ b/src/Module/Invite.php @@ -26,7 +26,7 @@ class Invite extends BaseModule self::checkFormSecurityTokenRedirectOnError('/', 'send_invite'); $app = DI::app(); - $config = $app->getConfig(); + $config = DI::config(); $max_invites = intval($config->get('system', 'max_invites')); if (!$max_invites) { @@ -112,7 +112,7 @@ class Invite extends BaseModule } $app = DI::app(); - $config = $app->getConfig(); + $config = DI::config(); $inviteOnly = false; diff --git a/src/Module/Maintenance.php b/src/Module/Maintenance.php index 35a6df6295..bee9ab53f5 100644 --- a/src/Module/Maintenance.php +++ b/src/Module/Maintenance.php @@ -17,9 +17,7 @@ class Maintenance extends BaseModule { public static function content(array $parameters = []) { - $config = DI::app()->getConfig(); - - $reason = $config->get('system', 'maintenance_reason'); + $reason = DI::config()->get('system', 'maintenance_reason'); if ((substr(Strings::normaliseLink($reason), 0, 7) === 'http://') || (substr(Strings::normaliseLink($reason), 0, 8) === 'https://')) { diff --git a/src/Module/Manifest.php b/src/Module/Manifest.php index de1dfc9150..a7ef344e4d 100644 --- a/src/Module/Manifest.php +++ b/src/Module/Manifest.php @@ -10,8 +10,7 @@ class Manifest extends BaseModule { public static function rawContent(array $parameters = []) { - $app = DI::app(); - $config = $app->getConfig(); + $config = DI::config(); $tpl = Renderer::getMarkupTemplate('manifest.tpl'); diff --git a/src/Module/NodeInfo.php b/src/Module/NodeInfo.php index 5c5b573b22..a62687de1b 100644 --- a/src/Module/NodeInfo.php +++ b/src/Module/NodeInfo.php @@ -2,10 +2,8 @@ namespace Friendica\Module; -use Friendica\App; use Friendica\BaseModule; use Friendica\Core\Addon; -use Friendica\Core\System; use Friendica\DI; /** @@ -16,12 +14,10 @@ class NodeInfo extends BaseModule { public static function rawContent(array $parameters = []) { - $app = DI::app(); - if ($parameters['version'] == '1.0') { - self::printNodeInfo1($app); + self::printNodeInfo1(); } elseif ($parameters['version'] == '2.0') { - self::printNodeInfo2($app); + self::printNodeInfo2(); } else { throw new \Friendica\Network\HTTPException\NotFoundException(); } @@ -30,13 +26,11 @@ class NodeInfo extends BaseModule /** * Return the supported services * - * @param App $app - * * @return array with supported services */ - private static function getUsage(App $app) + private static function getUsage() { - $config = $app->getConfig(); + $config = DI::config(); $usage = []; @@ -56,11 +50,9 @@ class NodeInfo extends BaseModule /** * Return the supported services * - * @param App $app - * * @return array with supported services */ - private static function getServices(App $app) + private static function getServices() { $services = [ 'inbound' => [], @@ -117,12 +109,10 @@ class NodeInfo extends BaseModule /** * Print the nodeinfo version 1 - * - * @param App $app */ - private static function printNodeInfo1(App $app) + private static function printNodeInfo1() { - $config = $app->getConfig(); + $config = DI::config(); $nodeinfo = [ 'version' => '1.0', @@ -156,9 +146,9 @@ class NodeInfo extends BaseModule $nodeinfo['protocols']['outbound'][] = 'gnusocial'; } - $nodeinfo['usage'] = self::getUsage($app); + $nodeinfo['usage'] = self::getUsage(); - $nodeinfo['services'] = self::getServices($app); + $nodeinfo['services'] = self::getServices(); $nodeinfo['metadata']['protocols'] = $nodeinfo['protocols']; $nodeinfo['metadata']['protocols']['outbound'][] = 'atom1.0'; @@ -180,12 +170,10 @@ class NodeInfo extends BaseModule /** * Print the nodeinfo version 2 - * - * @param App $app */ - private static function printNodeInfo2(App $app) + private static function printNodeInfo2() { - $config = $app->getConfig(); + $config = DI::config(); $imap = (function_exists('imap_open') && !$config->get('system', 'imap_disabled') && !$config->get('system', 'dfrn_only')); @@ -212,9 +200,9 @@ class NodeInfo extends BaseModule $nodeinfo['protocols'][] = 'ostatus'; } - $nodeinfo['usage'] = self::getUsage($app); + $nodeinfo['usage'] = self::getUsage(); - $nodeinfo['services'] = self::getServices($app); + $nodeinfo['services'] = self::getServices(); if (Addon::isEnabled('twitter')) { $nodeinfo['services']['inbound'][] = 'twitter'; diff --git a/src/Module/Register.php b/src/Module/Register.php index d079c5c420..9a6df2f634 100644 --- a/src/Module/Register.php +++ b/src/Module/Register.php @@ -198,7 +198,7 @@ class Register extends BaseModule $arr['blocked'] = $blocked; $arr['verified'] = $verified; - $arr['language'] = L10nClass::detectLanguage($_SERVER, $_GET, $a->getConfig()->get('system', 'language')); + $arr['language'] = L10nClass::detectLanguage($_SERVER, $_GET, DI::config()->get('system', 'language')); try { $result = Model\User::create($arr); diff --git a/src/Module/Security/Login.php b/src/Module/Security/Login.php index dc129e8f66..a049abc882 100644 --- a/src/Module/Security/Login.php +++ b/src/Module/Security/Login.php @@ -88,7 +88,7 @@ class Login extends BaseModule } $reg = false; - if ($register && intval($a->getConfig()->get('config', 'register_policy')) !== Register::CLOSED) { + if ($register && intval(DI::config()->get('config', 'register_policy')) !== Register::CLOSED) { $reg = [ 'title' => L10n::t('Create a New Account'), 'desc' => L10n::t('Register'), diff --git a/src/Module/Statistics.php b/src/Module/Statistics.php index 1fe129011a..11cbdf53af 100644 --- a/src/Module/Statistics.php +++ b/src/Module/Statistics.php @@ -4,23 +4,21 @@ namespace Friendica\Module; use Friendica\BaseModule; use Friendica\Core\Addon; -use Friendica\Core\System; use Friendica\DI; +use Friendica\Network\HTTPException\NotFoundException; class Statistics extends BaseModule { public static function init(array $parameters = []) { - $config = DI::app()->getConfig(); - - if (!$config->get("system", "nodeinfo")) { - throw new \Friendica\Network\HTTPException\NotFoundException(); + if (!DI::config()->get("system", "nodeinfo")) { + throw new NotFoundException(); } } public static function rawContent(array $parameters = []) { - $config = DI::app()->getConfig(); + $config = DI::config(); $logger = DI::app()->getLogger(); $registration_open = diff --git a/src/Module/Welcome.php b/src/Module/Welcome.php index e62c5a62db..6182146337 100644 --- a/src/Module/Welcome.php +++ b/src/Module/Welcome.php @@ -14,7 +14,7 @@ class Welcome extends BaseModule { public static function content(array $parameters = []) { - $config = DI::app()->getConfig(); + $config = DI::config(); $mail_disabled = ((function_exists('imap_open') && (!$config->get('system', 'imap_disabled')))); diff --git a/src/Module/WellKnown/HostMeta.php b/src/Module/WellKnown/HostMeta.php index 3b03567d71..aec95c2a27 100644 --- a/src/Module/WellKnown/HostMeta.php +++ b/src/Module/WellKnown/HostMeta.php @@ -17,7 +17,7 @@ class HostMeta extends BaseModule public static function rawContent(array $parameters = []) { $app = DI::app(); - $config = $app->getConfig(); + $config = DI::config(); header('Content-type: text/xml'); diff --git a/src/Module/WellKnown/XSocialRelay.php b/src/Module/WellKnown/XSocialRelay.php index 2ddac3836d..38a9e12435 100644 --- a/src/Module/WellKnown/XSocialRelay.php +++ b/src/Module/WellKnown/XSocialRelay.php @@ -15,7 +15,7 @@ class XSocialRelay extends BaseModule public static function rawContent(array $parameters = []) { $app = DI::app(); - $config = $app->getConfig(); + $config = DI::config(); $subscribe = $config->get('system', 'relay_subscribe', false); From e2b2778e0ab04edd649690b8f89e16909f0b624f Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Sun, 15 Dec 2019 23:46:56 +0100 Subject: [PATCH 05/34] Refactor dynamic App::getLogger() to static DI::logger() --- include/api.php | 2 +- src/App.php | 10 ---------- src/App/Authentication.php | 2 +- src/Core/Worker.php | 4 ++-- src/Model/Nodeinfo.php | 3 +-- src/Module/Admin/Summary.php | 6 +++--- src/Module/Filer/RemoveTag.php | 2 +- src/Module/Filer/SaveTag.php | 2 +- src/Module/Statistics.php | 2 +- 9 files changed, 11 insertions(+), 22 deletions(-) diff --git a/include/api.php b/include/api.php index 363a0b9700..12f5dcb8ab 100644 --- a/include/api.php +++ b/include/api.php @@ -328,7 +328,7 @@ function api_call(App $a) Logger::info(API_LOG_PREFIX . 'username {username}', ['module' => 'api', 'action' => 'call', 'username' => $a->user['username'], 'duration' => round($duration, 2)]); - $a->getProfiler()->saveLog($a->getLogger(), API_LOG_PREFIX . 'performance'); + $a->getProfiler()->saveLog(DI::logger(), API_LOG_PREFIX . 'performance'); if (false === $return) { /* diff --git a/src/App.php b/src/App.php index 6f1045ada5..ac0f45f9b5 100644 --- a/src/App.php +++ b/src/App.php @@ -155,16 +155,6 @@ class App return $this->config->getCache()->get('system', 'basepath'); } - /** - * The Logger of this app - * - * @return LoggerInterface - */ - public function getLogger() - { - return $this->logger; - } - /** * The profiler of this app * diff --git a/src/App/Authentication.php b/src/App/Authentication.php index b88690415c..b1424e0fd6 100644 --- a/src/App/Authentication.php +++ b/src/App/Authentication.php @@ -351,7 +351,7 @@ class Authentication * The week ensures that sessions will expire after some inactivity. */; if ($this->session->get('remember')) { - $a->getLogger()->info('Injecting cookie for remembered user ' . $user_record['nickname']); + $this->logger->info('Injecting cookie for remembered user ' . $user_record['nickname']); $this->cookie->set($user_record['uid'], $user_record['password'], $user_record['prvkey']); $this->session->remove('remember'); } diff --git a/src/Core/Worker.php b/src/Core/Worker.php index a87fef0771..d4a90dd196 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -443,7 +443,7 @@ class Worker Logger::info('Process done.', ['priority' => $queue["priority"], 'id' => $queue["id"], 'duration' => round($duration, 3)]); - $a->getProfiler()->saveLog($a->getLogger(), "ID " . $queue["id"] . ": " . $funcname); + $a->getProfiler()->saveLog(DI::logger(), "ID " . $queue["id"] . ": " . $funcname); $cooldown = Config::get("system", "worker_cooldown", 0); @@ -1086,7 +1086,7 @@ class Worker $args = ['no_cron' => !$do_cron]; $a = get_app(); - $process = new Core\Process($a->getLogger(), $a->getMode(), DI::config(), $a->getBasePath()); + $process = new Core\Process(DI::logger(), $a->getMode(), DI::config(), $a->getBasePath()); $process->run($command, $args); // after spawning we have to remove the flag. diff --git a/src/Model/Nodeinfo.php b/src/Model/Nodeinfo.php index 58a9e45447..6d9c77154a 100644 --- a/src/Model/Nodeinfo.php +++ b/src/Model/Nodeinfo.php @@ -18,9 +18,8 @@ class Nodeinfo */ public static function update() { - $app = DI::app(); $config = DI::config(); - $logger = $app->getLogger(); + $logger = DI::logger(); // If the addon 'statistics_json' is enabled then disable it and activate nodeinfo. if (Addon::isEnabled('statistics_json')) { diff --git a/src/Module/Admin/Summary.php b/src/Module/Admin/Summary.php index 60b35289c9..d634b89fbf 100644 --- a/src/Module/Admin/Summary.php +++ b/src/Module/Admin/Summary.php @@ -118,7 +118,7 @@ class Summary extends BaseAdminModule $currBasepath = DI::config()->get('system', 'basepath'); if ($confBasepath !== $currBasepath || !is_dir($currBasepath)) { if (is_dir($confBasepath) && Config::set('system', 'basepath', $confBasepath)) { - $a->getLogger()->info('Friendica\'s system.basepath was updated successfully.', [ + DI::logger()->info('Friendica\'s system.basepath was updated successfully.', [ 'from' => $currBasepath, 'to' => $confBasepath, ]); @@ -126,7 +126,7 @@ class Summary extends BaseAdminModule $currBasepath, $confBasepath); } elseif (!is_dir($currBasepath)) { - $a->getLogger()->alert('Friendica\'s system.basepath is wrong.', [ + DI::logger()->alert('Friendica\'s system.basepath is wrong.', [ 'from' => $currBasepath, 'to' => $confBasepath, ]); @@ -134,7 +134,7 @@ class Summary extends BaseAdminModule $currBasepath, $confBasepath); } else { - $a->getLogger()->alert('Friendica\'s system.basepath is wrong.', [ + DI::logger()->alert('Friendica\'s system.basepath is wrong.', [ 'from' => $currBasepath, 'to' => $confBasepath, ]); diff --git a/src/Module/Filer/RemoveTag.php b/src/Module/Filer/RemoveTag.php index 65fd6cdf36..5ecaf4c2f9 100644 --- a/src/Module/Filer/RemoveTag.php +++ b/src/Module/Filer/RemoveTag.php @@ -20,7 +20,7 @@ class RemoveTag extends BaseModule } $app = DI::app(); - $logger = $app->getLogger(); + $logger = DI::logger(); $item_id = (($app->argc > 1) ? intval($app->argv[1]) : 0); diff --git a/src/Module/Filer/SaveTag.php b/src/Module/Filer/SaveTag.php index 1e19cdff19..9c0709db90 100644 --- a/src/Module/Filer/SaveTag.php +++ b/src/Module/Filer/SaveTag.php @@ -26,7 +26,7 @@ class SaveTag extends BaseModule public static function rawContent(array $parameters = []) { $a = DI::app(); - $logger = $a->getLogger(); + $logger = DI::logger(); $term = XML::unescape(trim($_GET['term'] ?? '')); // @TODO: Replace with parameter from router diff --git a/src/Module/Statistics.php b/src/Module/Statistics.php index 11cbdf53af..ce15426b8a 100644 --- a/src/Module/Statistics.php +++ b/src/Module/Statistics.php @@ -19,7 +19,7 @@ class Statistics extends BaseModule public static function rawContent(array $parameters = []) { $config = DI::config(); - $logger = DI::app()->getLogger(); + $logger = DI::logger(); $registration_open = intval($config->get('config', 'register_policy')) !== Register::CLOSED From 181529f3df152dd0fdb6d19a35c64d0ff158ffd2 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Sun, 15 Dec 2019 23:50:35 +0100 Subject: [PATCH 06/34] Refactor dynamic App::getProfiler() to static DI::profiler() --- include/api.php | 2 +- src/App.php | 10 ---------- src/Content/Text/BBCode.php | 6 +++--- src/Content/Text/Markdown.php | 2 +- src/Core/Addon.php | 2 +- src/Core/Renderer.php | 4 ++-- src/Core/Theme.php | 3 +-- src/Core/Worker.php | 4 ++-- src/DI.php | 3 +++ src/Object/Image.php | 5 ++--- src/Util/Images.php | 2 +- src/Util/Network.php | 9 +++++---- 12 files changed, 22 insertions(+), 30 deletions(-) diff --git a/include/api.php b/include/api.php index 12f5dcb8ab..d2b41f988d 100644 --- a/include/api.php +++ b/include/api.php @@ -328,7 +328,7 @@ function api_call(App $a) Logger::info(API_LOG_PREFIX . 'username {username}', ['module' => 'api', 'action' => 'call', 'username' => $a->user['username'], 'duration' => round($duration, 2)]); - $a->getProfiler()->saveLog(DI::logger(), API_LOG_PREFIX . 'performance'); + DI::profiler()->saveLog(DI::logger(), API_LOG_PREFIX . 'performance'); if (false === $return) { /* diff --git a/src/App.php b/src/App.php index ac0f45f9b5..6c88c6c947 100644 --- a/src/App.php +++ b/src/App.php @@ -155,16 +155,6 @@ class App return $this->config->getCache()->get('system', 'basepath'); } - /** - * The profiler of this app - * - * @return Profiler - */ - public function getProfiler() - { - return $this->profiler; - } - /** * Returns the Mode of the Application * diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 2619dc92cc..f7ca6efd97 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1104,7 +1104,7 @@ class BBCode @curl_exec($ch); $curl_info = @curl_getinfo($ch); - $a->getProfiler()->saveTimestamp($stamp1, "network", System::callstack()); + DI::profiler()->saveTimestamp($stamp1, "network", System::callstack()); if (substr($curl_info['content_type'], 0, 6) == 'image/') { $text = "[url=" . $match[1] . ']' . $match[1] . "[/url]"; @@ -1178,7 +1178,7 @@ class BBCode @curl_exec($ch); $curl_info = @curl_getinfo($ch); - $a->getProfiler()->saveTimestamp($stamp1, "network", System::callstack()); + DI::profiler()->saveTimestamp($stamp1, "network", System::callstack()); // if its a link to a picture then embed this picture if (substr($curl_info['content_type'], 0, 6) == 'image/') { @@ -2061,7 +2061,7 @@ class BBCode // Now convert HTML to Markdown $text = HTML::toMarkdown($text); - $a->getProfiler()->saveTimestamp($stamp1, "parser", System::callstack()); + DI::profiler()->saveTimestamp($stamp1, "parser", System::callstack()); // Libertree has a problem with escaped hashtags. $text = str_replace(['\#'], ['#'], $text); diff --git a/src/Content/Text/Markdown.php b/src/Content/Text/Markdown.php index 004f01beed..8d363675fc 100644 --- a/src/Content/Text/Markdown.php +++ b/src/Content/Text/Markdown.php @@ -43,7 +43,7 @@ class Markdown $html = $MarkdownParser->transform($text); - DI::app()->getProfiler()->saveTimestamp($stamp1, "parser", System::callstack()); + DI::profiler()->saveTimestamp($stamp1, "parser", System::callstack()); return $html; } diff --git a/src/Core/Addon.php b/src/Core/Addon.php index 59e1ec7b96..252acd31f0 100644 --- a/src/Core/Addon.php +++ b/src/Core/Addon.php @@ -286,7 +286,7 @@ class Addon $stamp1 = microtime(true); $f = file_get_contents("addon/$addon/$addon.php"); - $a->getProfiler()->saveTimestamp($stamp1, "file", System::callstack()); + DI::profiler()->saveTimestamp($stamp1, "file", System::callstack()); $r = preg_match("|/\*.*\*/|msU", $f, $m); diff --git a/src/Core/Renderer.php b/src/Core/Renderer.php index c687a67283..8366d0db80 100644 --- a/src/Core/Renderer.php +++ b/src/Core/Renderer.php @@ -75,7 +75,7 @@ class Renderer exit(); } - $a->getProfiler()->saveTimestamp($stamp1, "rendering", System::callstack()); + DI::profiler()->saveTimestamp($stamp1, "rendering", System::callstack()); return $output; } @@ -102,7 +102,7 @@ class Renderer exit(); } - $a->getProfiler()->saveTimestamp($stamp1, "file", System::callstack()); + DI::profiler()->saveTimestamp($stamp1, "file", System::callstack()); return $template; } diff --git a/src/Core/Theme.php b/src/Core/Theme.php index dea3e20e64..a4dfe2f9fa 100644 --- a/src/Core/Theme.php +++ b/src/Core/Theme.php @@ -73,10 +73,9 @@ class Theme return $info; } - $a = \get_app(); $stamp1 = microtime(true); $theme_file = file_get_contents("view/theme/$theme/theme.php"); - $a->getProfiler()->saveTimestamp($stamp1, "file", System::callstack()); + DI::profiler()->saveTimestamp($stamp1, "file", System::callstack()); $result = preg_match("|/\*.*\*/|msU", $theme_file, $matches); diff --git a/src/Core/Worker.php b/src/Core/Worker.php index d4a90dd196..fc30ce12d5 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -386,7 +386,7 @@ class Worker // We use the callstack here to analyze the performance of executed worker entries. // For this reason the variables have to be initialized. - $a->getProfiler()->reset(); + DI::profiler()->reset(); $a->queue = $queue; @@ -443,7 +443,7 @@ class Worker Logger::info('Process done.', ['priority' => $queue["priority"], 'id' => $queue["id"], 'duration' => round($duration, 3)]); - $a->getProfiler()->saveLog(DI::logger(), "ID " . $queue["id"] . ": " . $funcname); + DI::profiler()->saveLog(DI::logger(), "ID " . $queue["id"] . ": " . $funcname); $cooldown = Config::get("system", "worker_cooldown", 0); diff --git a/src/DI.php b/src/DI.php index 6b86bddb56..89b638d226 100644 --- a/src/DI.php +++ b/src/DI.php @@ -17,6 +17,7 @@ use Friendica\Content; use Friendica\Util\DateTimeFormat; use Friendica\Util\FileSystem; use Friendica\Util\Logger\WorkerLogger; +use Friendica\Util\Profiler; use Psr\Log\LoggerInterface; /** @@ -39,6 +40,7 @@ use Psr\Log\LoggerInterface; * @method static LoggerInterface logger() * @method static LoggerInterface devLogger() * @method static LoggerInterface workerLogger() + * @method static Profiler profiler() * @method static ISession session() * @method static App\Authentication auth() * @method static App\Arguments args() @@ -79,6 +81,7 @@ class DI 'session' => ISession::class, 'dba' => Database::class, 'fs' => FileSystem::class, + 'profiler' => Profiler::class, ]; /** @var Dice */ diff --git a/src/Object/Image.php b/src/Object/Image.php index 972b48359f..e25afd5e90 100644 --- a/src/Object/Image.php +++ b/src/Object/Image.php @@ -8,6 +8,7 @@ namespace Friendica\Object; use Exception; use Friendica\Core\Config; use Friendica\Core\System; +use Friendica\DI; use Friendica\Util\Images; use Imagick; use ImagickPixel; @@ -607,11 +608,9 @@ class Image $string = $this->asString(); - $a = \get_app(); - $stamp1 = microtime(true); file_put_contents($path, $string); - $a->getProfiler()->saveTimestamp($stamp1, "file", System::callstack()); + DI::profiler()->saveTimestamp($stamp1, "file", System::callstack()); } /** diff --git a/src/Util/Images.php b/src/Util/Images.php index 7f31dd4383..e19304bba1 100644 --- a/src/Util/Images.php +++ b/src/Util/Images.php @@ -165,7 +165,7 @@ class Images $stamp1 = microtime(true); file_put_contents($tempfile, $img_str); - DI::app()->getProfiler()->saveTimestamp($stamp1, "file", System::callstack()); + DI::profiler()->saveTimestamp($stamp1, "file", System::callstack()); $data = getimagesize($tempfile); unlink($tempfile); diff --git a/src/Util/Network.php b/src/Util/Network.php index f222dc22df..b19c8af504 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -10,6 +10,7 @@ use Friendica\Core\Config; use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\Core\System; +use Friendica\DI; use Friendica\Network\CurlResult; class Network @@ -233,7 +234,7 @@ class Network @curl_close($ch); - $a->getProfiler()->saveTimestamp($stamp1, 'network', System::callstack()); + DI::profiler()->saveTimestamp($stamp1, 'network', System::callstack()); return $curlResponse; } @@ -325,7 +326,7 @@ class Network curl_close($ch); - $a->getProfiler()->saveTimestamp($stamp1, 'network', System::callstack()); + DI::profiler()->saveTimestamp($stamp1, 'network', System::callstack()); // Very old versions of Lighttpd don't like the "Expect" header, so we remove it when needed if ($curlResponse->getReturnCode() == 417) { @@ -654,7 +655,7 @@ class Network $http_code = $curl_info['http_code']; curl_close($ch); - $a->getProfiler()->saveTimestamp($stamp1, "network", System::callstack()); + DI::profiler()->saveTimestamp($stamp1, "network", System::callstack()); if ($http_code == 0) { return $url; @@ -696,7 +697,7 @@ class Network $body = curl_exec($ch); curl_close($ch); - $a->getProfiler()->saveTimestamp($stamp1, "network", System::callstack()); + DI::profiler()->saveTimestamp($stamp1, "network", System::callstack()); if (trim($body) == "") { return $url; From 9cec293cccf730a02ef2bc5d57b87a6cba44ea5e Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Sun, 15 Dec 2019 23:52:15 +0100 Subject: [PATCH 07/34] Refactor dynamic App::getMode() to static DI::mode() --- bin/daemon.php | 7 ++++--- bin/worker.php | 9 +++++---- src/App.php | 10 ---------- src/Core/Worker.php | 4 ++-- src/Module/Admin/Summary.php | 2 +- src/Module/Install.php | 2 +- 6 files changed, 13 insertions(+), 21 deletions(-) diff --git a/bin/daemon.php b/bin/daemon.php index 039a40cf06..f0154e74e8 100755 --- a/bin/daemon.php +++ b/bin/daemon.php @@ -12,6 +12,7 @@ use Friendica\Core\Config; use Friendica\Core\Logger; use Friendica\Core\Worker; use Friendica\Database\DBA; +use Friendica\DI; use Psr\Log\LoggerInterface; // Get options @@ -36,10 +37,10 @@ require dirname(__DIR__) . '/vendor/autoload.php'; $dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php'); $dice = $dice->addRule(LoggerInterface::class,['constructParams' => ['daemon']]); -\Friendica\DI::init($dice); -$a = \Friendica\DI::app(); +DI::init($dice); +$a = DI::app(); -if ($a->getMode()->isInstall()) { +if (DI::mode()->isInstall()) { die("Friendica isn't properly installed yet.\n"); } diff --git a/bin/worker.php b/bin/worker.php index e156170490..a478159195 100755 --- a/bin/worker.php +++ b/bin/worker.php @@ -10,6 +10,7 @@ use Friendica\App; use Friendica\Core\Config; use Friendica\Core\Update; use Friendica\Core\Worker; +use Friendica\DI; use Psr\Log\LoggerInterface; // Get options @@ -34,14 +35,14 @@ require dirname(__DIR__) . '/vendor/autoload.php'; $dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php'); $dice = $dice->addRule(LoggerInterface::class,['constructParams' => ['worker']]); -\Friendica\DI::init($dice); -$a = Friendica\DI::app(); +DI::init($dice); +$a = DI::app(); // Check the database structure and possibly fixes it -Update::check($a->getBasePath(), true, $a->getMode()); +Update::check($a->getBasePath(), true, DI::mode()); // Quit when in maintenance -if (!$a->getMode()->has(App\Mode::MAINTENANCEDISABLED)) { +if (!DI::mode()->has(App\Mode::MAINTENANCEDISABLED)) { return; } diff --git a/src/App.php b/src/App.php index 6c88c6c947..c0787a460e 100644 --- a/src/App.php +++ b/src/App.php @@ -155,16 +155,6 @@ class App return $this->config->getCache()->get('system', 'basepath'); } - /** - * Returns the Mode of the Application - * - * @return App\Mode The Application Mode - */ - public function getMode() - { - return $this->mode; - } - /** * Returns the Database of the Application * diff --git a/src/Core/Worker.php b/src/Core/Worker.php index fc30ce12d5..9a1570d72f 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -1086,7 +1086,7 @@ class Worker $args = ['no_cron' => !$do_cron]; $a = get_app(); - $process = new Core\Process(DI::logger(), $a->getMode(), DI::config(), $a->getBasePath()); + $process = new Core\Process(DI::logger(), DI::mode(), DI::config(), $a->getBasePath()); $process->run($command, $args); // after spawning we have to remove the flag. @@ -1129,7 +1129,7 @@ class Worker $priority = PRIORITY_MEDIUM; // Don't fork from frontend tasks by default - $dont_fork = Config::get("system", "worker_dont_fork", false) || !\get_app()->getMode()->isBackend(); + $dont_fork = Config::get("system", "worker_dont_fork", false) || !DI::mode()->isBackend(); $created = DateTimeFormat::utcNow(); $force_priority = false; diff --git a/src/Module/Admin/Summary.php b/src/Module/Admin/Summary.php index d634b89fbf..9853ce951b 100644 --- a/src/Module/Admin/Summary.php +++ b/src/Module/Admin/Summary.php @@ -111,7 +111,7 @@ class Summary extends BaseAdminModule } // check legacy basepath settings - $configLoader = new ConfigFileLoader($a->getBasePath(), $a->getMode()); + $configLoader = new ConfigFileLoader($a->getBasePath()); $configCache = new Config\Cache\ConfigCache(); $configLoader->setupCache($configCache); $confBasepath = $configCache->get('system', 'basepath'); diff --git a/src/Module/Install.php b/src/Module/Install.php index 107f83e77d..29fbdacbc0 100644 --- a/src/Module/Install.php +++ b/src/Module/Install.php @@ -51,7 +51,7 @@ class Install extends BaseModule { $a = DI::app(); - if (!$a->getMode()->isInstall()) { + if (!DI::mode()->isInstall()) { throw new HTTPException\ForbiddenException(); } From cc9b7bb14f14953baa7ffb6575ac92e086c9a40f Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Sun, 15 Dec 2019 23:52:47 +0100 Subject: [PATCH 08/34] Refactor dynamic App::getDBA() to static DI::dba() --- src/App.php | 10 ---------- src/Module/Install.php | 4 ++-- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/App.php b/src/App.php index c0787a460e..c0c3878538 100644 --- a/src/App.php +++ b/src/App.php @@ -155,16 +155,6 @@ class App return $this->config->getCache()->get('system', 'basepath'); } - /** - * Returns the Database of the Application - * - * @return Database - */ - public function getDBA() - { - return $this->database; - } - /** * @deprecated 2019.09 - use Page->registerStylesheet instead * @see Page::registerStylesheet() diff --git a/src/Module/Install.php b/src/Module/Install.php index 29fbdacbc0..228f4be44a 100644 --- a/src/Module/Install.php +++ b/src/Module/Install.php @@ -111,7 +111,7 @@ class Install extends BaseModule self::checkSetting($configCache, $_POST, 'database', 'database', ''); // If we cannot connect to the database, return to the previous step - if (!self::$installer->checkDB($a->getDBA())) { + if (!self::$installer->checkDB(DI::dba())) { self::$currentWizardStep = self::DATABASE_CONFIG; } @@ -135,7 +135,7 @@ class Install extends BaseModule self::checkSetting($configCache, $_POST, 'config', 'admin_email', ''); // If we cannot connect to the database, return to the Database config wizard - if (!self::$installer->checkDB($a->getDBA())) { + if (!self::$installer->checkDB(DI::dba())) { self::$currentWizardStep = self::DATABASE_CONFIG; return; } From 8e6973b774efeff5dd381e8984c22171c6a14c31 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Mon, 16 Dec 2019 00:28:31 +0100 Subject: [PATCH 09/34] Refactor deprecated App::internalRedirect() to DI::baseUrl()->redirect() --- include/items.php | 17 +++++----- mod/api.php | 3 +- mod/cal.php | 7 ++--- mod/dfrn_confirm.php | 5 +-- mod/dfrn_poll.php | 18 +++++------ mod/dfrn_request.php | 15 ++++----- mod/events.php | 11 ++++--- mod/follow.php | 15 ++++----- mod/item.php | 16 +++++----- mod/lostpass.php | 7 +++-- mod/message.php | 13 ++++---- mod/network.php | 6 ++-- mod/notifications.php | 7 ++--- mod/ostatus_subscribe.php | 3 +- mod/photos.php | 24 +++++++------- mod/profile_photo.php | 7 +++-- mod/profiles.php | 15 ++++----- mod/redir.php | 5 +-- mod/regmod.php | 5 +-- mod/removeme.php | 5 +-- mod/repair_ostatus.php | 3 +- mod/settings.php | 12 +++---- mod/suggest.php | 3 +- mod/tagrm.php | 17 +++++----- mod/uimport.php | 2 +- mod/unfollow.php | 19 ++++++------ mod/videos.php | 7 +++-- mod/wallmessage.php | 3 +- src/App.php | 31 +++++++------------ src/App/Authentication.php | 2 +- src/App/Module.php | 6 ++-- src/BaseModule.php | 2 +- src/Core/UserImport.php | 6 ++-- src/Model/Contact.php | 2 +- src/Module/Admin/Addons/Details.php | 10 +++--- src/Module/Admin/Addons/Index.php | 2 +- src/Module/Admin/Blocklist/Contact.php | 2 +- src/Module/Admin/Blocklist/Server.php | 2 +- src/Module/Admin/DBSync.php | 2 +- src/Module/Admin/Features.php | 2 +- src/Module/Admin/Item/Delete.php | 2 +- src/Module/Admin/Logs/Settings.php | 2 +- src/Module/Admin/Site.php | 10 +++--- src/Module/Admin/Themes/Details.php | 6 ++-- src/Module/Admin/Themes/Embed.php | 2 +- src/Module/Admin/Themes/Index.php | 2 +- src/Module/Admin/Tos.php | 2 +- src/Module/Admin/Users.php | 6 ++-- src/Module/Apps.php | 2 +- src/Module/BaseAdminModule.php | 2 +- src/Module/Contact.php | 27 ++++++++-------- src/Module/Debug/Feed.php | 2 +- src/Module/Delegation.php | 2 +- src/Module/Filer/RemoveTag.php | 2 +- src/Module/Filer/SaveTag.php | 2 +- src/Module/FollowConfirm.php | 4 +-- src/Module/Group.php | 16 +++++----- src/Module/Home.php | 4 +-- src/Module/Item/Ignore.php | 2 +- src/Module/Like.php | 2 +- src/Module/Notifications/Notify.php | 4 +-- src/Module/Objects.php | 2 +- src/Module/Pinned.php | 2 +- src/Module/RandomProfile.php | 2 +- src/Module/Register.php | 12 +++---- src/Module/Search/Saved.php | 2 +- src/Module/Security/Login.php | 4 +-- src/Module/Security/Logout.php | 2 +- src/Module/Security/TwoFactor/Recovery.php | 4 +-- src/Module/Security/TwoFactor/Verify.php | 4 +-- src/Module/Settings/Delegation.php | 8 ++--- src/Module/Settings/TwoFactor/AppSpecific.php | 12 +++---- src/Module/Settings/TwoFactor/Index.php | 10 +++--- src/Module/Settings/TwoFactor/Recovery.php | 6 ++-- src/Module/Settings/TwoFactor/Verify.php | 6 ++-- src/Module/Starred.php | 2 +- src/Module/Tos.php | 2 +- 77 files changed, 263 insertions(+), 259 deletions(-) diff --git a/include/items.php b/include/items.php index 5ae8558d81..e72b97c1d2 100644 --- a/include/items.php +++ b/include/items.php @@ -12,6 +12,7 @@ use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\Core\Session; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Item; use Friendica\Protocol\DFRN; use Friendica\Protocol\Feed; @@ -339,7 +340,7 @@ function drop_items(array $items) function drop_item($id, $return = '') { - $a = Friendica\DI::app(); + $a = DI::app(); // locate item to be deleted @@ -348,7 +349,7 @@ function drop_item($id, $return = '') if (!DBA::isResult($item)) { notice(L10n::t('Item not found.') . EOL); - $a->internalRedirect('network'); + DI::baseUrl()->redirect('network'); } if ($item['deleted']) { @@ -389,7 +390,7 @@ function drop_item($id, $return = '') } // Now check how the user responded to the confirmation query if (!empty($_REQUEST['canceled'])) { - $a->internalRedirect('display/' . $item['guid']); + DI::baseUrl()->redirect('display/' . $item['guid']); } $is_comment = ($item['gravity'] == GRAVITY_COMMENT) ? true : false; @@ -411,28 +412,28 @@ function drop_item($id, $return = '') if ($is_comment) { // Return to parent guid if (!empty($parentitem)) { - $a->internalRedirect('display/' . $parentitem['guid']); + DI::baseUrl()->redirect('display/' . $parentitem['guid']); //NOTREACHED } // In case something goes wrong else { - $a->internalRedirect('network'); + DI::baseUrl()->redirect('network'); //NOTREACHED } } else { // if unknown location or deleting top level post called from display if (empty($return_url) || strpos($return_url, 'display') !== false) { - $a->internalRedirect('network'); + DI::baseUrl()->redirect('network'); //NOTREACHED } else { - $a->internalRedirect($return_url); + DI::baseUrl()->redirect($return_url); //NOTREACHED } } } else { notice(L10n::t('Permission denied.') . EOL); - $a->internalRedirect('display/' . $item['guid']); + DI::baseUrl()->redirect('display/' . $item['guid']); //NOTREACHED } } diff --git a/mod/api.php b/mod/api.php index 929832480a..8ef9f5ec47 100644 --- a/mod/api.php +++ b/mod/api.php @@ -8,6 +8,7 @@ use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Module\Security\Login; require_once __DIR__ . '/../include/api.php'; @@ -76,7 +77,7 @@ function api_content(App $a) if (strstr($consumer->callback_url, $glue)) { $glue = "?"; } - $a->internalRedirect($consumer->callback_url . $glue . 'oauth_token=' . OAuthUtil::urlencode_rfc3986($params['oauth_token']) . '&oauth_verifier=' . OAuthUtil::urlencode_rfc3986($verifier)); + DI::baseUrl()->redirect($consumer->callback_url . $glue . 'oauth_token=' . OAuthUtil::urlencode_rfc3986($params['oauth_token']) . '&oauth_verifier=' . OAuthUtil::urlencode_rfc3986($verifier)); exit(); } diff --git a/mod/cal.php b/mod/cal.php index 51d17a10a4..5a4f0a9c51 100644 --- a/mod/cal.php +++ b/mod/cal.php @@ -16,12 +16,11 @@ use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\Core\Session; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Event; -use Friendica\Model\Group; use Friendica\Model\Item; use Friendica\Model\Profile; -use Friendica\Protocol\DFRN; use Friendica\Util\DateTimeFormat; use Friendica\Util\Temporal; @@ -289,7 +288,7 @@ function cal_content(App $a) // Respect the export feature setting for all other /cal pages if it's not the own profile if ((local_user() !== $owner_uid) && !Feature::isEnabled($owner_uid, "export_calendar")) { notice(L10n::t('Permission denied.') . EOL); - $a->internalRedirect('cal/' . $nick); + DI::baseUrl()->redirect('cal/' . $nick); } // Get the export data by uid @@ -310,7 +309,7 @@ function cal_content(App $a) $return_path = "cal/" . $nick; } - $a->internalRedirect($return_path); + DI::baseUrl()->redirect($return_path); } // If nothing went wrong we can echo the export content diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php index c92e5493a1..d9ba9dfac5 100644 --- a/mod/dfrn_confirm.php +++ b/mod/dfrn_confirm.php @@ -24,6 +24,7 @@ use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Group; use Friendica\Model\User; @@ -331,7 +332,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) // Let's send our user to the contact editor in case they want to // do anything special with this new friend. if ($handsfree === null) { - $a->internalRedirect('contact/' . intval($contact_id)); + DI::baseUrl()->redirect('contact/' . intval($contact_id)); } else { return; } @@ -551,6 +552,6 @@ function dfrn_confirm_post(App $a, $handsfree = null) } // somebody arrived here by mistake or they are fishing. Send them to the homepage. - $a->internalRedirect(); + DI::baseUrl()->redirect(); // NOTREACHED } diff --git a/mod/dfrn_poll.php b/mod/dfrn_poll.php index 7ebca9effa..002ddf924b 100644 --- a/mod/dfrn_poll.php +++ b/mod/dfrn_poll.php @@ -91,7 +91,7 @@ function dfrn_poll_init(App $a) $my_id = '0:' . $dfrn_id; break; default: - $a->internalRedirect(); + DI::baseUrl()->redirect(); break; // NOTREACHED } @@ -138,10 +138,10 @@ function dfrn_poll_init(App $a) if (!empty($destination_url)) { System::externalRedirect($destination_url); } else { - $a->internalRedirect('profile/' . $profile); + DI::baseUrl()->redirect('profile/' . $profile); } } - $a->internalRedirect(); + DI::baseUrl()->redirect(); } if ($type === 'profile-check' && $dfrn_version < 2.2) { @@ -325,7 +325,7 @@ function dfrn_poll_post(App $a) $sql_extra = sprintf(" AND `dfrn-id` = '%s' AND `duplex` = 1 ", DBA::escape($dfrn_id)); break; default: - $a->internalRedirect(); + DI::baseUrl()->redirect(); break; // NOTREACHED } @@ -445,7 +445,7 @@ function dfrn_poll_content(App $a) $my_id = '0:' . $dfrn_id; break; default: - $a->internalRedirect(); + DI::baseUrl()->redirect(); break; // NOTREACHED } @@ -541,18 +541,18 @@ function dfrn_poll_content(App $a) switch ($destination_url) { case 'profile': - $a->internalRedirect('profile/' . $profile . '?f=&tab=profile'); + DI::baseUrl()->redirect('profile/' . $profile . '?f=&tab=profile'); break; case 'photos': - $a->internalRedirect('photos/' . $profile); + DI::baseUrl()->redirect('photos/' . $profile); break; case 'status': case '': - $a->internalRedirect('profile/' . $profile); + DI::baseUrl()->redirect('profile/' . $profile); break; default: $appendix = (strstr($destination_url, '?') ? '&f=&redir=1' : '?f=&redir=1'); - $a->redirect($destination_url . $appendix); + DI::baseUrl()->redirect($destination_url . $appendix); break; } // NOTREACHED diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index 28845634ad..f7c9d9aafc 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -21,6 +21,7 @@ use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\Core\Session; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Group; use Friendica\Model\Profile; @@ -68,7 +69,7 @@ function dfrn_request_post(App $a) } if (!empty($_POST['cancel'])) { - $a->internalRedirect(); + DI::baseUrl()->redirect(); } /* @@ -194,14 +195,14 @@ function dfrn_request_post(App $a) } // (ignore reply, nothing we can do it failed) - $a->internalRedirect($forward_path); + DI::baseUrl()->redirect($forward_path); return; // NOTREACHED } } // invalid/bogus request notice(L10n::t('Unrecoverable protocol error.') . EOL); - $a->internalRedirect(); + DI::baseUrl()->redirect(); return; // NOTREACHED } @@ -334,19 +335,19 @@ function dfrn_request_post(App $a) $url = Network::isUrlValid($url); if (!$url) { notice(L10n::t('Invalid profile URL.') . EOL); - $a->internalRedirect($a->cmd); + DI::baseUrl()->redirect($a->cmd); return; // NOTREACHED } if (!Network::isUrlAllowed($url)) { notice(L10n::t('Disallowed profile URL.') . EOL); - $a->internalRedirect($a->cmd); + DI::baseUrl()->redirect($a->cmd); return; // NOTREACHED } if (Network::isUrlBlocked($url)) { notice(L10n::t('Blocked domain') . EOL); - $a->internalRedirect($a->cmd); + DI::baseUrl()->redirect($a->cmd); return; // NOTREACHED } @@ -354,7 +355,7 @@ function dfrn_request_post(App $a) if (!count($parms)) { notice(L10n::t('Profile location is not valid or does not contain profile information.') . EOL); - $a->internalRedirect($a->cmd); + DI::baseUrl()->redirect($a->cmd); } else { if (empty($parms['fn'])) { notice(L10n::t('Warning: profile location has no identifiable owner name.') . EOL); diff --git a/mod/events.php b/mod/events.php index 1a8eccde11..ddcac1bd15 100644 --- a/mod/events.php +++ b/mod/events.php @@ -15,6 +15,7 @@ use Friendica\Core\System; use Friendica\Core\Theme; use Friendica\Core\Worker; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Event; use Friendica\Model\Item; use Friendica\Model\Profile; @@ -123,7 +124,7 @@ function events_post(App $a) echo L10n::t('Event can not end before it has started.'); exit(); } - $a->internalRedirect($onerror_path); + DI::baseUrl()->redirect($onerror_path); } if (!$summary || ($start === DBA::NULL_DATETIME)) { @@ -132,7 +133,7 @@ function events_post(App $a) echo L10n::t('Event title and start time are required.'); exit(); } - $a->internalRedirect($onerror_path); + DI::baseUrl()->redirect($onerror_path); } $share = intval($_POST['share'] ?? 0); @@ -150,7 +151,7 @@ function events_post(App $a) if ($share) { - $aclFormatter = \Friendica\DI::aclFormatter(); + $aclFormatter = DI::aclFormatter(); $str_group_allow = $aclFormatter->toString($_POST['group_allow'] ?? ''); $str_contact_allow = $aclFormatter->toString($_POST['contact_allow'] ?? ''); @@ -205,7 +206,7 @@ function events_post(App $a) Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, $item_id); } - $a->internalRedirect('events'); + DI::baseUrl()->redirect('events'); } function events_content(App $a) @@ -578,6 +579,6 @@ function events_content(App $a) info(L10n::t('Event removed') . EOL); } - $a->internalRedirect('events'); + DI::baseUrl()->redirect('events'); } } diff --git a/mod/follow.php b/mod/follow.php index 31b92aa0dc..94db3ad38d 100644 --- a/mod/follow.php +++ b/mod/follow.php @@ -8,6 +8,7 @@ use Friendica\Core\L10n; use Friendica\Core\Protocol; use Friendica\Core\Renderer; use Friendica\Core\System; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Profile; use Friendica\Network\Probe; @@ -21,7 +22,7 @@ function follow_post(App $a) } if (isset($_REQUEST['cancel'])) { - $a->internalRedirect('contact'); + DI::baseUrl()->redirect('contact'); } $uid = local_user(); @@ -38,14 +39,14 @@ function follow_post(App $a) if ($result['message']) { notice($result['message']); } - $a->internalRedirect($return_path); + DI::baseUrl()->redirect($return_path); } elseif ($result['cid']) { - $a->internalRedirect('contact/' . $result['cid']); + DI::baseUrl()->redirect('contact/' . $result['cid']); } info(L10n::t('The contact could not be added.')); - $a->internalRedirect($return_path); + DI::baseUrl()->redirect($return_path); // NOTREACHED } @@ -55,7 +56,7 @@ function follow_content(App $a) if (!local_user()) { notice(L10n::t('Permission denied.')); - $a->internalRedirect($return_path); + DI::baseUrl()->redirect($return_path); // NOTREACHED } @@ -70,7 +71,7 @@ function follow_content(App $a) } if (!$url) { - $a->internalRedirect($return_path); + DI::baseUrl()->redirect($return_path); } $submit = L10n::t('Submit Request'); @@ -132,7 +133,7 @@ function follow_content(App $a) if (!$r) { notice(L10n::t('Permission denied.')); - $a->internalRedirect($return_path); + DI::baseUrl()->redirect($return_path); // NOTREACHED } diff --git a/mod/item.php b/mod/item.php index e20fb99521..9326bf60d9 100644 --- a/mod/item.php +++ b/mod/item.php @@ -125,7 +125,7 @@ function item_post(App $a) { if (!DBA::isResult($toplevel_item)) { notice(L10n::t('Unable to locate original post.') . EOL); if (!empty($_REQUEST['return'])) { - $a->internalRedirect($return_path); + DI::baseUrl()->redirect($return_path); } exit(); } @@ -173,7 +173,7 @@ function item_post(App $a) { notice(L10n::t('Permission denied.') . EOL); if (!empty($_REQUEST['return'])) { - $a->internalRedirect($return_path); + DI::baseUrl()->redirect($return_path); } exit(); @@ -327,7 +327,7 @@ function item_post(App $a) { } info(L10n::t('Empty post discarded.') . EOL); if (!empty($_REQUEST['return'])) { - $a->internalRedirect($return_path); + DI::baseUrl()->redirect($return_path); } exit(); } @@ -678,7 +678,7 @@ function item_post(App $a) { if (!empty($datarray['cancel'])) { Logger::log('mod_item: post cancelled by addon.'); if ($return_path) { - $a->internalRedirect($return_path); + DI::baseUrl()->redirect($return_path); } $json = ['cancel' => 1]; @@ -713,7 +713,7 @@ function item_post(App $a) { if (!empty($_REQUEST['return']) && strlen($return_path)) { Logger::log('return: ' . $return_path); - $a->internalRedirect($return_path); + DI::baseUrl()->redirect($return_path); } exit(); } @@ -733,14 +733,14 @@ function item_post(App $a) { if (!$post_id) { Logger::log("Item wasn't stored."); - $a->internalRedirect($return_path); + DI::baseUrl()->redirect($return_path); } $datarray = Item::selectFirst(Item::ITEM_FIELDLIST, ['id' => $post_id]); if (!DBA::isResult($datarray)) { Logger::log("Item with id ".$post_id." couldn't be fetched."); - $a->internalRedirect($return_path); + DI::baseUrl()->redirect($return_path); } // update filetags in pconfig @@ -855,7 +855,7 @@ function item_post_return($baseurl, $api_source, $return_path) } if ($return_path) { - $a->internalRedirect($return_path); + DI::baseUrl()->redirect($return_path); } $json = ['success' => 1]; diff --git a/mod/lostpass.php b/mod/lostpass.php index ecab0982c8..5d28143fea 100644 --- a/mod/lostpass.php +++ b/mod/lostpass.php @@ -10,6 +10,7 @@ use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\User; use Friendica\Util\DateTimeFormat; use Friendica\Util\Strings; @@ -18,14 +19,14 @@ function lostpass_post(App $a) { $loginame = Strings::escapeTags(trim($_POST['login-name'])); if (!$loginame) { - $a->internalRedirect(); + DI::baseUrl()->redirect(); } $condition = ['(`email` = ? OR `nickname` = ?) AND `verified` = 1 AND `blocked` = 0', $loginame, $loginame]; $user = DBA::selectFirst('user', ['uid', 'username', 'nickname', 'email', 'language'], $condition); if (!DBA::isResult($user)) { notice(L10n::t('No valid account found.') . EOL); - $a->internalRedirect(); + DI::baseUrl()->redirect(); } $pwdreset_token = Strings::getRandomName(12) . random_int(1000, 9999); @@ -77,7 +78,7 @@ function lostpass_post(App $a) 'body' => $body ]); - $a->internalRedirect(); + DI::baseUrl()->redirect(); } function lostpass_content(App $a) diff --git a/mod/message.php b/mod/message.php index 8efe825cd9..6944dfa679 100644 --- a/mod/message.php +++ b/mod/message.php @@ -13,6 +13,7 @@ use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Mail; use Friendica\Module\Security\Login; @@ -88,7 +89,7 @@ function message_post(App $a) $a->argc = 2; $a->argv[1] = 'new'; } else { - $a->internalRedirect($a->cmd . '/' . $ret); + DI::baseUrl()->redirect($a->cmd . '/' . $ret); } } @@ -156,7 +157,7 @@ function message_content(App $a) // Now check how the user responded to the confirmation query if (!empty($_REQUEST['canceled'])) { - $a->internalRedirect('message'); + DI::baseUrl()->redirect('message'); } $cmd = $a->argv[1]; @@ -164,7 +165,7 @@ function message_content(App $a) $message = DBA::selectFirst('mail', ['convid'], ['id' => $a->argv[2], 'uid' => local_user()]); if(!DBA::isResult($message)){ info(L10n::t('Conversation not found.') . EOL); - $a->internalRedirect('message'); + DI::baseUrl()->redirect('message'); } if (DBA::delete('mail', ['id' => $a->argv[2], 'uid' => local_user()])) { @@ -174,10 +175,10 @@ function message_content(App $a) $conversation = DBA::selectFirst('mail', ['id'], ['convid' => $message['convid'], 'uid' => local_user()]); if(!DBA::isResult($conversation)){ info(L10n::t('Conversation removed.') . EOL); - $a->internalRedirect('message'); + DI::baseUrl()->redirect('message'); } - $a->internalRedirect('message/' . $conversation['id'] ); + DI::baseUrl()->redirectinternalRedirect('message/' . $conversation['id'] ); } else { $r = q("SELECT `parent-uri`,`convid` FROM `mail` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($a->argv[2]), @@ -190,7 +191,7 @@ function message_content(App $a) info(L10n::t('Conversation removed.') . EOL); } } - $a->internalRedirect('message'); + DI::baseUrl()->redirect('message'); } } diff --git a/mod/network.php b/mod/network.php index 0376203401..14f70c9d65 100644 --- a/mod/network.php +++ b/mod/network.php @@ -128,7 +128,7 @@ function network_init(App $a) $redir_url = ($net_queries ? $net_baseurl . '?' . $net_queries : $net_baseurl); - $a->internalRedirect($redir_url); + DI::baseUrl()->redirect($redir_url); } } @@ -587,7 +587,7 @@ function networkThreadedView(App $a, $update, $parent) exit(); } notice(L10n::t('No such group') . EOL); - $a->internalRedirect('network/0'); + DI::baseUrl()->redirect('network/0'); // NOTREACHED } @@ -641,7 +641,7 @@ function networkThreadedView(App $a, $update, $parent) } } else { notice(L10n::t('Invalid contact.') . EOL); - $a->internalRedirect('network'); + DI::baseUrl()->redirect('network'); // NOTREACHED } } diff --git a/mod/notifications.php b/mod/notifications.php index e083e3b44c..7e1d2cff9e 100644 --- a/mod/notifications.php +++ b/mod/notifications.php @@ -17,12 +17,11 @@ use Friendica\DI; use Friendica\Module\Security\Login; use Friendica\Model\Contact; use Friendica\Model\Introduction; -use Friendica\Model\Notify; function notifications_post(App $a) { if (!local_user()) { - $a->internalRedirect(); + DI::baseUrl()->redirect(); } $request_id = (($a->argc > 1) ? $a->argv[1] : 0); @@ -45,7 +44,7 @@ function notifications_post(App $a) break; } - $a->internalRedirect('notifications/intros'); + DI::baseUrl()->redirect('notifications/intros'); } } @@ -113,7 +112,7 @@ function notifications_content(App $a) $notifs = $nm->getHomeList($show, $startrec, $perpage); // fallback - redirect to main page } else { - $a->internalRedirect('notifications'); + DI::baseUrl()->redirect('notifications'); } // Set the pager diff --git a/mod/ostatus_subscribe.php b/mod/ostatus_subscribe.php index 7f9725b853..f112a2ef91 100644 --- a/mod/ostatus_subscribe.php +++ b/mod/ostatus_subscribe.php @@ -8,6 +8,7 @@ use Friendica\Core\L10n; use Friendica\Core\PConfig; use Friendica\Core\Protocol; use Friendica\Core\System; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Network\Probe; use Friendica\Util\Network; @@ -16,7 +17,7 @@ function ostatus_subscribe_content(App $a) { if (!local_user()) { notice(L10n::t('Permission denied.') . EOL); - $a->internalRedirect('ostatus_subscribe'); + DI::baseUrl()->redirect('ostatus_subscribe'); // NOTREACHED } diff --git a/mod/photos.php b/mod/photos.php index a3d81c041d..fd1d6200f3 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -173,12 +173,12 @@ function photos_post(App $a) if ($a->argc > 3 && $a->argv[2] === 'album') { if (!Strings::isHex($a->argv[3])) { - $a->internalRedirect('photos/' . $a->data['user']['nickname'] . '/album'); + DI::baseUrl()->redirect('photos/' . $a->data['user']['nickname'] . '/album'); } $album = hex2bin($a->argv[3]); if ($album === L10n::t('Profile Photos') || $album === 'Contact Photos' || $album === L10n::t('Contact Photos')) { - $a->internalRedirect($_SESSION['photo_return']); + DI::baseUrl()->redirect($_SESSION['photo_return']); return; // NOTREACHED } @@ -189,13 +189,13 @@ function photos_post(App $a) if (!DBA::isResult($r)) { notice(L10n::t('Album not found.') . EOL); - $a->internalRedirect($_SESSION['photo_return']); + DI::baseUrl()->redirect($_SESSION['photo_return']); return; // NOTREACHED } // Check if the user has responded to a delete confirmation query if (!empty($_REQUEST['canceled'])) { - $a->internalRedirect($_SESSION['photo_return']); + DI::baseUrl()->redirect($_SESSION['photo_return']); } // RENAME photo album @@ -209,7 +209,7 @@ function photos_post(App $a) // Update the photo albums cache Photo::clearAlbumCache($page_owner_uid); - $a->internalRedirect('photos/' . $a->user['nickname'] . '/album/' . bin2hex($newalbum)); + DI::baseUrl()->redirect('photos/' . $a->user['nickname'] . '/album/' . bin2hex($newalbum)); return; // NOTREACHED } @@ -252,13 +252,13 @@ function photos_post(App $a) } } - $a->internalRedirect('photos/' . $a->argv[1]); + DI::baseUrl()->redirect('photos/' . $a->argv[1]); } if ($a->argc > 3 && $a->argv[2] === 'image') { // Check if the user has responded to a delete confirmation query for a single photo if (!empty($_POST['canceled'])) { - $a->internalRedirect('photos/' . $a->argv[1] . '/image/' . $a->argv[3]); + DI::baseUrl()->redirect('photos/' . $a->argv[1] . '/image/' . $a->argv[3]); } if (!empty($_POST['delete'])) { @@ -282,10 +282,10 @@ function photos_post(App $a) notice('Successfully deleted the photo.'); } else { notice('Failed to delete the photo.'); - $a->internalRedirect('photos/' . $a->argv[1] . '/image/' . $a->argv[3]); + DI::baseUrl()->redirect('photos/' . $a->argv[1] . '/image/' . $a->argv[3]); } - $a->internalRedirect('photos/' . $a->argv[1]); + DI::baseUrl()->redirect('photos/' . $a->argv[1]); return; // NOTREACHED } } @@ -591,7 +591,7 @@ function photos_post(App $a) } } } - $a->internalRedirect($_SESSION['photo_return']); + DI::baseUrl()->redirect($_SESSION['photo_return']); return; // NOTREACHED } @@ -817,7 +817,7 @@ function photos_post(App $a) // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook // if they do not wish to be redirected - $a->internalRedirect($_SESSION['photo_return']); + DI::baseUrl()->redirect($_SESSION['photo_return']); // NOTREACHED } @@ -994,7 +994,7 @@ function photos_content(App $a) if ($datatype === 'album') { // if $datum is not a valid hex, redirect to the default page if (!Strings::isHex($datum)) { - $a->internalRedirect('photos/' . $a->data['user']['nickname']. '/album'); + DI::baseUrl()->redirect('photos/' . $a->data['user']['nickname']. '/album'); } $album = hex2bin($datum); diff --git a/mod/profile_photo.php b/mod/profile_photo.php index 97d2da349c..412d19029e 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -11,6 +11,7 @@ use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Photo; use Friendica\Model\Profile; @@ -134,7 +135,7 @@ function profile_photo_post(App $a) } } - $a->internalRedirect($path); + DI::baseUrl()->redirect($path); return; // NOTREACHED } @@ -167,7 +168,7 @@ function profile_photo_post(App $a) @unlink($src); $imagecrop = profile_photo_crop_ui_head($a, $ph); - $a->internalRedirect('profile_photo/use/' . $imagecrop['hash']); + DI::baseUrl()->redirect('profile_photo/use/' . $imagecrop['hash']); } function profile_photo_content(App $a) @@ -222,7 +223,7 @@ function profile_photo_content(App $a) Worker::add(PRIORITY_LOW, "Directory", $url); } - $a->internalRedirect('profile/' . $a->user['nickname']); + DI::baseUrl()->redirect('profile/' . $a->user['nickname']); return; // NOTREACHED } $ph = Photo::getImageForPhoto($r[0]); diff --git a/mod/profiles.php b/mod/profiles.php index 46bc36db53..e298df668c 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -16,6 +16,7 @@ use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\GContact; use Friendica\Model\Profile; @@ -41,7 +42,7 @@ function profiles_init(App $a) { ); if (! DBA::isResult($r)) { notice(L10n::t('Profile not found.') . EOL); - $a->internalRedirect('profiles'); + DI::baseUrl()->redirect('profiles'); return; // NOTREACHED } @@ -62,7 +63,7 @@ function profiles_init(App $a) { info(L10n::t('Profile deleted.').EOL); } - $a->internalRedirect('profiles'); + DI::baseUrl()->redirect('profiles'); return; // NOTREACHED } @@ -96,10 +97,10 @@ function profiles_init(App $a) { info(L10n::t('New profile created.') . EOL); if (DBA::isResult($r3) && count($r3) == 1) { - $a->internalRedirect('profiles/' . $r3[0]['id']); + DI::baseUrl()->redirect('profiles/' . $r3[0]['id']); } - $a->internalRedirect('profiles'); + DI::baseUrl()->redirect('profiles'); } if (($a->argc > 2) && ($a->argv[1] === 'clone')) { @@ -134,10 +135,10 @@ function profiles_init(App $a) { ); info(L10n::t('New profile created.') . EOL); if ((DBA::isResult($r3)) && (count($r3) == 1)) { - $a->internalRedirect('profiles/'.$r3[0]['id']); + DI::baseUrl()->redirect('profiles/'.$r3[0]['id']); } - $a->internalRedirect('profiles'); + DI::baseUrl()->redirect('profiles'); return; // NOTREACHED } @@ -640,7 +641,7 @@ function profiles_content(App $a) { ); if (DBA::isResult($r)) { //Go to the default profile. - $a->internalRedirect('profiles/' . $r[0]['id']); + DI::baseUrl()->redirect('profiles/' . $r[0]['id']); } } diff --git a/mod/redir.php b/mod/redir.php index 9d86f27a96..57f96a7ac6 100644 --- a/mod/redir.php +++ b/mod/redir.php @@ -6,6 +6,7 @@ use Friendica\Core\Logger; use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Profile; use Friendica\Util\Network; @@ -30,7 +31,7 @@ function redir_init(App $a) { $contact = DBA::selectFirst('contact', $fields, ['id' => $cid, 'uid' => [0, local_user()]]); if (!DBA::isResult($contact)) { notice(L10n::t('Contact not found.')); - $a->internalRedirect(); + DI::baseUrl()->redirect(); } $contact_url = $contact['url']; @@ -120,7 +121,7 @@ function redir_init(App $a) { } notice(L10n::t('Contact not found.')); - $a->internalRedirect(); + DI::baseUrl()->redirect(); } function redir_magic($a, $cid, $url) diff --git a/mod/regmod.php b/mod/regmod.php index 78cba8a2ab..0fc5a88994 100644 --- a/mod/regmod.php +++ b/mod/regmod.php @@ -9,6 +9,7 @@ use Friendica\Core\L10n; use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Register; use Friendica\Model\User; use Friendica\Module\Security\Login; @@ -98,11 +99,11 @@ function regmod_content(App $a) if ($cmd === 'deny') { user_deny($hash); - $a->internalRedirect('admin/users/'); + DI::baseUrl()->redirect('admin/users/'); } if ($cmd === 'allow') { user_allow($hash); - $a->internalRedirect('admin/users/'); + DI::baseUrl()->redirect('admin/users/'); } } diff --git a/mod/removeme.php b/mod/removeme.php index 7ed0d1da90..30e332d328 100644 --- a/mod/removeme.php +++ b/mod/removeme.php @@ -8,6 +8,7 @@ use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\User; use Friendica\Util\Strings; @@ -59,7 +60,7 @@ function removeme_post(App $a) unset($_SESSION['authenticated']); unset($_SESSION['uid']); - $a->internalRedirect(); + DI::baseUrl()->redirect(); // NOTREACHED } } @@ -67,7 +68,7 @@ function removeme_post(App $a) function removeme_content(App $a) { if (!local_user()) { - $a->internalRedirect(); + DI::baseUrl()->redirect(); } $hash = Strings::getRandomHex(); diff --git a/mod/repair_ostatus.php b/mod/repair_ostatus.php index 51a6aadaad..f1a86e6b23 100644 --- a/mod/repair_ostatus.php +++ b/mod/repair_ostatus.php @@ -8,13 +8,14 @@ use Friendica\Core\L10n; use Friendica\Core\Protocol; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Contact; function repair_ostatus_content(App $a) { if (! local_user()) { notice(L10n::t('Permission denied.') . EOL); - $a->internalRedirect('ostatus_repair'); + DI::baseUrl()->redirect('ostatus_repair'); // NOTREACHED } diff --git a/mod/settings.php b/mod/settings.php index b126defcba..416a8adcda 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -173,7 +173,7 @@ function settings_post(App $a) $key = $_POST['remove']; DBA::delete('tokens', ['id' => $key, 'uid' => local_user()]); - $a->internalRedirect('settings/oauth/', true); + DI::baseUrl()->redirect('settings/oauth/', true); return; } @@ -219,7 +219,7 @@ function settings_post(App $a) ); } } - $a->internalRedirect('settings/oauth/', true); + DI::baseUrl()->redirect('settings/oauth/', true); return; } @@ -383,7 +383,7 @@ function settings_post(App $a) } Hook::callAll('display_settings_post', $_POST); - $a->internalRedirect('settings/display'); + DI::baseUrl()->redirect('settings/display'); return; // NOTREACHED } @@ -419,7 +419,7 @@ function settings_post(App $a) if (!empty($_POST['resend_relocate'])) { Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::RELOCATION, local_user()); info(L10n::t("Relocate message has been send to your contacts")); - $a->internalRedirect('settings'); + DI::baseUrl()->redirect('settings'); } Hook::callAll('settings_post', $_POST); @@ -638,7 +638,7 @@ function settings_post(App $a) // Update the global contact for the user GContact::updateForUser(local_user()); - $a->internalRedirect('settings'); + DI::baseUrl()->redirect('settings'); return; // NOTREACHED } @@ -705,7 +705,7 @@ function settings_content(App $a) BaseModule::checkFormSecurityTokenRedirectOnError('/settings/oauth', 'settings_oauth', 't'); DBA::delete('clients', ['client_id' => $a->argv[3], 'uid' => local_user()]); - $a->internalRedirect('settings/oauth/', true); + DI::baseUrl()->redirect('settings/oauth/', true); return; } diff --git a/mod/suggest.php b/mod/suggest.php index 4b67dd6eb8..86c7f7afdf 100644 --- a/mod/suggest.php +++ b/mod/suggest.php @@ -10,6 +10,7 @@ use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\GContact; use Friendica\Util\Proxy as ProxyUtils; @@ -28,7 +29,7 @@ function suggest_post(App $a) notice(L10n::t('Contact suggestion successfully ignored.')); } - $a->internalRedirect('suggest'); + DI::baseUrl()->redirect('suggest'); } function suggest_content(App $a) diff --git a/mod/tagrm.php b/mod/tagrm.php index 3f091f298a..267ee718cc 100644 --- a/mod/tagrm.php +++ b/mod/tagrm.php @@ -7,6 +7,7 @@ use Friendica\App; use Friendica\Content\Text\BBCode; use Friendica\Core\L10n; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Item; use Friendica\Model\Term; use Friendica\Util\Strings; @@ -14,11 +15,11 @@ use Friendica\Util\Strings; function tagrm_post(App $a) { if (!local_user()) { - $a->internalRedirect($_SESSION['photo_return']); + DI::baseUrl()->redirect($_SESSION['photo_return']); } if (!empty($_POST['submit']) && ($_POST['submit'] === L10n::t('Cancel'))) { - $a->internalRedirect($_SESSION['photo_return']); + DI::baseUrl()->redirect($_SESSION['photo_return']); } $tags = []; @@ -30,7 +31,7 @@ function tagrm_post(App $a) update_tags($item_id, $tags); info(L10n::t('Tag(s) removed') . EOL); - $a->internalRedirect($_SESSION['photo_return']); + DI::baseUrl()->redirect($_SESSION['photo_return']); // NOTREACHED } @@ -71,31 +72,31 @@ function tagrm_content(App $a) $o = ''; if (!local_user()) { - $a->internalRedirect($_SESSION['photo_return']); + DI::baseUrl()->redirect($_SESSION['photo_return']); // NOTREACHED } if ($a->argc == 3) { update_tags($a->argv[1], [Strings::escapeTags(trim(hex2bin($a->argv[2])))]); - $a->internalRedirect($_SESSION['photo_return']); + DI::baseUrl()->redirect($_SESSION['photo_return']); } $item_id = (($a->argc > 1) ? intval($a->argv[1]) : 0); if (!$item_id) { - $a->internalRedirect($_SESSION['photo_return']); + DI::baseUrl()->redirect($_SESSION['photo_return']); // NOTREACHED } $item = Item::selectFirst(['tag'], ['id' => $item_id, 'uid' => local_user()]); if (!DBA::isResult($item)) { - $a->internalRedirect($_SESSION['photo_return']); + DI::baseUrl()->redirect($_SESSION['photo_return']); } $arr = explode(',', $item['tag']); if (empty($item['tag'])) { - $a->internalRedirect($_SESSION['photo_return']); + DI::baseUrl()->redirect($_SESSION['photo_return']); } $o .= '

' . L10n::t('Remove Item Tag') . '

'; diff --git a/mod/uimport.php b/mod/uimport.php index 436802265b..b1cb8f82a5 100644 --- a/mod/uimport.php +++ b/mod/uimport.php @@ -19,7 +19,7 @@ function uimport_post(App $a) } if (!empty($_FILES['accountfile'])) { - UserImport::importAccount($a, $_FILES['accountfile']); + UserImport::importAccount($_FILES['accountfile']); return; } } diff --git a/mod/unfollow.php b/mod/unfollow.php index 7afd82c98a..c7ad413d22 100644 --- a/mod/unfollow.php +++ b/mod/unfollow.php @@ -9,6 +9,7 @@ use Friendica\Core\Protocol; use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Profile; use Friendica\Model\User; @@ -20,7 +21,7 @@ function unfollow_post(App $a) if (!local_user()) { notice(L10n::t('Permission denied.')); - $a->internalRedirect('login'); + DI::baseUrl()->redirect('login'); // NOTREACHED } @@ -34,17 +35,17 @@ function unfollow_post(App $a) if (!DBA::isResult($contact)) { notice(L10n::t("You aren't following this contact.")); - $a->internalRedirect($base_return_path); + DI::baseUrl()->redirect($base_return_path); // NOTREACHED } if (!empty($_REQUEST['cancel'])) { - $a->internalRedirect($base_return_path . '/' . $contact['id']); + DI::baseUrl()->redirect($base_return_path . '/' . $contact['id']); } if (!in_array($contact['network'], Protocol::NATIVE_SUPPORT)) { notice(L10n::t('Unfollowing is currently not supported by your network.')); - $a->internalRedirect($base_return_path . '/' . $contact['id']); + DI::baseUrl()->redirect($base_return_path . '/' . $contact['id']); // NOTREACHED } @@ -65,7 +66,7 @@ function unfollow_post(App $a) } info(L10n::t('Contact unfollowed')); - $a->internalRedirect($return_path); + DI::baseUrl()->redirect($return_path); // NOTREACHED } @@ -75,7 +76,7 @@ function unfollow_content(App $a) if (!local_user()) { notice(L10n::t('Permission denied.')); - $a->internalRedirect('login'); + DI::baseUrl()->redirect('login'); // NOTREACHED } @@ -90,13 +91,13 @@ function unfollow_content(App $a) if (!DBA::isResult($contact)) { notice(L10n::t("You aren't following this contact.")); - $a->internalRedirect($base_return_path); + DI::baseUrl()->redirect($base_return_path); // NOTREACHED } if (!in_array($contact['network'], Protocol::NATIVE_SUPPORT)) { notice(L10n::t('Unfollowing is currently not supported by your network.')); - $a->internalRedirect($base_return_path . '/' . $contact['id']); + DI::baseUrl()->redirect($base_return_path . '/' . $contact['id']); // NOTREACHED } @@ -107,7 +108,7 @@ function unfollow_content(App $a) if (!DBA::isResult($self)) { notice(L10n::t('Permission denied.')); - $a->internalRedirect($base_return_path); + DI::baseUrl()->redirect($base_return_path); // NOTREACHED } diff --git a/mod/videos.php b/mod/videos.php index 4174c7f48a..c6f342aa70 100644 --- a/mod/videos.php +++ b/mod/videos.php @@ -12,6 +12,7 @@ use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\Core\Session; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Attach; use Friendica\Model\Contact; use Friendica\Model\Group; @@ -75,7 +76,7 @@ function videos_post(App $a) $owner_uid = $a->data['user']['uid']; if (local_user() != $owner_uid) { - $a->internalRedirect('videos/' . $a->data['user']['nickname']); + DI::baseUrl()->redirect('videos/' . $a->data['user']['nickname']); } if (($a->argc == 2) && !empty($_POST['delete']) && !empty($_POST['id'])) { @@ -92,11 +93,11 @@ function videos_post(App $a) ], local_user()); } - $a->internalRedirect('videos/' . $a->data['user']['nickname']); + DI::baseUrl()->redirect('videos/' . $a->data['user']['nickname']); return; // NOTREACHED } - $a->internalRedirect('videos/' . $a->data['user']['nickname']); + DI::baseUrl()->redirect('videos/' . $a->data['user']['nickname']); } function videos_content(App $a) diff --git a/mod/wallmessage.php b/mod/wallmessage.php index ad8ca96675..eaa3174f4a 100644 --- a/mod/wallmessage.php +++ b/mod/wallmessage.php @@ -8,6 +8,7 @@ use Friendica\Core\Logger; use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Mail; use Friendica\Model\Profile; use Friendica\Util\Strings; @@ -72,7 +73,7 @@ function wallmessage_post(App $a) { info(L10n::t('Message sent.') . EOL); } - $a->internalRedirect('profile/'.$user['nickname']); + DI::baseUrl()->redirect('profile/'.$user['nickname']); } diff --git a/src/App.php b/src/App.php index c0c3878538..65ab3be53d 100644 --- a/src/App.php +++ b/src/App.php @@ -681,9 +681,9 @@ class App // in install mode, any url loads install module // but we need "view" module for stylesheet if ($this->mode->isInstall() && $moduleName !== 'install') { - $this->internalRedirect('install'); + $this->baseURL->redirect('install'); } elseif (!$this->mode->isInstall() && !$this->mode->has(App\Mode::MAINTENANCEDISABLED) && $moduleName !== 'maintenance') { - $this->internalRedirect('maintenance'); + $this->baseURL->redirect('maintenance'); } else { $this->checkURL(); Core\Update::check($this->getBasePath(), false, $this->mode); @@ -693,35 +693,35 @@ class App // Compatibility with the Android Diaspora client if ($moduleName == 'stream') { - $this->internalRedirect('network?order=post'); + $this->baseURL->redirect('network?order=post'); } if ($moduleName == 'conversations') { - $this->internalRedirect('message'); + $this->baseURL->redirect('message'); } if ($moduleName == 'commented') { - $this->internalRedirect('network?order=comment'); + $this->baseURL->redirect('network?order=comment'); } if ($moduleName == 'liked') { - $this->internalRedirect('network?order=comment'); + $this->baseURL->redirect('network?order=comment'); } if ($moduleName == 'activity') { - $this->internalRedirect('network?conv=1'); + $this->baseURL->redirect('network?conv=1'); } if (($moduleName == 'status_messages') && ($this->args->getCommand() == 'status_messages/new')) { - $this->internalRedirect('bookmarklet'); + $this->baseURL->redirect('bookmarklet'); } if (($moduleName == 'user') && ($this->args->getCommand() == 'user/edit')) { - $this->internalRedirect('settings'); + $this->baseURL->redirect('settings'); } if (($moduleName == 'tag_followings') && ($this->args->getCommand() == 'tag_followings/manage')) { - $this->internalRedirect('search'); + $this->baseURL->redirect('search'); } // Initialize module that can set the current theme in the init() method, either directly or via App->profile_uid @@ -732,7 +732,7 @@ class App $module = $module->determineClass($this->args, $router, $this->config); // Let the module run it's internal process (init, get, post, ...) - $module->run($this->l10n, $this, $this->logger, $_SERVER, $_POST); + $module->run($this->l10n, $this->baseURL, $this->logger, $_SERVER, $_POST); } catch (HTTPException $e) { ModuleHTTPException::rawContent($e); } @@ -740,15 +740,6 @@ class App $this->page->run($this, $this->baseURL, $this->mode, $module, $this->l10n, $this->config, $pconfig); } - /** - * @deprecated 2019.12 use BaseUrl::redirect instead - * @see BaseURL::redirect() - */ - public function internalRedirect($toUrl = '', $ssl = false) - { - $this->baseURL->redirect($toUrl, $ssl); - } - /** * Automatically redirects to relative or absolute URL * Should only be used if it isn't clear if the URL is either internal or external diff --git a/src/App/Authentication.php b/src/App/Authentication.php index b1424e0fd6..f9d14171e9 100644 --- a/src/App/Authentication.php +++ b/src/App/Authentication.php @@ -407,7 +407,7 @@ class Authentication if ($a->isAjax()) { throw new HTTPException\ForbiddenException(); } else { - $a->internalRedirect('2fa'); + $this->baseUrl->redirect('2fa'); } } } diff --git a/src/App/Module.php b/src/App/Module.php index 39111c9501..51be234937 100644 --- a/src/App/Module.php +++ b/src/App/Module.php @@ -208,14 +208,14 @@ class Module * Run the determined module class and calls all hooks applied to * * @param Core\L10n\L10n $l10n The L10n instance - * @param App $app The whole Friendica app (for method arguments) + * @param App\BaseURL $baseUrl The Friendica Base URL * @param LoggerInterface $logger The Friendica logger * @param array $server The $_SERVER variable * @param array $post The $_POST variables * * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public function run(Core\L10n\L10n $l10n, App $app, LoggerInterface $logger, array $server, array $post) + public function run(Core\L10n\L10n $l10n, App\BaseURL $baseUrl, LoggerInterface $logger, array $server, array $post) { if ($this->printNotAllowedAddon) { info($l10n->t("You must be logged in to use addons. ")); @@ -239,7 +239,7 @@ class Module if (!empty($queryString) && ($queryString === 'q=internal_error.html') && isset($dreamhost_error_hack)) { $logger->info('index.php: dreamhost_error_hack invoked.', ['Original URI' => $server['REQUEST_URI']]); - $app->internalRedirect($server['REQUEST_URI']); + $baseUrl->redirect($server['REQUEST_URI']); } $logger->debug('index.php: page not found.', ['request_uri' => $server['REQUEST_URI'], 'address' => $server['REMOTE_ADDR'], 'query' => $server['QUERY_STRING']]); diff --git a/src/BaseModule.php b/src/BaseModule.php index 3d6a3f691f..dcacce78bb 100644 --- a/src/BaseModule.php +++ b/src/BaseModule.php @@ -140,7 +140,7 @@ abstract class BaseModule Logger::log('checkFormSecurityToken failed: user ' . $a->user['guid'] . ' - form element ' . $typename); Logger::log('checkFormSecurityToken failed: _REQUEST data: ' . print_r($_REQUEST, true), Logger::DATA); notice(self::getFormSecurityStandardErrorMessage()); - $a->internalRedirect($err_redirect); + DI::baseUrl()->redirect($err_redirect); } } diff --git a/src/Core/UserImport.php b/src/Core/UserImport.php index 71767e8cef..b06e01e9f7 100644 --- a/src/Core/UserImport.php +++ b/src/Core/UserImport.php @@ -7,6 +7,7 @@ namespace Friendica\Core; use Friendica\App; use Friendica\Database\DBA; use Friendica\Database\DBStructure; +use Friendica\DI; use Friendica\Model\Photo; use Friendica\Object\Image; use Friendica\Util\Strings; @@ -85,12 +86,11 @@ class UserImport /** * @brief Import account file exported from mod/uexport * - * @param App $a Friendica App Class * @param array $file array from $_FILES * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException */ - public static function importAccount(App $a, $file) + public static function importAccount($file) { Logger::log("Start user import from " . $file['tmp_name']); /* @@ -282,6 +282,6 @@ class UserImport Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::RELOCATION, $newuid); info(L10n::t("Done. You can now login with your username and password")); - $a->internalRedirect('login'); + DI::baseUrl()->redirect('login'); } } diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 577f3da1df..8d4b8c6312 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -2272,7 +2272,7 @@ class Contact $myaddr = bin2hex($a->user['nickname'] . '@' . $a->getHostName()); } - $a->internalRedirect($ret['request'] . "&addr=$myaddr"); + DI::baseUrl()->redirect($ret['request'] . "&addr=$myaddr"); // NOTREACHED } diff --git a/src/Module/Admin/Addons/Details.php b/src/Module/Admin/Addons/Details.php index b7c9b68c28..afca0b150c 100644 --- a/src/Module/Admin/Addons/Details.php +++ b/src/Module/Admin/Addons/Details.php @@ -29,11 +29,11 @@ class Details extends BaseAdminModule $func($a); } - $a->internalRedirect('admin/addons/' . $addon); + DI::baseUrl()->redirect('admin/addons/' . $addon); } } - $a->internalRedirect('admin/addons'); + DI::baseUrl()->redirect('admin/addons'); } public static function content(array $parameters = []) @@ -51,7 +51,7 @@ class Details extends BaseAdminModule if (!is_file("addon/$addon/$addon.php")) { notice(L10n::t('Addon not found.')); Addon::uninstall($addon); - $a->internalRedirect('admin/addons'); + DI::baseUrl()->redirect('admin/addons'); } if (($_GET['action'] ?? '') == 'toggle') { @@ -68,7 +68,7 @@ class Details extends BaseAdminModule Addon::saveEnabledList(); - $a->internalRedirect('admin/addons/' . $addon); + DI::baseUrl()->redirect('admin/addons/' . $addon); } // display addon details @@ -119,6 +119,6 @@ class Details extends BaseAdminModule ]); } - $a->internalRedirect('admin/addons'); + DI::baseUrl()->redirect('admin/addons'); } } diff --git a/src/Module/Admin/Addons/Index.php b/src/Module/Admin/Addons/Index.php index 237eb73255..bc28aaa8fe 100644 --- a/src/Module/Admin/Addons/Index.php +++ b/src/Module/Admin/Addons/Index.php @@ -41,7 +41,7 @@ class Index extends BaseAdminModule } - $a->internalRedirect('admin/addons'); + DI::baseUrl()->redirect('admin/addons'); } $addons = Addon::getAvailableList(); diff --git a/src/Module/Admin/Blocklist/Contact.php b/src/Module/Admin/Blocklist/Contact.php index e21c0ed959..71e96834b6 100644 --- a/src/Module/Admin/Blocklist/Contact.php +++ b/src/Module/Admin/Blocklist/Contact.php @@ -39,7 +39,7 @@ class Contact extends BaseAdminModule notice(L10n::tt('%s contact unblocked', '%s contacts unblocked', count($contacts))); } - DI::app()->internalRedirect('admin/blocklist/contact'); + DI::baseUrl()->redirect('admin/blocklist/contact'); } public static function content(array $parameters = []) diff --git a/src/Module/Admin/Blocklist/Server.php b/src/Module/Admin/Blocklist/Server.php index 5b84e40653..87cb8709db 100644 --- a/src/Module/Admin/Blocklist/Server.php +++ b/src/Module/Admin/Blocklist/Server.php @@ -48,7 +48,7 @@ class Server extends BaseAdminModule info(L10n::t('Site blocklist updated.') . EOL); } - DI::app()->internalRedirect('admin/blocklist/server'); + DI::baseUrl()->redirect('admin/blocklist/server'); } public static function content(array $parameters = []) diff --git a/src/Module/Admin/DBSync.php b/src/Module/Admin/DBSync.php index 7aeba4e1b1..6f6ebe3d00 100644 --- a/src/Module/Admin/DBSync.php +++ b/src/Module/Admin/DBSync.php @@ -32,7 +32,7 @@ class DBSync extends BaseAdminModule } info(L10n::t('Update has been marked successful') . EOL); } - $a->internalRedirect('admin/dbsync'); + DI::baseUrl()->redirect('admin/dbsync'); } if ($a->argc > 2) { diff --git a/src/Module/Admin/Features.php b/src/Module/Admin/Features.php index c9a5a9813d..7cc7932af8 100644 --- a/src/Module/Admin/Features.php +++ b/src/Module/Admin/Features.php @@ -40,7 +40,7 @@ class Features extends BaseAdminModule } } - DI::app()->internalRedirect('admin/features'); + DI::baseUrl()->redirect('admin/features'); } public static function content(array $parameters = []) diff --git a/src/Module/Admin/Item/Delete.php b/src/Module/Admin/Item/Delete.php index 77849a9aa9..744a57f073 100644 --- a/src/Module/Admin/Item/Delete.php +++ b/src/Module/Admin/Item/Delete.php @@ -34,7 +34,7 @@ class Delete extends BaseAdminModule } info(L10n::t('Item marked for deletion.') . EOL); - DI::app()->internalRedirect('admin/item/delete'); + DI::baseUrl()->redirect('admin/item/delete'); } public static function content(array $parameters = []) diff --git a/src/Module/Admin/Logs/Settings.php b/src/Module/Admin/Logs/Settings.php index 0617c1c217..ccddf69a1d 100644 --- a/src/Module/Admin/Logs/Settings.php +++ b/src/Module/Admin/Logs/Settings.php @@ -35,7 +35,7 @@ class Settings extends BaseAdminModule } info(L10n::t("Log settings updated.")); - DI::app()->internalRedirect('admin/logs'); + DI::baseUrl()->redirect('admin/logs'); } public static function content(array $parameters = []) diff --git a/src/Module/Admin/Site.php b/src/Module/Admin/Site.php index abf9d95edb..42b35edff3 100644 --- a/src/Module/Admin/Site.php +++ b/src/Module/Admin/Site.php @@ -48,7 +48,7 @@ class Site extends BaseAdminModule $parsed = @parse_url($new_url); if (!is_array($parsed) || empty($parsed['host']) || empty($parsed['scheme'])) { notice(L10n::t("Can not parse base url. Must have at least ://")); - $a->internalRedirect('admin/site'); + DI::baseUrl()->redirect('admin/site'); } /* steps: @@ -77,7 +77,7 @@ class Site extends BaseAdminModule $r = DBA::e(sprintf("UPDATE %s SET %s;", $table_name, $upds)); if (!DBA::isResult($r)) { notice("Failed updating '$table_name': " . DBA::errorMessage()); - $a->internalRedirect('admin/site'); + DI::baseUrl()->redirect('admin/site'); } } @@ -105,7 +105,7 @@ class Site extends BaseAdminModule info("Relocation started. Could take a while to complete."); - $a->internalRedirect('admin/site'); + DI::baseUrl()->redirect('admin/site'); } // end relocate @@ -229,7 +229,7 @@ class Site extends BaseAdminModule foreach ($storage_form_errors as $name => $err) { notice('Storage backend, ' . $storage_opts[$name][1] . ': ' . $err); } - $a->internalRedirect('admin/site' . $active_panel); + DI::baseUrl()->redirect('admin/site' . $active_panel); } } else { info(L10n::t('Invalid storage backend setting value.')); @@ -410,7 +410,7 @@ class Site extends BaseAdminModule info(L10n::t('Site settings updated.') . EOL); - $a->internalRedirect('admin/site' . $active_panel); + DI::baseUrl()->redirect('admin/site' . $active_panel); } public static function content(array $parameters = []) diff --git a/src/Module/Admin/Themes/Details.php b/src/Module/Admin/Themes/Details.php index 0e9fa08f52..c45204e98a 100644 --- a/src/Module/Admin/Themes/Details.php +++ b/src/Module/Admin/Themes/Details.php @@ -36,7 +36,7 @@ class Details extends BaseAdminModule return; } - $a->internalRedirect('admin/themes/' . $theme); + DI::baseUrl()->redirect('admin/themes/' . $theme); } } @@ -76,7 +76,7 @@ class Details extends BaseAdminModule info(L10n::t('Theme %s failed to install.', $theme)); } - $a->internalRedirect('admin/themes/' . $theme); + DI::baseUrl()->redirect('admin/themes/' . $theme); } $readme = null; @@ -122,6 +122,6 @@ class Details extends BaseAdminModule ]); } - $a->internalRedirect('admin/themes'); + DI::baseUrl()->redirect('admin/themes'); } } diff --git a/src/Module/Admin/Themes/Embed.php b/src/Module/Admin/Themes/Embed.php index 8a7b5c19ea..0ef72773d2 100644 --- a/src/Module/Admin/Themes/Embed.php +++ b/src/Module/Admin/Themes/Embed.php @@ -50,7 +50,7 @@ class Embed extends BaseAdminModule return; } - $a->internalRedirect('admin/themes/' . $theme . '/embed?mode=minimal'); + DI::baseUrl()->redirect('admin/themes/' . $theme . '/embed?mode=minimal'); } } diff --git a/src/Module/Admin/Themes/Index.php b/src/Module/Admin/Themes/Index.php index db6c4bc60b..63b3d6f39e 100644 --- a/src/Module/Admin/Themes/Index.php +++ b/src/Module/Admin/Themes/Index.php @@ -59,7 +59,7 @@ class Index extends BaseAdminModule } - $a->internalRedirect('admin/themes'); + DI::baseUrl()->redirect('admin/themes'); } $themes = []; diff --git a/src/Module/Admin/Tos.php b/src/Module/Admin/Tos.php index 5c7d592253..5e434bc0d0 100644 --- a/src/Module/Admin/Tos.php +++ b/src/Module/Admin/Tos.php @@ -30,7 +30,7 @@ class Tos extends BaseAdminModule info(L10n::t('The Terms of Service settings have been updated.')); - DI::app()->internalRedirect('admin/tos'); + DI::baseUrl()->redirect('admin/tos'); } public static function content(array $parameters = []) diff --git a/src/Module/Admin/Users.php b/src/Module/Admin/Users.php index e6162ae858..7d8574e56b 100644 --- a/src/Module/Admin/Users.php +++ b/src/Module/Admin/Users.php @@ -129,7 +129,7 @@ class Users extends BaseAdminModule } } - $a->internalRedirect('admin/users'); + DI::baseUrl()->redirect('admin/users'); } public static function content(array $parameters = []) @@ -145,7 +145,7 @@ class Users extends BaseAdminModule $user = User::getById($uid, ['username', 'blocked']); if (!DBA::isResult($user)) { notice('User not found' . EOL); - $a->internalRedirect('admin/users'); + DI::baseUrl()->redirect('admin/users'); return ''; // NOTREACHED } @@ -175,7 +175,7 @@ class Users extends BaseAdminModule break; } - $a->internalRedirect('admin/users'); + DI::baseUrl()->redirect('admin/users'); } /* get pending */ diff --git a/src/Module/Apps.php b/src/Module/Apps.php index be0b60f6e1..d7cd0fc72e 100644 --- a/src/Module/Apps.php +++ b/src/Module/Apps.php @@ -18,7 +18,7 @@ class Apps extends BaseModule { $privateaddons = Config::get('config', 'private_addons'); if ($privateaddons === "1" && !local_user()) { - DI::app()->internalRedirect(); + DI::baseUrl()->redirect(); } } diff --git a/src/Module/BaseAdminModule.php b/src/Module/BaseAdminModule.php index 08db0a98c4..3a5cde24c8 100644 --- a/src/Module/BaseAdminModule.php +++ b/src/Module/BaseAdminModule.php @@ -56,7 +56,7 @@ abstract class BaseAdminModule extends BaseModule if (!is_site_admin()) { notice(L10n::t('Please login to continue.')); Session::set('return_path', $a->query_string); - $a->internalRedirect('login'); + DI::baseUrl()->redirect('login'); } if (!empty($_SESSION['submanage'])) { diff --git a/src/Module/Contact.php b/src/Module/Contact.php index d366eaf0bd..45e4900ac2 100644 --- a/src/Module/Contact.php +++ b/src/Module/Contact.php @@ -22,7 +22,6 @@ use Friendica\Model; use Friendica\Module\Security\Login; use Friendica\Network\HTTPException\BadRequestException; use Friendica\Network\HTTPException\NotFoundException; -use Friendica\Network\Probe; use Friendica\Util\DateTimeFormat; use Friendica\Util\Proxy as ProxyUtils; use Friendica\Util\Strings; @@ -34,7 +33,7 @@ use Friendica\Util\Strings; */ class Contact extends BaseModule { - private static function batchActions(App $a) + private static function batchActions() { if (empty($_POST['contact_batch']) || !is_array($_POST['contact_batch'])) { return; @@ -74,7 +73,7 @@ class Contact extends BaseModule info(L10n::tt('%d contact edited.', '%d contacts edited.', $count_actions)); } - $a->internalRedirect('contact'); + DI::baseUrl()->redirect('contact'); } public static function post(array $parameters = []) @@ -87,7 +86,7 @@ class Contact extends BaseModule // @TODO: Replace with parameter from router if ($a->argv[1] === 'batch') { - self::batchActions($a); + self::batchActions(); return; } @@ -99,7 +98,7 @@ class Contact extends BaseModule if (!DBA::exists('contact', ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false])) { notice(L10n::t('Could not access contact record.') . EOL); - $a->internalRedirect('contact'); + DI::baseUrl()->redirect('contact'); return; // NOTREACHED } @@ -280,9 +279,9 @@ class Contact extends BaseModule if ($contact['self']) { // @TODO: Replace with parameter from router if (($a->argc == 3) && intval($a->argv[1]) && in_array($a->argv[2], ['posts', 'conversations'])) { - $a->internalRedirect('profile/' . $contact['nick']); + DI::baseUrl()->redirect('profile/' . $contact['nick']); } else { - $a->internalRedirect('profile/' . $contact['nick'] . '?tab=profile'); + DI::baseUrl()->redirect('profile/' . $contact['nick'] . '?tab=profile'); } } @@ -380,13 +379,13 @@ class Contact extends BaseModule if ($cmd === 'update' && ($orig_record['uid'] != 0)) { self::updateContactFromPoll($contact_id); - $a->internalRedirect('contact/' . $contact_id); + DI::baseUrl()->redirect('contact/' . $contact_id); // NOTREACHED } if ($cmd === 'updateprofile' && ($orig_record['uid'] != 0)) { self::updateContactFromProbe($contact_id); - $a->internalRedirect('crepair/' . $contact_id); + DI::baseUrl()->redirect('crepair/' . $contact_id); // NOTREACHED } @@ -396,7 +395,7 @@ class Contact extends BaseModule $blocked = Model\Contact::isBlockedByUser($contact_id, local_user()); info(($blocked ? L10n::t('Contact has been blocked') : L10n::t('Contact has been unblocked')) . EOL); - $a->internalRedirect('contact/' . $contact_id); + DI::baseUrl()->redirect('contact/' . $contact_id); // NOTREACHED } @@ -406,7 +405,7 @@ class Contact extends BaseModule $ignored = Model\Contact::isIgnoredByUser($contact_id, local_user()); info(($ignored ? L10n::t('Contact has been ignored') : L10n::t('Contact has been unignored')) . EOL); - $a->internalRedirect('contact/' . $contact_id); + DI::baseUrl()->redirect('contact/' . $contact_id); // NOTREACHED } @@ -417,7 +416,7 @@ class Contact extends BaseModule info((($archived) ? L10n::t('Contact has been archived') : L10n::t('Contact has been unarchived')) . EOL); } - $a->internalRedirect('contact/' . $contact_id); + DI::baseUrl()->redirect('contact/' . $contact_id); // NOTREACHED } @@ -451,13 +450,13 @@ class Contact extends BaseModule } // Now check how the user responded to the confirmation query if (!empty($_REQUEST['canceled'])) { - $a->internalRedirect('contact'); + DI::baseUrl()->redirect('contact'); } self::dropContact($orig_record); info(L10n::t('Contact has been removed.') . EOL); - $a->internalRedirect('contact'); + DI::baseUrl()->redirect('contact'); // NOTREACHED } if ($cmd === 'posts') { diff --git a/src/Module/Debug/Feed.php b/src/Module/Debug/Feed.php index 48601d6bb3..9a48d743c8 100644 --- a/src/Module/Debug/Feed.php +++ b/src/Module/Debug/Feed.php @@ -19,7 +19,7 @@ class Feed extends BaseModule { if (!local_user()) { info(L10n::t('You must be logged in to use this module')); - DI::app()->internalRedirect(); + DI::baseUrl()->redirect(); } } diff --git a/src/Module/Delegation.php b/src/Module/Delegation.php index 32d02a00e9..cb2f24ce1e 100644 --- a/src/Module/Delegation.php +++ b/src/Module/Delegation.php @@ -89,7 +89,7 @@ class Delegation extends BaseModule $ret = []; Hook::callAll('home_init', $ret); - DI::app()->internalRedirect('profile/' . DI::app()->user['nickname']); + DI::baseUrl()->redirect('profile/' . DI::app()->user['nickname']); // NOTREACHED } diff --git a/src/Module/Filer/RemoveTag.php b/src/Module/Filer/RemoveTag.php index 5ecaf4c2f9..dfe548d817 100644 --- a/src/Module/Filer/RemoveTag.php +++ b/src/Module/Filer/RemoveTag.php @@ -47,6 +47,6 @@ class RemoveTag extends BaseModule info('Item was not deleted'); } - $app->internalRedirect('network?file=' . rawurlencode($term)); + DI::baseUrl()->redirect('network?file=' . rawurlencode($term)); } } diff --git a/src/Module/Filer/SaveTag.php b/src/Module/Filer/SaveTag.php index 9c0709db90..93f683744e 100644 --- a/src/Module/Filer/SaveTag.php +++ b/src/Module/Filer/SaveTag.php @@ -19,7 +19,7 @@ class SaveTag extends BaseModule { if (!local_user()) { info(L10n::t('You must be logged in to use this module')); - DI::app()->internalRedirect(); + DI::baseUrl()->redirect(); } } diff --git a/src/Module/FollowConfirm.php b/src/Module/FollowConfirm.php index a19f127376..b97b00944c 100644 --- a/src/Module/FollowConfirm.php +++ b/src/Module/FollowConfirm.php @@ -13,8 +13,6 @@ class FollowConfirm extends BaseModule { public static function post(array $parameters = []) { - $a = DI::app(); - $uid = local_user(); if (!$uid) { notice(L10n::t('Permission denied.') . EOL); @@ -33,6 +31,6 @@ class FollowConfirm extends BaseModule $Intro->confirm($duplex, $hidden); - $a->internalRedirect('contact/' . intval($cid)); + DI::baseUrl()->redirect('contact/' . intval($cid)); } } diff --git a/src/Module/Group.php b/src/Module/Group.php index e7e1978986..b3fe1ba53b 100644 --- a/src/Module/Group.php +++ b/src/Module/Group.php @@ -30,7 +30,7 @@ class Group extends BaseModule if (!local_user()) { notice(L10n::t('Permission denied.')); - $a->internalRedirect(); + DI::baseUrl()->redirect(); } // @TODO: Replace with parameter from router @@ -43,12 +43,12 @@ class Group extends BaseModule info(L10n::t('Group created.')); $r = Model\Group::getIdByName(local_user(), $name); if ($r) { - $a->internalRedirect('group/' . $r); + DI::baseUrl()->redirect('group/' . $r); } } else { notice(L10n::t('Could not create group.')); } - $a->internalRedirect('group'); + DI::baseUrl()->redirect('group'); } // @TODO: Replace with parameter from router @@ -58,7 +58,7 @@ class Group extends BaseModule $group = DBA::selectFirst('group', ['id', 'name'], ['id' => $a->argv[1], 'uid' => local_user()]); if (!DBA::isResult($group)) { notice(L10n::t('Group not found.')); - $a->internalRedirect('contact'); + DI::baseUrl()->redirect('contact'); } $groupname = Strings::escapeTags(trim($_POST['groupname'])); if (strlen($groupname) && ($groupname != $group['name'])) { @@ -142,7 +142,7 @@ class Group extends BaseModule // With no group number provided we jump to the unassigned contacts as a starting point // @TODO: Replace with parameter from router if ($a->argc == 1) { - $a->internalRedirect('group/none'); + DI::baseUrl()->redirect('group/none'); } // Switch to text mode interface if we have more than 'n' contacts or group members @@ -200,7 +200,7 @@ class Group extends BaseModule if (intval($a->argv[2])) { if (!Model\Group::exists($a->argv[2], local_user())) { notice(L10n::t('Group not found.')); - $a->internalRedirect('contact'); + DI::baseUrl()->redirect('contact'); } if (Model\Group::remove($a->argv[2])) { @@ -209,7 +209,7 @@ class Group extends BaseModule notice(L10n::t('Unable to remove group.')); } } - $a->internalRedirect('group'); + DI::baseUrl()->redirect('group'); } // @TODO: Replace with parameter from router @@ -226,7 +226,7 @@ class Group extends BaseModule $group = DBA::selectFirst('group', ['id', 'name'], ['id' => $a->argv[1], 'uid' => local_user(), 'deleted' => false]); if (!DBA::isResult($group)) { notice(L10n::t('Group not found.')); - $a->internalRedirect('contact'); + DI::baseUrl()->redirect('contact'); } $members = Model\Contact::getByGroupId($group['id']); diff --git a/src/Module/Home.php b/src/Module/Home.php index f5032f7c30..fc8817b31b 100644 --- a/src/Module/Home.php +++ b/src/Module/Home.php @@ -25,11 +25,11 @@ class Home extends BaseModule Hook::callAll('home_init', $ret); if (local_user() && ($app->user['nickname'])) { - $app->internalRedirect('network'); + DI::baseUrl()->redirect('network'); } if (strlen($config->get('system', 'singleuser'))) { - $app->internalRedirect('/profile/' . $config->get('system', 'singleuser')); + DI::baseUrl()->redirect('/profile/' . $config->get('system', 'singleuser')); } $customHome = ''; diff --git a/src/Module/Item/Ignore.php b/src/Module/Item/Ignore.php index f59ba229c1..b200741665 100644 --- a/src/Module/Item/Ignore.php +++ b/src/Module/Item/Ignore.php @@ -67,7 +67,7 @@ class Ignore extends BaseModule $rand = "?$rand"; } - DI::app()->internalRedirect($return_path . $rand); + DI::baseUrl()->redirect($return_path . $rand); } // the json doesn't really matter, it will either be 0 or 1 diff --git a/src/Module/Like.php b/src/Module/Like.php index 74a0b8d859..2c5f02b1f6 100644 --- a/src/Module/Like.php +++ b/src/Module/Like.php @@ -47,7 +47,7 @@ class Like extends BaseModule $rand = "?$rand"; } - $app->internalRedirect($returnPath . $rand); + DI::baseUrl()->redirect($returnPath . $rand); } } } diff --git a/src/Module/Notifications/Notify.php b/src/Module/Notifications/Notify.php index 5200c59114..bb52ce8124 100644 --- a/src/Module/Notifications/Notify.php +++ b/src/Module/Notifications/Notify.php @@ -58,10 +58,10 @@ class Notify extends BaseModule } } - $a->internalRedirect(); + DI::baseUrl()->redirect(); } // @TODO: Replace with parameter from router - $a->internalRedirect('notifications/system'); + DI::baseUrl()->redirect('notifications/system'); } } diff --git a/src/Module/Objects.php b/src/Module/Objects.php index 4817811a34..4113a545d5 100644 --- a/src/Module/Objects.php +++ b/src/Module/Objects.php @@ -25,7 +25,7 @@ class Objects extends BaseModule } if (!ActivityPub::isRequest()) { - $a->internalRedirect(str_replace('objects/', 'display/', $a->query_string)); + DI::baseUrl()->redirect(str_replace('objects/', 'display/', $a->query_string)); } /// @todo Add Authentication to enable fetching of non public content diff --git a/src/Module/Pinned.php b/src/Module/Pinned.php index 1bd25f2722..b28777516e 100644 --- a/src/Module/Pinned.php +++ b/src/Module/Pinned.php @@ -31,7 +31,7 @@ class Pinned extends BaseModule $returnPath = $_REQUEST['return'] ?? ''; if (!empty($returnPath)) { $rand = '_=' . time() . (strpos($returnPath, '?') ? '&' : '?') . 'rand'; - DI::app()->internalRedirect($returnPath . $rand); + DI::baseUrl()->redirect($returnPath . $rand); } // the json doesn't really matter, it will either be 0 or 1 diff --git a/src/Module/RandomProfile.php b/src/Module/RandomProfile.php index f595ae98ed..c14e9f6cac 100644 --- a/src/Module/RandomProfile.php +++ b/src/Module/RandomProfile.php @@ -23,6 +23,6 @@ class RandomProfile extends BaseModule $a->redirect($link); } - $a->internalRedirect('profile'); + DI::baseUrl()->redirect('profile'); } } diff --git a/src/Module/Register.php b/src/Module/Register.php index 9a6df2f634..2c9b00bf0c 100644 --- a/src/Module/Register.php +++ b/src/Module/Register.php @@ -238,7 +238,7 @@ class Register extends BaseModule if ($res) { \info(L10n::t('Registration successful. Please check your email for further instructions.') . EOL); - $a->internalRedirect(); + DI::baseUrl()->redirect(); } else { \notice( L10n::t('Failed to send email message. Here your accout details:
login: %s
password: %s

You can change your password after login.', @@ -248,12 +248,12 @@ class Register extends BaseModule } } else { \info(L10n::t('Registration successful.') . EOL); - $a->internalRedirect(); + DI::baseUrl()->redirect(); } } elseif (intval(Config::get('config', 'register_policy')) === self::APPROVE) { if (!strlen(Config::get('config', 'admin_email'))) { \notice(L10n::t('Your registration can not be processed.') . EOL); - $a->internalRedirect(); + DI::baseUrl()->redirect(); } // Check if the note to the admin is actually filled out @@ -261,12 +261,12 @@ class Register extends BaseModule \notice(L10n::t('You have to leave a request note for the admin.') . L10n::t('Your registration can not be processed.') . EOL); - $a->internalRedirect('register/'); + DI::baseUrl()->redirect('register/'); } // Is there text in the tar pit? if (!empty($_POST['registertarpit'])) { \notice(L10n::t('You have entered too much information.')); - $a->internalRedirect('register/'); + DI::baseUrl()->redirect('register/'); } Model\Register::createForApproval($user['uid'], Config::get('system', 'language'), $_POST['permonlybox']); @@ -312,7 +312,7 @@ class Register extends BaseModule ); \info(L10n::t('Your registration is pending approval by the site owner.') . EOL); - $a->internalRedirect(); + DI::baseUrl()->redirect(); } return; diff --git a/src/Module/Search/Saved.php b/src/Module/Search/Saved.php index c2d60bc5a3..47925b0ae1 100644 --- a/src/Module/Search/Saved.php +++ b/src/Module/Search/Saved.php @@ -36,6 +36,6 @@ class Saved extends BaseModule } } - DI::app()->internalRedirect($return_url); + DI::baseUrl()->redirect($return_url); } } diff --git a/src/Module/Security/Login.php b/src/Module/Security/Login.php index a049abc882..c525778985 100644 --- a/src/Module/Security/Login.php +++ b/src/Module/Security/Login.php @@ -25,10 +25,8 @@ class Login extends BaseModule { public static function content(array $parameters = []) { - $a = DI::app(); - if (local_user()) { - $a->internalRedirect(); + DI::baseUrl()->redirect(); } return self::form(Session::get('return_path'), intval(Config::get('config', 'register_policy')) !== \Friendica\Module\Register::CLOSED); diff --git a/src/Module/Security/Logout.php b/src/Module/Security/Logout.php index c0a0761087..abe409ca1d 100644 --- a/src/Module/Security/Logout.php +++ b/src/Module/Security/Logout.php @@ -40,7 +40,7 @@ class Logout extends BaseModule System::externalRedirect($visitor_home); } else { info(L10n::t('Logged out.')); - DI::app()->internalRedirect(); + DI::baseUrl()->redirect(); } } } diff --git a/src/Module/Security/TwoFactor/Recovery.php b/src/Module/Security/TwoFactor/Recovery.php index 9a6beb13ad..bbbb2d4451 100644 --- a/src/Module/Security/TwoFactor/Recovery.php +++ b/src/Module/Security/TwoFactor/Recovery.php @@ -52,12 +52,12 @@ class Recovery extends BaseModule public static function content(array $parameters = []) { if (!local_user()) { - DI::app()->internalRedirect(); + DI::baseUrl()->redirect(); } // Already authenticated with 2FA token if (Session::get('2fa')) { - DI::app()->internalRedirect(); + DI::baseUrl()->redirect(); } return Renderer::replaceMacros(Renderer::getMarkupTemplate('twofactor/recovery.tpl'), [ diff --git a/src/Module/Security/TwoFactor/Verify.php b/src/Module/Security/TwoFactor/Verify.php index ff494d7ca0..8fc647472d 100644 --- a/src/Module/Security/TwoFactor/Verify.php +++ b/src/Module/Security/TwoFactor/Verify.php @@ -50,12 +50,12 @@ class Verify extends BaseModule public static function content(array $parameters = []) { if (!local_user()) { - DI::app()->internalRedirect(); + DI::baseUrl()->redirect(); } // Already authenticated with 2FA token if (Session::get('2fa')) { - DI::app()->internalRedirect(); + DI::baseUrl()->redirect(); } return Renderer::replaceMacros(Renderer::getMarkupTemplate('twofactor/verify.tpl'), [ diff --git a/src/Module/Settings/Delegation.php b/src/Module/Settings/Delegation.php index 43d4857463..9884876566 100644 --- a/src/Module/Settings/Delegation.php +++ b/src/Module/Settings/Delegation.php @@ -64,7 +64,7 @@ class Delegation extends BaseSettingsModule if ($action === 'add' && $user_id) { if (Session::get('submanage')) { notice(L10n::t('Delegated administrators can view but not change delegation permissions.')); - DI::app()->internalRedirect('settings/delegation'); + DI::baseUrl()->redirect('settings/delegation'); } $user = User::getById($user_id, ['nickname']); @@ -80,17 +80,17 @@ class Delegation extends BaseSettingsModule notice(L10n::t('Delegate user not found.')); } - DI::app()->internalRedirect('settings/delegation'); + DI::baseUrl()->redirect('settings/delegation'); } if ($action === 'remove' && $user_id) { if (Session::get('submanage')) { notice(L10n::t('Delegated administrators can view but not change delegation permissions.')); - DI::app()->internalRedirect('settings/delegation'); + DI::baseUrl()->redirect('settings/delegation'); } DBA::delete('manage', ['uid' => $user_id, 'mid' => local_user()]); - DI::app()->internalRedirect('settings/delegation'); + DI::baseUrl()->redirect('settings/delegation'); } // find everybody that currently has delegated management to this account/page diff --git a/src/Module/Settings/TwoFactor/AppSpecific.php b/src/Module/Settings/TwoFactor/AppSpecific.php index 1823b56f0d..a303862712 100644 --- a/src/Module/Settings/TwoFactor/AppSpecific.php +++ b/src/Module/Settings/TwoFactor/AppSpecific.php @@ -30,12 +30,12 @@ class AppSpecific extends BaseSettingsModule $verified = PConfig::get(local_user(), '2fa', 'verified'); if (!$verified) { - DI::app()->internalRedirect('settings/2fa'); + DI::baseUrl()->redirect('settings/2fa'); } if (!self::checkFormSecurityToken('settings_2fa_password', 't')) { notice(L10n::t('Please enter your password to access this page.')); - DI::app()->internalRedirect('settings/2fa'); + DI::baseUrl()->redirect('settings/2fa'); } } @@ -53,10 +53,10 @@ class AppSpecific extends BaseSettingsModule $description = $_POST['description'] ?? ''; if (empty($description)) { notice(L10n::t('App-specific password generation failed: The description is empty.')); - DI::app()->internalRedirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password')); + DI::baseUrl()->redirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password')); } elseif (AppSpecificPassword::checkDuplicateForUser(local_user(), $description)) { notice(L10n::t('App-specific password generation failed: This description already exists.')); - DI::app()->internalRedirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password')); + DI::baseUrl()->redirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password')); } else { self::$appSpecificPassword = AppSpecificPassword::generateForUser(local_user(), $_POST['description'] ?? ''); notice(L10n::t('New app-specific password generated.')); @@ -66,7 +66,7 @@ class AppSpecific extends BaseSettingsModule case 'revoke_all' : AppSpecificPassword::deleteAllForUser(local_user()); notice(L10n::t('App-specific passwords successfully revoked.')); - DI::app()->internalRedirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password')); + DI::baseUrl()->redirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password')); break; } } @@ -78,7 +78,7 @@ class AppSpecific extends BaseSettingsModule notice(L10n::t('App-specific password successfully revoked.')); } - DI::app()->internalRedirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password')); + DI::baseUrl()->redirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password')); } } diff --git a/src/Module/Settings/TwoFactor/Index.php b/src/Module/Settings/TwoFactor/Index.php index 9e822e89ee..06e0e66d51 100644 --- a/src/Module/Settings/TwoFactor/Index.php +++ b/src/Module/Settings/TwoFactor/Index.php @@ -39,7 +39,7 @@ class Index extends BaseSettingsModule PConfig::set(local_user(), '2fa', 'secret', $Google2FA->generateSecretKey(32)); - DI::app()->internalRedirect('settings/2fa/recovery?t=' . self::getFormSecurityToken('settings_2fa_password')); + DI::baseUrl()->redirect('settings/2fa/recovery?t=' . self::getFormSecurityToken('settings_2fa_password')); } break; case 'disable': @@ -50,22 +50,22 @@ class Index extends BaseSettingsModule Session::remove('2fa'); notice(L10n::t('Two-factor authentication successfully disabled.')); - DI::app()->internalRedirect('settings/2fa'); + DI::baseUrl()->redirect('settings/2fa'); } break; case 'recovery': if ($has_secret) { - DI::app()->internalRedirect('settings/2fa/recovery?t=' . self::getFormSecurityToken('settings_2fa_password')); + DI::baseUrl()->redirect('settings/2fa/recovery?t=' . self::getFormSecurityToken('settings_2fa_password')); } break; case 'app_specific': if ($has_secret) { - DI::app()->internalRedirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password')); + DI::baseUrl()->redirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password')); } break; case 'configure': if (!$verified) { - DI::app()->internalRedirect('settings/2fa/verify?t=' . self::getFormSecurityToken('settings_2fa_password')); + DI::baseUrl()->redirect('settings/2fa/verify?t=' . self::getFormSecurityToken('settings_2fa_password')); } break; } diff --git a/src/Module/Settings/TwoFactor/Recovery.php b/src/Module/Settings/TwoFactor/Recovery.php index 28f839644c..492b96635b 100644 --- a/src/Module/Settings/TwoFactor/Recovery.php +++ b/src/Module/Settings/TwoFactor/Recovery.php @@ -28,12 +28,12 @@ class Recovery extends BaseSettingsModule $secret = PConfig::get(local_user(), '2fa', 'secret'); if (!$secret) { - DI::app()->internalRedirect('settings/2fa'); + DI::baseUrl()->redirect('settings/2fa'); } if (!self::checkFormSecurityToken('settings_2fa_password', 't')) { notice(L10n::t('Please enter your password to access this page.')); - DI::app()->internalRedirect('settings/2fa'); + DI::baseUrl()->redirect('settings/2fa'); } } @@ -49,7 +49,7 @@ class Recovery extends BaseSettingsModule if ($_POST['action'] == 'regenerate') { RecoveryCode::regenerateForUser(local_user()); notice(L10n::t('New recovery codes successfully generated.')); - DI::app()->internalRedirect('settings/2fa/recovery?t=' . self::getFormSecurityToken('settings_2fa_password')); + DI::baseUrl()->redirect('settings/2fa/recovery?t=' . self::getFormSecurityToken('settings_2fa_password')); } } } diff --git a/src/Module/Settings/TwoFactor/Verify.php b/src/Module/Settings/TwoFactor/Verify.php index b478632620..96feab825a 100644 --- a/src/Module/Settings/TwoFactor/Verify.php +++ b/src/Module/Settings/TwoFactor/Verify.php @@ -35,12 +35,12 @@ class Verify extends BaseSettingsModule $verified = PConfig::get(local_user(), '2fa', 'verified'); if ($secret && $verified) { - DI::app()->internalRedirect('settings/2fa'); + DI::baseUrl()->redirect('settings/2fa'); } if (!self::checkFormSecurityToken('settings_2fa_password', 't')) { notice(L10n::t('Please enter your password to access this page.')); - DI::app()->internalRedirect('settings/2fa'); + DI::baseUrl()->redirect('settings/2fa'); } } @@ -63,7 +63,7 @@ class Verify extends BaseSettingsModule notice(L10n::t('Two-factor authentication successfully activated.')); - DI::app()->internalRedirect('settings/2fa'); + DI::baseUrl()->redirect('settings/2fa'); } else { notice(L10n::t('Invalid code, please retry.')); } diff --git a/src/Module/Starred.php b/src/Module/Starred.php index d6ec19ea73..0f111b21e0 100644 --- a/src/Module/Starred.php +++ b/src/Module/Starred.php @@ -36,7 +36,7 @@ class Starred extends BaseModule $returnPath = $_REQUEST['return'] ?? ''; if (!empty($returnPath)) { $rand = '_=' . time() . (strpos($returnPath, '?') ? '&' : '?') . 'rand'; - DI::app()->internalRedirect($returnPath . $rand); + DI::baseUrl()->redirect($returnPath . $rand); } // the json doesn't really matter, it will either be 0 or 1 diff --git a/src/Module/Tos.php b/src/Module/Tos.php index 7adce79174..b28c98de7b 100644 --- a/src/Module/Tos.php +++ b/src/Module/Tos.php @@ -51,7 +51,7 @@ class Tos extends BaseModule public static function init(array $parameters = []) { if (strlen(Config::get('system','singleuser'))) { - DI::app()->internalRedirect('profile/' . Config::get('system','singleuser')); + DI::baseUrl()->redirect('profile/' . Config::get('system','singleuser')); } } From 8b6e123b3f20392f5676f1514d4033c090ccf099 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Mon, 16 Dec 2019 00:30:39 +0100 Subject: [PATCH 10/34] Refactor deprecated App::isAjax() to DI::mode()->isAjax() --- mod/item.php | 4 ++-- src/App.php | 9 --------- src/App/Authentication.php | 8 ++++++-- src/Module/Admin/Themes/Details.php | 2 +- src/Module/Admin/Themes/Embed.php | 2 +- src/Module/Debug/ItemBody.php | 2 +- src/Module/Group.php | 2 +- 7 files changed, 12 insertions(+), 17 deletions(-) diff --git a/mod/item.php b/mod/item.php index 9326bf60d9..55e4896e75 100644 --- a/mod/item.php +++ b/mod/item.php @@ -878,7 +878,7 @@ function item_content(App $a) $o = ''; if (($a->argc >= 3) && ($a->argv[1] === 'drop') && intval($a->argv[2])) { - if ($a->isAjax()) { + if (DI::mode()->isAjax()) { $o = Item::deleteForUser(['id' => $a->argv[2]], local_user()); } else { if (!empty($a->argv[3])) { @@ -889,7 +889,7 @@ function item_content(App $a) } } - if ($a->isAjax()) { + if (DI::mode()->isAjax()) { // ajax return: [, 0 (no perm) | ] echo json_encode([intval($a->argv[2]), intval($o)]); exit(); diff --git a/src/App.php b/src/App.php index 65ab3be53d..05d592367d 100644 --- a/src/App.php +++ b/src/App.php @@ -543,15 +543,6 @@ class App return Core\Theme::getStylesheetPath($this->getCurrentTheme()); } - /** - * @deprecated 2019.09 - use App\Mode->isAjax() instead - * @see App\Mode::isAjax() - */ - public function isAjax() - { - return $this->mode->isAjax(); - } - /** * @deprecated use Arguments->get() instead * diff --git a/src/App/Authentication.php b/src/App/Authentication.php index f9d14171e9..b8073698f2 100644 --- a/src/App/Authentication.php +++ b/src/App/Authentication.php @@ -31,6 +31,8 @@ class Authentication { /** @var Configuration */ private $config; + /** @var App\Mode */ + private $mode; /** @var App\BaseURL */ private $baseUrl; /** @var L10n */ @@ -48,6 +50,7 @@ class Authentication * Authentication constructor. * * @param Configuration $config + * @param App\Mode $mode * @param App\BaseURL $baseUrl * @param L10n $l10n * @param Database $dba @@ -55,9 +58,10 @@ class Authentication * @param User\Cookie $cookie * @param Session\ISession $session */ - public function __construct(Configuration $config, App\BaseURL $baseUrl, L10n $l10n, Database $dba, LoggerInterface $logger, User\Cookie $cookie, Session\ISession $session) + public function __construct(Configuration $config, App\Mode $mode, App\BaseURL $baseUrl, L10n $l10n, Database $dba, LoggerInterface $logger, User\Cookie $cookie, Session\ISession $session) { $this->config = $config; + $this->mode = $mode; $this->baseUrl = $baseUrl; $this->l10n = $l10n; $this->dba = $dba; @@ -404,7 +408,7 @@ class Authentication } // Case 2: No valid 2FA session: redirect to code verification page - if ($a->isAjax()) { + if ($this->mode->isAjax()) { throw new HTTPException\ForbiddenException(); } else { $this->baseUrl->redirect('2fa'); diff --git a/src/Module/Admin/Themes/Details.php b/src/Module/Admin/Themes/Details.php index c45204e98a..f6a3c61b73 100644 --- a/src/Module/Admin/Themes/Details.php +++ b/src/Module/Admin/Themes/Details.php @@ -32,7 +32,7 @@ class Details extends BaseAdminModule info(L10n::t('Theme settings updated.')); - if ($a->isAjax()) { + if (DI::mode()->isAjax()) { return; } diff --git a/src/Module/Admin/Themes/Embed.php b/src/Module/Admin/Themes/Embed.php index 0ef72773d2..fc0d3301bf 100644 --- a/src/Module/Admin/Themes/Embed.php +++ b/src/Module/Admin/Themes/Embed.php @@ -46,7 +46,7 @@ class Embed extends BaseAdminModule info(L10n::t('Theme settings updated.')); - if ($a->isAjax()) { + if (DI::mode()->isAjax()) { return; } diff --git a/src/Module/Debug/ItemBody.php b/src/Module/Debug/ItemBody.php index 8212ce38b5..d32e1f6c2d 100644 --- a/src/Module/Debug/ItemBody.php +++ b/src/Module/Debug/ItemBody.php @@ -31,7 +31,7 @@ class ItemBody extends BaseModule $item = Item::selectFirst(['body'], ['uid' => local_user(), 'id' => $itemId]); if (!empty($item)) { - if ($app->isAjax()) { + if (DI::mode()->isAjax()) { echo str_replace("\n", '
', $item['body']); exit(); } else { diff --git a/src/Module/Group.php b/src/Module/Group.php index b3fe1ba53b..8de4c5033b 100644 --- a/src/Module/Group.php +++ b/src/Module/Group.php @@ -24,7 +24,7 @@ class Group extends BaseModule { $a = DI::app(); - if ($a->isAjax()) { + if (DI::mode()->isAjax()) { self::ajaxPost(); } From aedbdc536a62d8076f567c853f4cd73f644bf0af Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Mon, 16 Dec 2019 00:31:29 +0100 Subject: [PATCH 11/34] Refactor deprecated App::getArgumentValue() to DI::args()->get() --- src/App.php | 10 ---------- src/Module/Help.php | 2 +- src/Module/Install.php | 3 +-- 3 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/App.php b/src/App.php index 05d592367d..7b0fa07abc 100644 --- a/src/App.php +++ b/src/App.php @@ -543,16 +543,6 @@ class App return Core\Theme::getStylesheetPath($this->getCurrentTheme()); } - /** - * @deprecated use Arguments->get() instead - * - * @see App\Arguments - */ - public function getArgumentValue($position, $default = '') - { - return $this->args->get($position, $default); - } - /** * Sets the base url for use in cmdline programs which don't have * $_SERVER variables diff --git a/src/Module/Help.php b/src/Module/Help.php index 7c1ecd7465..70c99a0a6f 100644 --- a/src/Module/Help.php +++ b/src/Module/Help.php @@ -36,7 +36,7 @@ class Help extends BaseModule $path .= '/'; } - $path .= $a->getArgumentValue($x); + $path .= DI::args()->get($x); } $title = basename($path); $filename = $path; diff --git a/src/Module/Install.php b/src/Module/Install.php index 228f4be44a..10a6176e40 100644 --- a/src/Module/Install.php +++ b/src/Module/Install.php @@ -57,8 +57,7 @@ class Install extends BaseModule // route: install/testrwrite // $baseurl/install/testrwrite to test if rewrite in .htaccess is working - // @TODO: Replace with parameter from router - if ($a->getArgumentValue(1, '') == 'testrewrite') { + if (DI::args()->get(1, '') == 'testrewrite') { // Status Code 204 means that it worked without content throw new HTTPException\NoContentException(); } From 5609e94b0542c3acf1e9851452eaa8c012768f3d Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Mon, 16 Dec 2019 00:33:35 +0100 Subject: [PATCH 12/34] Refactor deprecated App - process methods to DI::process()->*() --- src/App.php | 26 -------------------------- src/Core/Worker.php | 12 +++++------- src/DI.php | 3 +++ 3 files changed, 8 insertions(+), 33 deletions(-) diff --git a/src/App.php b/src/App.php index 7b0fa07abc..e213b741a3 100644 --- a/src/App.php +++ b/src/App.php @@ -13,12 +13,10 @@ use Friendica\Core\Config\Cache\ConfigCache; use Friendica\Core\Config\Configuration; use Friendica\Core\Config\PConfiguration; use Friendica\Core\L10n\L10n; -use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Core\Theme; use Friendica\Database\Database; use Friendica\Model\Profile; -use Friendica\Module\Security\Login; use Friendica\Module\Special\HTTPException as ModuleHTTPException; use Friendica\Network\HTTPException; use Friendica\Util\ConfigFileLoader; @@ -356,30 +354,6 @@ class App $this->getBaseURL(); } - /** - * @deprecated 2019.09 - use Core\Process->isMaxProcessesReached() instead - */ - public function isMaxProcessesReached() - { - return $this->process->isMaxProcessesReached(); - } - - /** - * @deprecated 2019.09 - use Core\Process->isMinMemoryReached() instead - */ - public function isMinMemoryReached() - { - return $this->process->isMinMemoryReached(); - } - - /** - * @deprecated 2019.09 - use Core\Process->isMaxLoadReached() instead - */ - public function isMaxLoadReached() - { - return $this->process->isMaxLoadReached(); - } - /** * Generates the site's default sender email address * diff --git a/src/Core/Worker.php b/src/Core/Worker.php index 9a1570d72f..62f7bd4c6a 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -56,7 +56,7 @@ class Worker self::$up_start = microtime(true); // At first check the maximum load. We shouldn't continue with a high load - if ($a->isMaxLoadReached()) { + if (DI::process()->isMaxLoadReached()) { Logger::log('Pre check: maximum load reached, quitting.', Logger::DEBUG); return; } @@ -78,7 +78,7 @@ class Worker } // Do we have too few memory? - if ($a->isMinMemoryReached()) { + if (DI::process()->isMinMemoryReached()) { Logger::log('Pre check: Memory limit reached, quitting.', Logger::DEBUG); return; } @@ -90,7 +90,7 @@ class Worker } // Possibly there are too much database processes that block the system - if ($a->isMaxProcessesReached()) { + if (DI::process()->isMaxProcessesReached()) { Logger::log('Pre check: maximum processes reached, quitting.', Logger::DEBUG); return; } @@ -140,7 +140,7 @@ class Worker } // Check free memory - if ($a->isMinMemoryReached()) { + if (DI::process()->isMinMemoryReached()) { Logger::log('Memory limit reached, quitting.', Logger::DEBUG); Lock::release('worker'); return; @@ -251,8 +251,6 @@ class Worker */ public static function execute($queue) { - $a = \get_app(); - $mypid = getmypid(); // Quit when in maintenance @@ -262,7 +260,7 @@ class Worker } // Constantly check the number of parallel database processes - if ($a->isMaxProcessesReached()) { + if (DI::process()->isMaxProcessesReached()) { Logger::log("Max processes reached for process ".$mypid, Logger::DEBUG); return false; } diff --git a/src/DI.php b/src/DI.php index 89b638d226..c3f6d07f9c 100644 --- a/src/DI.php +++ b/src/DI.php @@ -8,6 +8,7 @@ use Friendica\Core\Config\Configuration; use Friendica\Core\Config\PConfiguration; use Friendica\Core\L10n\L10n; use Friendica\Core\Lock\ILock; +use Friendica\Core\Process; use Friendica\Core\Session\ISession; use Friendica\Database\Database; use Friendica\Model\Notify; @@ -51,6 +52,7 @@ use Psr\Log\LoggerInterface; * @method static App\Router router() * @method static Database dba() * @method static FileSystem fs() + * @method static Process process() * */ class DI @@ -82,6 +84,7 @@ class DI 'dba' => Database::class, 'fs' => FileSystem::class, 'profiler' => Profiler::class, + 'process' => Process::class, ]; /** @var Dice */ From e93fba51362a8cc212cb42542fd013ffd28b1164 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Mon, 16 Dec 2019 00:36:31 +0100 Subject: [PATCH 13/34] Remove deprecated App::removeBaseURL - process methods to DI::baseUrl()->remove() --- mod/display.php | 3 ++- mod/profiles.php | 2 +- src/App.php | 15 --------------- src/Content/Nav.php | 3 ++- src/Core/System.php | 2 +- src/Model/Item.php | 2 +- src/Module/Item/Compose.php | 4 ++-- src/Object/Post.php | 8 ++++---- view/theme/frio/theme.php | 3 ++- view/theme/vier/theme.php | 3 ++- 10 files changed, 17 insertions(+), 28 deletions(-) diff --git a/mod/display.php b/mod/display.php index de46cce0cb..0d082f5982 100644 --- a/mod/display.php +++ b/mod/display.php @@ -16,6 +16,7 @@ use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\Core\Session; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Group; use Friendica\Model\Item; @@ -326,7 +327,7 @@ function display_content(App $a, $update = false, $update_uid = 0) $title = trim(HTML::toPlaintext(BBCode::convert($item["title"], false), 0, true)); $author_name = $item["author-name"]; - $image = $a->removeBaseURL($item["author-avatar"]); + $image = DI::baseUrl()->remove($item["author-avatar"]); if ($title == "") { $title = $author_name; diff --git a/mod/profiles.php b/mod/profiles.php index e298df668c..18fe636d3d 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -655,7 +655,7 @@ function profiles_content(App $a) { $profiles = ''; foreach ($r as $rr) { $profiles .= Renderer::replaceMacros($tpl, [ - '$photo' => $a->removeBaseURL($rr['thumb']), + '$photo' => DI::baseUrl()->remove($rr['thumb']), '$id' => $rr['id'], '$alt' => L10n::t('Profile Image'), '$profile_name' => $rr['profile-name'], diff --git a/src/App.php b/src/App.php index e213b741a3..d04c6f3235 100644 --- a/src/App.php +++ b/src/App.php @@ -323,21 +323,6 @@ class App return $this->baseURL->getUrlPath(); } - /** - * @brief Removes the base url from an url. This avoids some mixed content problems. - * - * @param string $origURL - * - * @return string The cleaned url - * - * @deprecated 2019.09 - Use BaseURL->remove() instead - * @see BaseURL::remove() - */ - public function removeBaseURL(string $origURL) - { - return $this->baseURL->remove($origURL); - } - /** * Returns the current UserAgent as a String * diff --git a/src/Content/Nav.php b/src/Content/Nav.php index ff1680ab3f..6fca7beb91 100644 --- a/src/Content/Nav.php +++ b/src/Content/Nav.php @@ -12,6 +12,7 @@ use Friendica\Core\Renderer; use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Profile; use Friendica\Model\User; @@ -167,7 +168,7 @@ class Nav // user info $contact = DBA::selectFirst('contact', ['micro'], ['uid' => $a->user['uid'], 'self' => true]); $userinfo = [ - 'icon' => (DBA::isResult($contact) ? $a->removeBaseURL($contact['micro']) : 'images/person-48.jpg'), + 'icon' => (DBA::isResult($contact) ? DI::baseUrl()->remove($contact['micro']) : 'images/person-48.jpg'), 'name' => $a->user['username'], ]; } diff --git a/src/Core/System.php b/src/Core/System.php index 367e055c93..426eb0a53d 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -41,7 +41,7 @@ class System */ public static function removedBaseUrl(string $orig_url) { - return DI::app()->removeBaseURL($orig_url); + return DI::baseUrl()->remove($orig_url); } /** diff --git a/src/Model/Item.php b/src/Model/Item.php index f955337179..3f3de8f8f1 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -3655,7 +3655,7 @@ class Item ]; if (!empty($item['plink'])) { - $ret["href"] = $a->removeBaseURL($item['plink']); + $ret["href"] = DI::baseUrl()->remove($item['plink']); $ret["title"] = L10n::t('link to source'); } diff --git a/src/Module/Item/Compose.php b/src/Module/Item/Compose.php index 7a26c93cf0..5d4a3c18ed 100644 --- a/src/Module/Item/Compose.php +++ b/src/Module/Item/Compose.php @@ -127,9 +127,9 @@ class Compose extends BaseModule '$type' => $type, '$wall' => $wall, '$default' => '', - '$mylink' => $a->removeBaseURL($a->contact['url']), + '$mylink' => DI::baseUrl()->remove($a->contact['url']), '$mytitle' => L10n::t('This is you'), - '$myphoto' => $a->removeBaseURL($a->contact['thumb']), + '$myphoto' => DI::baseUrl()->remove($a->contact['thumb']), '$submit' => L10n::t('Submit'), '$edbold' => L10n::t('Bold'), '$editalic' => L10n::t('Italic'), diff --git a/src/Object/Post.php b/src/Object/Post.php index e5a66a562f..38ef122748 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -409,7 +409,7 @@ class Post 'profile_url' => $profile_link, 'item_photo_menu' => item_photo_menu($item), 'name' => $name_e, - 'thumb' => $a->removeBaseURL(ProxyUtils::proxifyUrl($item['author-avatar'], false, ProxyUtils::SIZE_THUMB)), + 'thumb' => DI::baseUrl()->remove(ProxyUtils::proxifyUrl($item['author-avatar'], false, ProxyUtils::SIZE_THUMB)), 'osparkle' => $osparkle, 'sparkle' => $sparkle, 'title' => $title_e, @@ -423,7 +423,7 @@ class Post 'shiny' => $shiny, 'owner_self' => $item['author-link'] == Session::get('my_url'), 'owner_url' => $this->getOwnerUrl(), - 'owner_photo' => $a->removeBaseURL(ProxyUtils::proxifyUrl($item['owner-avatar'], false, ProxyUtils::SIZE_THUMB)), + 'owner_photo' => DI::baseUrl()->remove(ProxyUtils::proxifyUrl($item['owner-avatar'], false, ProxyUtils::SIZE_THUMB)), 'owner_name' => $owner_name_e, 'plink' => Item::getPlink($item), 'edpost' => $edpost, @@ -899,9 +899,9 @@ class Post '$qcomment' => $qcomment, '$default' => $default_text, '$profile_uid' => $uid, - '$mylink' => $a->removeBaseURL($a->contact['url']), + '$mylink' => DI::baseUrl()->remove($a->contact['url']), '$mytitle' => L10n::t('This is you'), - '$myphoto' => $a->removeBaseURL($a->contact['thumb']), + '$myphoto' => DI::baseUrl()->remove($a->contact['thumb']), '$comment' => L10n::t('Comment'), '$submit' => L10n::t('Submit'), '$edbold' => L10n::t('Bold'), diff --git a/view/theme/frio/theme.php b/view/theme/frio/theme.php index 5995f54374..1e255e38b0 100644 --- a/view/theme/frio/theme.php +++ b/view/theme/frio/theme.php @@ -17,6 +17,7 @@ use Friendica\Core\Logger; use Friendica\Core\Renderer; use Friendica\Core\Session; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model; use Friendica\Module; use Friendica\Util\Strings; @@ -239,7 +240,7 @@ function frio_remote_nav($a, &$nav) // user info $r = q("SELECT `micro` FROM `contact` WHERE `uid` = %d AND `self`", intval($a->user['uid'])); - $r[0]['photo'] = (DBA::isResult($r) ? $a->removeBaseURL($r[0]['micro']) : 'images/person-48.jpg'); + $r[0]['photo'] = (DBA::isResult($r) ? DI::baseUrl()->remove($r[0]['micro']) : 'images/person-48.jpg'); $r[0]['name'] = $a->user['username']; } elseif (!local_user() && remote_user()) { $r = q("SELECT `name`, `nick`, `micro` AS `photo` FROM `contact` WHERE `id` = %d", intval(remote_user())); diff --git a/view/theme/vier/theme.php b/view/theme/vier/theme.php index e5d71bdf57..2ffa957fe0 100644 --- a/view/theme/vier/theme.php +++ b/view/theme/vier/theme.php @@ -18,6 +18,7 @@ use Friendica\Core\PConfig; use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\GContact; use Friendica\Util\Proxy as ProxyUtils; @@ -163,7 +164,7 @@ function vier_community_info() $entry = Renderer::replaceMacros($tpl, [ '$id' => $rr['id'], '$profile_link' => $profile_link, - '$photo' => $a->removeBaseURL($rr['thumb']), + '$photo' => DI::baseUrl()->remove($rr['thumb']), '$alt_text' => $rr['name']]); $aside['$lastusers_items'][] = $entry; } From 29003896960760c7fe4ed34dddf99c9bb629c3f0 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Mon, 16 Dec 2019 00:39:54 +0100 Subject: [PATCH 14/34] Remove deprecated App::getUrlPath - process methods to DI::baseUrl()->getUrlPath() --- mod/dfrn_request.php | 6 +++--- mod/redir.php | 2 +- mod/settings.php | 2 +- src/App.php | 12 ------------ src/Model/Contact.php | 2 +- src/Module/Admin/Site.php | 4 ++-- src/Module/Magic.php | 2 +- src/Module/Profile.php | 2 +- view/theme/frio/php/default.php | 3 ++- 9 files changed, 12 insertions(+), 23 deletions(-) diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index f7c9d9aafc..24548c027a 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -457,8 +457,8 @@ function dfrn_request_post(App $a) if ($network == Protocol::DIASPORA) { $uri = $nickname . '@' . $a->getHostName(); - if ($a->getURLPath()) { - $uri .= '/' . $a->getURLPath(); + if (DI::baseUrl()->getUrlPath()) { + $uri .= '/' . DI::baseUrl()->getUrlPath(); } $uri = urlencode($uri); @@ -610,7 +610,7 @@ function dfrn_request_content(App $a) } elseif (!empty($_GET['address'])) { $myaddr = $_GET['address']; } elseif (local_user()) { - if (strlen($a->getURLPath())) { + if (strlen(DI::baseUrl()->getUrlPath())) { $myaddr = System::baseUrl() . '/profile/' . $a->user['nickname']; } else { $myaddr = $a->user['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3); diff --git a/mod/redir.php b/mod/redir.php index 57f96a7ac6..6083117b40 100644 --- a/mod/redir.php +++ b/mod/redir.php @@ -60,7 +60,7 @@ function redir_init(App $a) { } if (remote_user()) { - $host = substr($a->getBaseURL() . ($a->getURLPath() ? '/' . $a->getURLPath() : ''), strpos($a->getBaseURL(), '://') + 3); + $host = substr(DI::baseUrl()->getUrlPath() . (DI::baseUrl()->getUrlPath() ? '/' . DI::baseUrl()->getUrlPath() : ''), strpos(DI::baseUrl()->getUrlPath(), '://') + 3); $remotehost = substr($contact['addr'], strpos($contact['addr'], '@') + 1); // On a local instance we have to check if the local user has already authenticated diff --git a/mod/settings.php b/mod/settings.php index 416a8adcda..c01d179388 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -1127,7 +1127,7 @@ function settings_content(App $a) $tpl_addr = Renderer::getMarkupTemplate('settings/nick_set.tpl'); $prof_addr = Renderer::replaceMacros($tpl_addr,[ - '$desc' => L10n::t("Your Identity Address is '%s' or '%s'.", $nickname . '@' . $a->getHostName() . $a->getURLPath(), System::baseUrl() . '/profile/' . $nickname), + '$desc' => L10n::t("Your Identity Address is '%s' or '%s'.", $nickname . '@' . $a->getHostName() . DI::baseUrl()->getUrlPath(), System::baseUrl() . '/profile/' . $nickname), '$basepath' => $a->getHostName() ]); diff --git a/src/App.php b/src/App.php index d04c6f3235..01702967e2 100644 --- a/src/App.php +++ b/src/App.php @@ -311,18 +311,6 @@ class App return $this->baseURL->getHostname(); } - /** - * Returns the sub-path of the full URL - * - * @return string - * - * @deprecated 2019.06 - use BaseURL->getUrlPath() instead - */ - public function getURLPath() - { - return $this->baseURL->getUrlPath(); - } - /** * Returns the current UserAgent as a String * diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 8d4b8c6312..f06156d01e 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -2266,7 +2266,7 @@ class Contact if (($protocol === Protocol::DFRN) && !DBA::isResult($contact)) { if ($interactive) { - if (strlen($a->getURLPath())) { + if (strlen(DI::baseUrl()->getUrlPath())) { $myaddr = bin2hex(System::baseUrl() . '/profile/' . $a->user['nickname']); } else { $myaddr = bin2hex($a->user['nickname'] . '@' . $a->getHostName()); diff --git a/src/Module/Admin/Site.php b/src/Module/Admin/Site.php index 42b35edff3..6467bd4c52 100644 --- a/src/Module/Admin/Site.php +++ b/src/Module/Admin/Site.php @@ -242,7 +242,7 @@ class Site extends BaseAdminModule Worker::add(PRIORITY_LOW, 'Directory'); } - if ($a->getURLPath() != "") { + if (DI::baseUrl()->getUrlPath() != "") { $diaspora_enabled = false; } if ($ssl_policy != intval(Config::get('system', 'ssl_policy'))) { @@ -523,7 +523,7 @@ class Site extends BaseAdminModule 'develop' => L10n::t('check the development version') ]; - $diaspora_able = ($a->getURLPath() == ''); + $diaspora_able = (DI::baseUrl()->getUrlPath() == ''); $optimize_max_tablesize = Config::get('system', 'optimize_max_tablesize', -1); diff --git a/src/Module/Magic.php b/src/Module/Magic.php index d34f7e8744..b0d2b82b28 100644 --- a/src/Module/Magic.php +++ b/src/Module/Magic.php @@ -80,7 +80,7 @@ class Magic extends BaseModule $headers = HTTPSignature::createSig( $headers, $user['prvkey'], - 'acct:' . $user['nickname'] . '@' . $a->getHostName() . ($a->getURLPath() ? '/' . $a->getURLPath() : '') + 'acct:' . $user['nickname'] . '@' . $a->getHostName() . (DI::baseUrl()->getUrlPath() ? '/' . DI::baseUrl()->getUrlPath() : '') ); // Try to get an authentication token from the other instance. diff --git a/src/Module/Profile.php b/src/Module/Profile.php index 0515d22e18..cbb953dd75 100644 --- a/src/Module/Profile.php +++ b/src/Module/Profile.php @@ -120,7 +120,7 @@ class Profile extends BaseModule $a->page['htmlhead'] .= '' . "\n"; $a->page['htmlhead'] .= '' . "\n"; $a->page['htmlhead'] .= '' . "\n"; - $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $a->getHostName() . ($a->getURLPath() ? '/' . $a->getURLPath() : '')); + $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $a->getHostName() . (DI::baseUrl()->getUrlPath() ? '/' . DI::baseUrl()->getUrlPath() : '')); $a->page['htmlhead'] .= '' . "\n"; header('Link: <' . System::baseUrl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false); diff --git a/view/theme/frio/php/default.php b/view/theme/frio/php/default.php index 6b39e68acb..73ceea5845 100644 --- a/view/theme/frio/php/default.php +++ b/view/theme/frio/php/default.php @@ -10,6 +10,7 @@ use Friendica\Core\Config; use Friendica\Core\PConfig; use Friendica\Core\System; +use Friendica\DI; use Friendica\Model\Profile; require_once 'view/theme/frio/php/frio_boot.php'; @@ -19,7 +20,7 @@ if (!isset($minimal)) { $minimal = false; } -$basepath = $a->getURLPath() ? "/" . $a->getURLPath() . "/" : "/"; +$basepath = DI::baseUrl()->getUrlPath() ? "/" . DI::baseUrl()->getUrlPath() . "/" : "/"; $frio = "view/theme/frio"; $view_mode_class = ($a->is_mobile || $a->is_tablet) ? 'mobile-view' : 'desktop-view'; $is_singleuser = Config::get('system', 'singleuser'); From 50be94aa5ecdceb10de0d6b4764b8eeca78a826f Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Mon, 16 Dec 2019 00:47:24 +0100 Subject: [PATCH 15/34] Remove deprecated App::getHostName() - process methods to DI::baseUrl()->getHostName() --- boot.php | 4 +--- include/api.php | 4 +--- include/enotify.php | 3 ++- mod/dfrn_request.php | 2 +- mod/settings.php | 4 ++-- src/App.php | 12 ------------ src/Core/System.php | 2 +- src/Model/Contact.php | 2 +- src/Model/Item.php | 6 ++---- src/Model/Profile.php | 3 ++- src/Model/User.php | 4 ++-- src/Module/Magic.php | 2 +- src/Module/OpenSearch.php | 2 +- src/Module/Profile.php | 2 +- src/Module/Register.php | 4 ++-- src/Module/WellKnown/HostMeta.php | 2 +- src/Network/Probe.php | 3 ++- src/Protocol/Feed.php | 3 ++- src/Protocol/OStatus.php | 3 ++- src/Util/ExAuth.php | 9 +++------ src/Worker/CronJobs.php | 2 +- src/Worker/Delivery.php | 4 ++-- src/Worker/Notifier.php | 2 +- 23 files changed, 34 insertions(+), 50 deletions(-) diff --git a/boot.php b/boot.php index ecf83854ff..fa99a7bb39 100644 --- a/boot.php +++ b/boot.php @@ -482,8 +482,6 @@ function get_server() function get_temppath() { - $a = \get_app(); - $temppath = Config::get("system", "temppath"); if (($temppath != "") && System::isDirectoryUsable($temppath)) { @@ -500,7 +498,7 @@ function get_temppath() $temppath = BasePath::getRealPath($temppath); // To avoid any interferences with other systems we create our own directory - $new_temppath = $temppath . "/" . $a->getHostName(); + $new_temppath = $temppath . "/" . DI::baseUrl()->getHostname(); if (!is_dir($new_temppath)) { /// @TODO There is a mkdir()+chmod() upwards, maybe generalize this (+ configurable) into a function/method? mkdir($new_temppath); diff --git a/include/api.php b/include/api.php index d2b41f988d..2681b7b4ca 100644 --- a/include/api.php +++ b/include/api.php @@ -3563,10 +3563,8 @@ api_register_func('api/friendships/incoming', 'api_friendships_incoming', true); */ function api_statusnet_config($type) { - $a = \get_app(); - $name = Config::get('config', 'sitename'); - $server = $a->getHostName(); + $server = DI::baseUrl()->getHostname(); $logo = System::baseUrl() . '/images/friendica-64.png'; $email = Config::get('config', 'admin_email'); $closed = intval(Config::get('config', 'register_policy')) === \Friendica\Module\Register::CLOSED ? 'true' : 'false'; diff --git a/include/enotify.php b/include/enotify.php index c0f23b0848..24f4429f67 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -12,6 +12,7 @@ use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\Model\Contact; +use Friendica\DI; use Friendica\Model\Item; use Friendica\Model\User; use Friendica\Protocol\Activity; @@ -68,7 +69,7 @@ function notification($params) } $sender_name = $sitename; - $hostname = $a->getHostName(); + $hostname = DI::baseUrl()->getHostname(); if (strpos($hostname, ':')) { $hostname = substr($hostname, 0, strpos($hostname, ':')); } diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index 24548c027a..0c0e5421ad 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -455,7 +455,7 @@ function dfrn_request_post(App $a) // Diaspora needs the uri in the format user@domain.tld // Diaspora will support the remote subscription in a future version if ($network == Protocol::DIASPORA) { - $uri = $nickname . '@' . $a->getHostName(); + $uri = $nickname . '@' . DI::baseUrl()->getHostname(); if (DI::baseUrl()->getUrlPath()) { $uri .= '/' . DI::baseUrl()->getUrlPath(); diff --git a/mod/settings.php b/mod/settings.php index c01d179388..eb664e378a 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -1127,8 +1127,8 @@ function settings_content(App $a) $tpl_addr = Renderer::getMarkupTemplate('settings/nick_set.tpl'); $prof_addr = Renderer::replaceMacros($tpl_addr,[ - '$desc' => L10n::t("Your Identity Address is '%s' or '%s'.", $nickname . '@' . $a->getHostName() . DI::baseUrl()->getUrlPath(), System::baseUrl() . '/profile/' . $nickname), - '$basepath' => $a->getHostName() + '$desc' => L10n::t("Your Identity Address is '%s' or '%s'.", $nickname . '@' . DI::baseUrl()->getHostname() . DI::baseUrl()->getUrlPath(), System::baseUrl() . '/profile/' . $nickname), + '$basepath' => DI::baseUrl()->getHostname() ]); $stpl = Renderer::getMarkupTemplate('settings/settings.tpl'); diff --git a/src/App.php b/src/App.php index 01702967e2..b414926006 100644 --- a/src/App.php +++ b/src/App.php @@ -299,18 +299,6 @@ class App $this->baseURL->saveByURL($url); } - /** - * Returns the current hostname - * - * @return string - * - * @deprecated 2019.06 - use BaseURL->getHostname() instead - */ - public function getHostName() - { - return $this->baseURL->getHostname(); - } - /** * Returns the current UserAgent as a String * diff --git a/src/Core/System.php b/src/Core/System.php index 426eb0a53d..d5902c003a 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -182,7 +182,7 @@ class System if (is_bool($prefix) && !$prefix) { $prefix = ''; } elseif (empty($prefix)) { - $prefix = hash('crc32', DI::app()->getHostName()); + $prefix = hash('crc32', DI::baseUrl()->getHostname()); } while (strlen($prefix) < ($size - 13)) { diff --git a/src/Model/Contact.php b/src/Model/Contact.php index f06156d01e..84481b9fa5 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -2269,7 +2269,7 @@ class Contact if (strlen(DI::baseUrl()->getUrlPath())) { $myaddr = bin2hex(System::baseUrl() . '/profile/' . $a->user['nickname']); } else { - $myaddr = bin2hex($a->user['nickname'] . '@' . $a->getHostName()); + $myaddr = bin2hex($a->user['nickname'] . '@' . DI::baseUrl()->getHostname()); } DI::baseUrl()->redirect($ret['request'] . "&addr=$myaddr"); diff --git a/src/Model/Item.php b/src/Model/Item.php index 3f3de8f8f1..507ee654ec 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1279,7 +1279,7 @@ class Item if ($notify) { // We have to avoid duplicates. So we create the GUID in form of a hash of the plink or uri. // We add the hash of our own host because our host is the original creator of the post. - $prefix_host = \get_app()->getHostName(); + $prefix_host = DI::baseUrl()->getHostname(); } else { $prefix_host = ''; @@ -2752,8 +2752,6 @@ class Item public static function isRemoteSelf($contact, &$datarray) { - $a = \get_app(); - if (!$contact['remote_self']) { return false; } @@ -2765,7 +2763,7 @@ class Item } // Prevent to forward already forwarded posts - if ($datarray["app"] == $a->getHostName()) { + if ($datarray["app"] == DI::baseUrl()->getHostname()) { Logger::log('Already forwarded (second test)', Logger::DEBUG); return false; } diff --git a/src/Model/Profile.php b/src/Model/Profile.php index 8659506cb1..3f7877c558 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -23,6 +23,7 @@ use Friendica\Core\System; use Friendica\Core\Theme; use Friendica\Core\Worker; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Protocol\Activity; use Friendica\Protocol\Diaspora; use Friendica\Util\DateTimeFormat; @@ -1175,7 +1176,7 @@ class Profile $a->contact = $arr['visitor']; - info(L10n::t('OpenWebAuth: %1$s welcomes %2$s', $a->getHostName(), $visitor['name'])); + info(L10n::t('OpenWebAuth: %1$s welcomes %2$s', DI::baseUrl()->getHostname(), $visitor['name'])); Logger::log('OpenWebAuth: auth success from ' . $visitor['addr'], Logger::DEBUG); } diff --git a/src/Model/User.php b/src/Model/User.php index 4f270d2d12..22a8b04744 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -18,6 +18,7 @@ use Friendica\Core\Protocol; use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\TwoFactor\AppSpecificPassword; use Friendica\Object\Image; use Friendica\Util\Crypto; @@ -587,7 +588,6 @@ class User */ public static function create(array $data) { - $a = \get_app(); $return = ['user' => null, 'password' => '']; $using_invites = Config::get('system', 'invitation_only'); @@ -633,7 +633,7 @@ class User $_SESSION['register'] = 1; $_SESSION['openid'] = $openid_url; - $openid = new LightOpenID($a->getHostName()); + $openid = new LightOpenID(DI::baseUrl()->getHostname()); $openid->identity = $openid_url; $openid->returnUrl = System::baseUrl() . '/openid'; $openid->required = ['namePerson/friendly', 'contact/email', 'namePerson']; diff --git a/src/Module/Magic.php b/src/Module/Magic.php index b0d2b82b28..b878b0e701 100644 --- a/src/Module/Magic.php +++ b/src/Module/Magic.php @@ -80,7 +80,7 @@ class Magic extends BaseModule $headers = HTTPSignature::createSig( $headers, $user['prvkey'], - 'acct:' . $user['nickname'] . '@' . $a->getHostName() . (DI::baseUrl()->getUrlPath() ? '/' . DI::baseUrl()->getUrlPath() : '') + 'acct:' . $user['nickname'] . '@' . DI::baseUrl()->getHostname()() . (DI::baseUrl()->getUrlPath() ? '/' . DI::baseUrl()->getUrlPath() : '') ); // Try to get an authentication token from the other instance. diff --git a/src/Module/OpenSearch.php b/src/Module/OpenSearch.php index acab0f5ed4..dbf04040b8 100644 --- a/src/Module/OpenSearch.php +++ b/src/Module/OpenSearch.php @@ -21,7 +21,7 @@ class OpenSearch extends BaseModule { header('Content-type: application/opensearchdescription+xml'); - $hostname = DI::app()->getHostName(); + $hostname = DI::baseUrl()->getHostname()(); $baseUrl = DI::app()->getBaseURL(); /** @var DOMDocument $xml */ diff --git a/src/Module/Profile.php b/src/Module/Profile.php index cbb953dd75..04364ba0cc 100644 --- a/src/Module/Profile.php +++ b/src/Module/Profile.php @@ -120,7 +120,7 @@ class Profile extends BaseModule $a->page['htmlhead'] .= '' . "\n"; $a->page['htmlhead'] .= '' . "\n"; $a->page['htmlhead'] .= '' . "\n"; - $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $a->getHostName() . (DI::baseUrl()->getUrlPath() ? '/' . DI::baseUrl()->getUrlPath() : '')); + $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . DI::baseUrl()->getHostname() . (DI::baseUrl()->getUrlPath() ? '/' . DI::baseUrl()->getUrlPath() : '')); $a->page['htmlhead'] .= '' . "\n"; header('Link: <' . System::baseUrl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false); diff --git a/src/Module/Register.php b/src/Module/Register.php index 2c9b00bf0c..613b3da7b5 100644 --- a/src/Module/Register.php +++ b/src/Module/Register.php @@ -124,7 +124,7 @@ class Register extends BaseModule '$ask_password' => $ask_password, '$password1' => ['password1', L10n::t('New Password:'), '', L10n::t('Leave empty for an auto generated password.')], '$password2' => ['confirm', L10n::t('Confirm:'), '', ''], - '$nickdesc' => L10n::t('Choose a profile nickname. This must begin with a text character. Your profile address on this site will then be "nickname@%s".', DI::app()->getHostName()), + '$nickdesc' => L10n::t('Choose a profile nickname. This must begin with a text character. Your profile address on this site will then be "nickname@%s".', DI::baseUrl()->getHostname()), '$nicklabel' => L10n::t('Choose a nickname: '), '$photo' => $photo, '$publish' => $profile_publish, @@ -132,7 +132,7 @@ class Register extends BaseModule '$username' => $username, '$email' => $email, '$nickname' => $nickname, - '$sitename' => DI::app()->getHostName(), + '$sitename' => DI::baseUrl()->getHostname()(), '$importh' => L10n::t('Import'), '$importt' => L10n::t('Import your profile to this friendica instance'), '$showtoslink' => Config::get('system', 'tosdisplay'), diff --git a/src/Module/WellKnown/HostMeta.php b/src/Module/WellKnown/HostMeta.php index aec95c2a27..2e63f300de 100644 --- a/src/Module/WellKnown/HostMeta.php +++ b/src/Module/WellKnown/HostMeta.php @@ -30,7 +30,7 @@ class HostMeta extends BaseModule $tpl = Renderer::getMarkupTemplate('xrd_host.tpl'); echo Renderer::replaceMacros($tpl, [ - '$zhost' => $app->getHostName(), + '$zhost' => DI::baseUrl()->getHostname()(), '$zroot' => $app->getBaseURL(), '$domain' => $app->getBaseURL(), '$bigkey' => Salmon::salmonKey($config->get('system', 'site_pubkey')) diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 878198504d..aa0b2e0441 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -17,6 +17,7 @@ use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Profile; use Friendica\Protocol\ActivityNamespace; @@ -76,7 +77,7 @@ class Probe */ private static function ownHost($host) { - $own_host = \get_app()->getHostName(); + $own_host = DI::baseUrl()->getHostname(); $parts = parse_url($host); diff --git a/src/Protocol/Feed.php b/src/Protocol/Feed.php index 705a094c38..c30e08f7be 100644 --- a/src/Protocol/Feed.php +++ b/src/Protocol/Feed.php @@ -13,6 +13,7 @@ use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Item; use Friendica\Protocol\ActivityNamespace; use Friendica\Util\ParseUrl; @@ -465,7 +466,7 @@ class Feed { // Distributed items should have a well formatted URI. // Additionally we have to avoid conflicts with identical URI between imported feeds and these items. if ($notify) { - $item['guid'] = Item::guidFromUri($orig_plink, $a->getHostName()); + $item['guid'] = Item::guidFromUri($orig_plink, DI::baseUrl()->getHostname()()); unset($item['uri']); unset($item['parent-uri']); diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index a63b12731d..f1cfa54c0f 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -17,6 +17,7 @@ use Friendica\Core\PConfig; use Friendica\Core\Protocol; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\APContact; use Friendica\Model\Contact; use Friendica\Model\Conversation; @@ -1846,7 +1847,7 @@ class OStatus } $item["uri"] = $item['parent-uri'] = $item['thr-parent'] - = 'tag:'.get_app()->getHostName(). + = 'tag:' . DI::baseUrl()->getHostname()(). ','.date('Y-m-d').':'.$action.':'.$owner['uid']. ':person:'.$connect_id.':'.$item['created']; diff --git a/src/Util/ExAuth.php b/src/Util/ExAuth.php index 46452f6e4e..cf98312aa3 100644 --- a/src/Util/ExAuth.php +++ b/src/Util/ExAuth.php @@ -37,6 +37,7 @@ namespace Friendica\Util; use Friendica\Core\Config; use Friendica\Core\PConfig; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\User; class ExAuth @@ -123,8 +124,6 @@ class ExAuth */ private function isUser(array $aCommand) { - $a = \get_app(); - // Check if there is a username if (!isset($aCommand[1])) { $this->writeLog(LOG_NOTICE, 'invalid isuser command, no username given'); @@ -140,7 +139,7 @@ class ExAuth $sUser = str_replace(['%20', '(a)'], [' ', '@'], $aCommand[1]); // Does the hostname match? So we try directly - if ($a->getHostName() == $aCommand[2]) { + if (DI::baseUrl()->getHostname() == $aCommand[2]) { $this->writeLog(LOG_INFO, 'internal user check for ' . $sUser . '@' . $aCommand[2]); $found = DBA::exists('user', ['nickname' => $sUser]); } else { @@ -205,8 +204,6 @@ class ExAuth */ private function auth(array $aCommand) { - $a = \get_app(); - // check user authentication if (sizeof($aCommand) != 4) { $this->writeLog(LOG_NOTICE, 'invalid auth command, data missing'); @@ -222,7 +219,7 @@ class ExAuth $sUser = str_replace(['%20', '(a)'], [' ', '@'], $aCommand[1]); // Does the hostname match? So we try directly - if ($a->getHostName() == $aCommand[2]) { + if (DI::baseUrl()->getHostname() == $aCommand[2]) { $this->writeLog(LOG_INFO, 'internal auth for ' . $sUser . '@' . $aCommand[2]); $aUser = DBA::selectFirst('user', ['uid', 'password', 'legacy_password'], ['nickname' => $sUser]); diff --git a/src/Worker/CronJobs.php b/src/Worker/CronJobs.php index e8553ed1c1..6267bf6f33 100644 --- a/src/Worker/CronJobs.php +++ b/src/Worker/CronJobs.php @@ -47,7 +47,7 @@ class CronJobs Logger::info('cron_start'); Nodeinfo::update(); // Now trying to register - $url = 'http://the-federation.info/register/' . $a->getHostName(); + $url = 'http://the-federation.info/register/' . DI::baseUrl()->getHostname(); Logger::debug('Check registering url', ['url' => $url]); $ret = Network::fetchUrl($url); Logger::debug('Check registering answer', ['answer' => $ret]); diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index ef5a7b9f20..ed2ff2979d 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -140,7 +140,7 @@ class Delivery // if $parent['wall'] == 1 we will already have the parent message in our array // and we will relay the whole lot. - $localhost = DI::app()->getHostName(); + $localhost = DI::baseUrl()->getHostname(); if (strpos($localhost, ':')) { $localhost = substr($localhost, 0, strpos($localhost, ':')); } @@ -548,7 +548,7 @@ class Delivery $headers = 'From: ' . Email::encodeHeader($local_user['username'],'UTF-8') . ' <' . $local_user['email'] . '>' . "\n"; } } else { - $headers = 'From: '. Email::encodeHeader($local_user['username'], 'UTF-8') . ' getHostName() . '>' . "\n"; + $headers = 'From: '. Email::encodeHeader($local_user['username'], 'UTF-8') . ' getHostname() . '>' . "\n"; } $headers .= 'Message-Id: <' . Email::iri2msgid($target_item['uri']) . '>' . "\n"; diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index d6bf0ef484..fea2da7e32 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -180,7 +180,7 @@ class Notifier // if $parent['wall'] == 1 we will already have the parent message in our array // and we will relay the whole lot. - $localhost = str_replace('www.','',$a->getHostName()); + $localhost = str_replace('www.','', DI::baseUrl()->getHostname()); if (strpos($localhost,':')) { $localhost = substr($localhost,0,strpos($localhost,':')); } From e57a87f2249caffa547d7ec3228102b92248cae3 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Mon, 16 Dec 2019 00:48:20 +0100 Subject: [PATCH 16/34] Remove deprecated App::setBaseURL() - process methods to DI::baseUrl()->saveByURL() --- bin/worker.php | 2 +- src/App.php | 14 -------------- src/Module/Admin/Site.php | 2 +- 3 files changed, 2 insertions(+), 16 deletions(-) diff --git a/bin/worker.php b/bin/worker.php index a478159195..b2d97cc115 100755 --- a/bin/worker.php +++ b/bin/worker.php @@ -46,7 +46,7 @@ if (!DI::mode()->has(App\Mode::MAINTENANCEDISABLED)) { return; } -$a->setBaseURL(Config::get('system', 'url')); +DI::baseUrl()->saveByURL(Config::get('system', 'url')); $spawn = array_key_exists('s', $options) || array_key_exists('spawn', $options); diff --git a/src/App.php b/src/App.php index b414926006..c00a574c2d 100644 --- a/src/App.php +++ b/src/App.php @@ -285,20 +285,6 @@ class App return $this->baseURL->get($ssl); } - /** - * @brief Initializes the baseurl components - * - * Clears the baseurl cache to prevent inconsistencies - * - * @param string $url - * - * @deprecated 2019.06 - use BaseURL->saveByURL($url) instead - */ - public function setBaseURL($url) - { - $this->baseURL->saveByURL($url); - } - /** * Returns the current UserAgent as a String * diff --git a/src/Module/Admin/Site.php b/src/Module/Admin/Site.php index 6467bd4c52..267680583d 100644 --- a/src/Module/Admin/Site.php +++ b/src/Module/Admin/Site.php @@ -95,7 +95,7 @@ class Site extends BaseAdminModule // update config Config::set('system', 'url', $new_url); - $a->setBaseURL($new_url); + DI::baseUrl()->saveByURL($new_url); // send relocate $usersStmt = DBA::select('user', ['uid'], ['account_removed' => false, 'account_expired' => false]); From e944d7bed6b971494bff82396960d280e6a82cca Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Mon, 16 Dec 2019 01:05:15 +0100 Subject: [PATCH 17/34] Remove deprecated App::getBaseURL() - process methods to DI::baseUrl()->get() --- mod/dfrn_request.php | 2 +- mod/profile_photo.php | 2 +- mod/regmod.php | 4 +--- mod/removeme.php | 2 +- mod/settings.php | 2 +- src/App.php | 20 +++----------------- src/Content/Text/BBCode.php | 2 +- src/Core/Renderer.php | 3 +-- src/Model/Item.php | 2 +- src/Model/Photo.php | 6 ++---- src/Model/Profile.php | 6 +++--- src/Module/Admin/Addons/Details.php | 2 +- src/Module/Admin/Addons/Index.php | 4 +--- src/Module/Admin/Blocklist/Contact.php | 2 +- src/Module/Admin/Blocklist/Server.php | 4 +--- src/Module/Admin/DBSync.php | 4 ++-- src/Module/Admin/Logs/Settings.php | 4 +--- src/Module/Admin/Site.php | 10 ++++------ src/Module/Admin/Summary.php | 10 +++++----- src/Module/Admin/Themes/Details.php | 2 +- src/Module/Admin/Themes/Index.php | 6 ++---- src/Module/Admin/Users.php | 6 ++---- src/Module/AllFriends.php | 2 +- src/Module/BaseSearchModule.php | 4 +--- src/Module/Bookmarklet.php | 2 +- src/Module/Contact.php | 4 ++-- src/Module/Debug/Localtime.php | 2 +- src/Module/Diaspora/Fetch.php | 2 +- src/Module/Friendica.php | 11 +++++------ src/Module/Help.php | 2 +- src/Module/Home.php | 2 +- src/Module/Install.php | 12 +++++------- src/Module/Invite.php | 6 +++--- src/Module/Magic.php | 2 +- src/Module/OpenSearch.php | 2 +- src/Module/ReallySimpleDiscovery.php | 3 +-- src/Module/Security/Login.php | 4 ++-- src/Module/WellKnown/HostMeta.php | 5 ++--- src/Module/WellKnown/NodeInfo.php | 13 ++++--------- src/Module/WellKnown/XSocialRelay.php | 5 ++--- src/Module/Xrd.php | 4 ++-- src/Protocol/ActivityPub/Transmitter.php | 2 +- src/Protocol/DFRN.php | 2 +- 43 files changed, 76 insertions(+), 120 deletions(-) diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index 0c0e5421ad..f7dc5f55cd 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -437,7 +437,7 @@ function dfrn_request_post(App $a) } // "Homecoming" - send the requestor back to their site to record the introduction. - $dfrn_url = bin2hex($a->getBaseURL() . '/profile/' . $nickname); + $dfrn_url = bin2hex(DI::baseUrl()->get() . '/profile/' . $nickname); $aes_allow = ((function_exists('openssl_encrypt')) ? 1 : 0); System::externalRedirect($parms['dfrn-request'] . "?dfrn_url=$dfrn_url" diff --git a/mod/profile_photo.php b/mod/profile_photo.php index 412d19029e..6d625cedeb 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -126,7 +126,7 @@ function profile_photo_post(App $a) info(L10n::t('Shift-reload the page or clear browser cache if the new photo does not display immediately.') . EOL); // Update global directory in background if ($path && strlen(Config::get('system', 'directory'))) { - Worker::add(PRIORITY_LOW, "Directory", $a->getBaseURL() . '/' . $path); + Worker::add(PRIORITY_LOW, "Directory", DI::baseUrl()->get() . '/' . $path); } Worker::add(PRIORITY_LOW, 'ProfileUpdate', local_user()); diff --git a/mod/regmod.php b/mod/regmod.php index 0fc5a88994..e08edfbcc9 100644 --- a/mod/regmod.php +++ b/mod/regmod.php @@ -16,8 +16,6 @@ use Friendica\Module\Security\Login; function user_allow($hash) { - $a = \get_app(); - $register = Register::getByHash($hash); if (!DBA::isResult($register)) { return false; @@ -45,7 +43,7 @@ function user_allow($hash) $l10n, $user, Config::get('config', 'sitename'), - $a->getBaseUrl(), + DI::baseUrl()->get(), ($register['password'] ?? '') ?: 'Sent in a previous email' ); diff --git a/mod/removeme.php b/mod/removeme.php index 30e332d328..ecf65c04c1 100644 --- a/mod/removeme.php +++ b/mod/removeme.php @@ -80,7 +80,7 @@ function removeme_content(App $a) $tpl = Renderer::getMarkupTemplate('removeme.tpl'); $o = Renderer::replaceMacros($tpl, [ - '$basedir' => $a->getBaseURL(), + '$basedir' => DI::baseUrl()->get(), '$hash' => $hash, '$title' => L10n::t('Remove My Account'), '$desc' => L10n::t('This will completely remove your account. Once this has been done it is not recoverable.'), diff --git a/mod/settings.php b/mod/settings.php index eb664e378a..7dad1f04c1 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -721,7 +721,7 @@ function settings_content(App $a) $tpl = Renderer::getMarkupTemplate('settings/oauth.tpl'); $o .= Renderer::replaceMacros($tpl, [ '$form_security_token' => BaseModule::getFormSecurityToken("settings_oauth"), - '$baseurl' => $a->getBaseURL(true), + '$baseurl' => DI::baseUrl()->get(true), '$title' => L10n::t('Connected Apps'), '$add' => L10n::t('Add application'), '$edit' => L10n::t('Edit'), diff --git a/src/App.php b/src/App.php index c00a574c2d..35ef04df6e 100644 --- a/src/App.php +++ b/src/App.php @@ -271,20 +271,6 @@ class App return $this->baseURL->getScheme(); } - /** - * Retrieves the Friendica instance base URL - * - * @param bool $ssl Whether to append http or https under BaseURL::SSL_POLICY_SELFSIGN - * - * @return string Friendica server base URL - * - * @deprecated 2019.09 - use BaseUrl->get($ssl) instead - */ - public function getBaseURL($ssl = false) - { - return $this->baseURL->get($ssl); - } - /** * Returns the current UserAgent as a String * @@ -298,7 +284,7 @@ class App FRIENDICA_CODENAME . "' " . FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION . '; ' . - $this->getBaseURL(); + $this->baseURL->get(); } /** @@ -478,8 +464,8 @@ class App // and www.example.com vs example.com. // We will only change the url to an ip address if there is no existing setting - if (empty($url) || (!Util\Strings::compareLink($url, $this->getBaseURL())) && (!preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $this->baseURL->getHostname()))) { - $this->config->set('system', 'url', $this->getBaseURL()); + if (empty($url) || (!Util\Strings::compareLink($url, $this->baseURL->get())) && (!preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $this->baseURL->getHostname()))) { + $this->config->set('system', 'url', $this->baseURL->get()); } } diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index f7ca6efd97..ada0a0f35a 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1152,7 +1152,7 @@ class BBCode $a = DI::app(); // When the picture link is the own photo path then we can avoid fetching the link - $own_photo_url = preg_quote(Strings::normaliseLink($a->getBaseURL()) . '/photos/'); + $own_photo_url = preg_quote(Strings::normaliseLink(DI::baseUrl()->get()) . '/photos/'); if (preg_match('|' . $own_photo_url . '.*?/image/|', Strings::normaliseLink($match[1]))) { if (!empty($match[3])) { $text = '[img=' . str_replace('-1.', '-0.', $match[2]) . ']' . $match[3] . '[/img]'; diff --git a/src/Core/Renderer.php b/src/Core/Renderer.php index 8366d0db80..32247310cf 100644 --- a/src/Core/Renderer.php +++ b/src/Core/Renderer.php @@ -61,10 +61,9 @@ class Renderer public static function replaceMacros($s, array $vars = []) { $stamp1 = microtime(true); - $a = DI::app(); // pass $baseurl to all templates if it isn't set - $vars = array_merge(['$baseurl' => $a->getBaseURL()], $vars); + $vars = array_merge(['$baseurl' => DI::baseUrl()->get()], $vars); $t = self::getTemplateEngine(); diff --git a/src/Model/Item.php b/src/Model/Item.php index 507ee654ec..16a6a0a24c 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -2511,7 +2511,7 @@ class Item $guid = System::createUUID(); } - return DI::app()->getBaseURL() . '/objects/' . $guid; + return DI::baseUrl()->get() . '/objects/' . $guid; } /** diff --git a/src/Model/Photo.php b/src/Model/Photo.php index af17cc395e..dd49892240 100644 --- a/src/Model/Photo.php +++ b/src/Model/Photo.php @@ -679,8 +679,7 @@ class Photo */ public static function getGUID($name) { - $a = \get_app(); - $base = $a->getBaseURL(); + $base = DI::baseUrl()->get(); $guid = str_replace([Strings::normaliseLink($base), '/photo/'], '', Strings::normaliseLink($name)); @@ -725,8 +724,7 @@ class Photo */ public static function isLocalPage($name) { - $a = \get_app(); - $base = $a->getBaseURL(); + $base = DI::baseUrl()->get(); $guid = str_replace(Strings::normaliseLink($base), '', Strings::normaliseLink($name)); $guid = preg_replace("=/photos/.*/image/(.*)=ism", '$1', $guid); diff --git a/src/Model/Profile.php b/src/Model/Profile.php index 3f7877c558..0ebb400f6e 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -337,7 +337,7 @@ class Profile if (isset($profile['url'])) { $profile_url = $profile['url']; } else { - $profile_url = $a->getBaseURL() . '/profile/' . $profile['nickname']; + $profile_url = DI::baseUrl()->get() . '/profile/' . $profile['nickname']; } $follow_link = null; @@ -1080,13 +1080,13 @@ class Profile $query = rtrim(str_replace($addr_request, '', $a->query_string), '?&'); // The other instance needs to know where to redirect. - $dest = urlencode($a->getBaseURL() . '/' . $query); + $dest = urlencode(DI::baseUrl()->get() . '/' . $query); // We need to extract the basebath from the profile url // to redirect the visitors '/magic' module. $basepath = Contact::getBasepath($contact['url']); - if ($basepath != $a->getBaseURL() && !strstr($dest, '/magic')) { + if ($basepath != DI::baseUrl()->get() && !strstr($dest, '/magic')) { $magic_path = $basepath . '/magic' . '?owa=1&dest=' . $dest . '&' . $addr_request; // We have to check if the remote server does understand /magic without invoking something diff --git a/src/Module/Admin/Addons/Details.php b/src/Module/Admin/Addons/Details.php index afca0b150c..bc1925717e 100644 --- a/src/Module/Admin/Addons/Details.php +++ b/src/Module/Admin/Addons/Details.php @@ -101,7 +101,7 @@ class Details extends BaseAdminModule '$page' => L10n::t('Addons'), '$toggle' => L10n::t('Toggle'), '$settings' => L10n::t('Settings'), - '$baseurl' => $a->getBaseURL(true), + '$baseurl' => DI::baseUrl()->get(true), '$addon' => $addon, '$status' => $status, diff --git a/src/Module/Admin/Addons/Index.php b/src/Module/Admin/Addons/Index.php index bc28aaa8fe..511cb44755 100644 --- a/src/Module/Admin/Addons/Index.php +++ b/src/Module/Admin/Addons/Index.php @@ -14,8 +14,6 @@ class Index extends BaseAdminModule { parent::content($parameters); - $a = DI::app(); - // reload active themes if (!empty($_GET['action'])) { parent::checkFormSecurityTokenRedirectOnError('/admin/addons', 'admin_addons', 't'); @@ -52,7 +50,7 @@ class Index extends BaseAdminModule '$page' => L10n::t('Addons'), '$submit' => L10n::t('Save Settings'), '$reload' => L10n::t('Reload active addons'), - '$baseurl' => $a->getBaseURL(true), + '$baseurl' => DI::baseUrl()->get(true), '$function' => 'addons', '$addons' => $addons, '$pcount' => count($addons), diff --git a/src/Module/Admin/Blocklist/Contact.php b/src/Module/Admin/Blocklist/Contact.php index 71e96834b6..b2e9c50827 100644 --- a/src/Module/Admin/Blocklist/Contact.php +++ b/src/Module/Admin/Blocklist/Contact.php @@ -76,7 +76,7 @@ class Contact extends BaseAdminModule '$form_security_token' => parent::getFormSecurityToken('admin_contactblock'), // values // - '$baseurl' => $a->getBaseURL(true), + '$baseurl' => DI::baseUrl()->get(true), '$contacts' => $contacts, '$total_contacts' => L10n::tt('%s total blocked contact', '%s total blocked contacts', $total), diff --git a/src/Module/Admin/Blocklist/Server.php b/src/Module/Admin/Blocklist/Server.php index 87cb8709db..43c6543e46 100644 --- a/src/Module/Admin/Blocklist/Server.php +++ b/src/Module/Admin/Blocklist/Server.php @@ -55,8 +55,6 @@ class Server extends BaseAdminModule { parent::content($parameters); - $a = DI::app(); - $blocklist = Config::get('system', 'blocklist'); $blocklistform = []; if (is_array($blocklist)) { @@ -91,7 +89,7 @@ class Server extends BaseAdminModule '$threason' => L10n::t('Reason for the block'), '$delentry' => L10n::t('Delete entry from blocklist'), '$entries' => $blocklistform, - '$baseurl' => $a->getBaseURL(true), + '$baseurl' => DI::baseUrl()->get(true), '$confirm_delete' => L10n::t('Delete entry from blocklist?'), '$form_security_token' => parent::getFormSecurityToken("admin_blocklist") ]); diff --git a/src/Module/Admin/DBSync.php b/src/Module/Admin/DBSync.php index 6f6ebe3d00..a0e70737e5 100644 --- a/src/Module/Admin/DBSync.php +++ b/src/Module/Admin/DBSync.php @@ -88,13 +88,13 @@ class DBSync extends BaseAdminModule if (!count($failed)) { $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('admin/dbsync/structure_check.tpl'), [ - '$base' => $a->getBaseURL(true), + '$base' => DI::baseUrl()->get(true), '$banner' => L10n::t('No failed updates.'), '$check' => L10n::t('Check database structure'), ]); } else { $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('admin/dbsync/failed_updates.tpl'), [ - '$base' => $a->getBaseURL(true), + '$base' => DI::baseUrl()->get(true), '$banner' => L10n::t('Failed Updates'), '$desc' => L10n::t('This does not include updates prior to 1139, which did not return a status.'), '$mark' => L10n::t("Mark success \x28if update was manually applied\x29"), diff --git a/src/Module/Admin/Logs/Settings.php b/src/Module/Admin/Logs/Settings.php index ccddf69a1d..21380af4a5 100644 --- a/src/Module/Admin/Logs/Settings.php +++ b/src/Module/Admin/Logs/Settings.php @@ -42,8 +42,6 @@ class Settings extends BaseAdminModule { parent::content($parameters); - $a = DI::app(); - $log_choices = [ LogLevel::ERROR => 'Error', LogLevel::WARNING => 'Warning', @@ -65,7 +63,7 @@ class Settings extends BaseAdminModule '$page' => L10n::t('Logs'), '$submit' => L10n::t('Save Settings'), '$clear' => L10n::t('Clear'), - '$baseurl' => $a->getBaseURL(true), + '$baseurl' => DI::baseUrl()->get(true), '$logname' => Config::get('system', 'logfile'), // see /help/smarty3-templates#1_1 on any Friendica node '$debugging' => ['debugging', L10n::t("Enable Debugging"), Config::get('system', 'debugging'), ""], diff --git a/src/Module/Admin/Site.php b/src/Module/Admin/Site.php index 267680583d..ed16a65b77 100644 --- a/src/Module/Admin/Site.php +++ b/src/Module/Admin/Site.php @@ -56,7 +56,7 @@ class Site extends BaseAdminModule * send relocate for every local user * */ - $old_url = $a->getBaseURL(true); + $old_url = DI::baseUrl()->get(true); // Generate host names for relocation the addresses in the format user@address.tld $new_host = str_replace("http://", "@", Strings::normaliseLink($new_url)); @@ -417,8 +417,6 @@ class Site extends BaseAdminModule { parent::content($parameters); - $a = DI::app(); - /* Installed langs */ $lang_choices = L10n::getAvailableLanguages(); @@ -578,7 +576,7 @@ class Site extends BaseAdminModule '$relay_title' => L10n::t('Message Relay'), '$relocate' => L10n::t('Relocate Instance'), '$relocate_warning' => L10n::t('Warning! Advanced function. Could make this server unreachable.'), - '$baseurl' => $a->getBaseURL(true), + '$baseurl' => DI::baseUrl()->get(true), // name, label, value, help string, extra data... '$sitename' => ['sitename', L10n::t('Site name'), Config::get('config', 'sitename'), ''], @@ -661,14 +659,14 @@ class Site extends BaseAdminModule '$proxy_disabled' => ['proxy_disabled', L10n::t('Disable picture proxy'), Config::get('system', 'proxy_disabled'), L10n::t('The picture proxy increases performance and privacy. It shouldn\'t be used on systems with very low bandwidth.')], '$only_tag_search' => ['only_tag_search', L10n::t('Only search in tags'), Config::get('system', 'only_tag_search'), L10n::t('On large systems the text search can slow down the system extremely.')], - '$relocate_url' => ['relocate_url', L10n::t('New base url'), $a->getBaseURL(), L10n::t('Change base url for this server. Sends relocate message to all Friendica and Diaspora* contacts of all users.')], + '$relocate_url' => ['relocate_url', L10n::t('New base url'), DI::baseUrl()->get(), L10n::t('Change base url for this server. Sends relocate message to all Friendica and Diaspora* contacts of all users.')], '$rino' => ['rino', L10n::t('RINO Encryption'), intval(Config::get('system', 'rino_encrypt')), L10n::t('Encryption layer between nodes.'), [0 => L10n::t('Disabled'), 1 => L10n::t('Enabled')]], '$worker_queues' => ['worker_queues', L10n::t('Maximum number of parallel workers'), Config::get('system', 'worker_queues'), L10n::t('On shared hosters set this to %d. On larger systems, values of %d are great. Default value is %d.', 5, 20, 10)], '$worker_dont_fork' => ['worker_dont_fork', L10n::t('Don\'t use "proc_open" with the worker'), Config::get('system', 'worker_dont_fork'), L10n::t('Enable this if your system doesn\'t allow the use of "proc_open". This can happen on shared hosters. If this is enabled you should increase the frequency of worker calls in your crontab.')], '$worker_fastlane' => ['worker_fastlane', L10n::t('Enable fastlane'), Config::get('system', 'worker_fastlane'), L10n::t('When enabed, the fastlane mechanism starts an additional worker if processes with higher priority are blocked by processes of lower priority.')], - '$worker_frontend' => ['worker_frontend', L10n::t('Enable frontend worker'), Config::get('system', 'frontend_worker'), L10n::t('When enabled the Worker process is triggered when backend access is performed (e.g. messages being delivered). On smaller sites you might want to call %s/worker on a regular basis via an external cron job. You should only enable this option if you cannot utilize cron/scheduled jobs on your server.', $a->getBaseURL())], + '$worker_frontend' => ['worker_frontend', L10n::t('Enable frontend worker'), Config::get('system', 'frontend_worker'), L10n::t('When enabled the Worker process is triggered when backend access is performed (e.g. messages being delivered). On smaller sites you might want to call %s/worker on a regular basis via an external cron job. You should only enable this option if you cannot utilize cron/scheduled jobs on your server.', DI::baseUrl()->get())], '$relay_subscribe' => ['relay_subscribe', L10n::t('Subscribe to relay'), Config::get('system', 'relay_subscribe'), L10n::t('Enables the receiving of public posts from the relay. They will be included in the search, subscribed tags and on the global community page.')], '$relay_server' => ['relay_server', L10n::t('Relay server'), Config::get('system', 'relay_server', 'https://relay.diasp.org'), L10n::t('Address of the relay server where public posts should be send to. For example https://relay.diasp.org')], diff --git a/src/Module/Admin/Summary.php b/src/Module/Admin/Summary.php index 9853ce951b..6f304082af 100644 --- a/src/Module/Admin/Summary.php +++ b/src/Module/Admin/Summary.php @@ -63,18 +63,18 @@ class Summary extends BaseAdminModule // Legacy config file warning if (file_exists('.htconfig.php')) { - $warningtext[] = L10n::t('Friendica\'s configuration now is stored in config/local.config.php, please copy config/local-sample.config.php and move your config from .htconfig.php. See the Config help page for help with the transition.', $a->getBaseURL() . '/help/Config'); + $warningtext[] = L10n::t('Friendica\'s configuration now is stored in config/local.config.php, please copy config/local-sample.config.php and move your config from .htconfig.php. See the Config help page for help with the transition.', DI::baseUrl()->get() . '/help/Config'); } if (file_exists('config/local.ini.php')) { - $warningtext[] = L10n::t('Friendica\'s configuration now is stored in config/local.config.php, please copy config/local-sample.config.php and move your config from config/local.ini.php. See the Config help page for help with the transition.', $a->getBaseURL() . '/help/Config'); + $warningtext[] = L10n::t('Friendica\'s configuration now is stored in config/local.config.php, please copy config/local-sample.config.php and move your config from config/local.ini.php. See the Config help page for help with the transition.', DI::baseUrl()->get() . '/help/Config'); } // Check server vitality if (!self::checkSelfHostMeta()) { - $well_known = $a->getBaseURL() . '/.well-known/host-meta'; + $well_known = DI::baseUrl()->get() . '/.well-known/host-meta'; $warningtext[] = L10n::t('%s is not reachable on your system. This is a severe configuration issue that prevents server to server communication. See the installation page for help.', - $well_known, $well_known, $a->getBaseURL() . '/help/Install'); + $well_known, $well_known, DI::baseUrl()->get() . '/help/Install'); } // Check logfile permission @@ -208,7 +208,7 @@ class Summary extends BaseAdminModule private static function checkSelfHostMeta() { // Fetch the host-meta to check if this really is a vital server - return Network::curl(DI::app()->getBaseURL() . '/.well-known/host-meta')->isSuccess(); + return Network::curl(DI::baseUrl()->get() . '/.well-known/host-meta')->isSuccess(); } } diff --git a/src/Module/Admin/Themes/Details.php b/src/Module/Admin/Themes/Details.php index f6a3c61b73..2b573eec3b 100644 --- a/src/Module/Admin/Themes/Details.php +++ b/src/Module/Admin/Themes/Details.php @@ -106,7 +106,7 @@ class Details extends BaseAdminModule '$page' => L10n::t('Themes'), '$toggle' => L10n::t('Toggle'), '$settings' => L10n::t('Settings'), - '$baseurl' => $a->getBaseURL(true), + '$baseurl' => DI::baseUrl()->get(true), '$addon' => $theme, '$status' => $status, '$action' => $action, diff --git a/src/Module/Admin/Themes/Index.php b/src/Module/Admin/Themes/Index.php index 63b3d6f39e..dc848f93f8 100644 --- a/src/Module/Admin/Themes/Index.php +++ b/src/Module/Admin/Themes/Index.php @@ -16,13 +16,11 @@ class Index extends BaseAdminModule { parent::content($parameters); - $a = DI::app(); - $allowed_themes = Theme::getAllowedList(); // reload active themes if (!empty($_GET['action'])) { - parent::checkFormSecurityTokenRedirectOnError($a->getBaseURL() . '/admin/themes', 'admin_themes', 't'); + parent::checkFormSecurityTokenRedirectOnError(DI::baseUrl()->get() . '/admin/themes', 'admin_themes', 't'); switch ($_GET['action']) { case 'reload': @@ -97,7 +95,7 @@ class Index extends BaseAdminModule '$page' => L10n::t('Themes'), '$submit' => L10n::t('Save Settings'), '$reload' => L10n::t('Reload active themes'), - '$baseurl' => $a->getBaseURL(true), + '$baseurl' => DI::baseUrl()->get(true), '$function' => 'themes', '$addons' => $addons, '$pcount' => count($themes), diff --git a/src/Module/Admin/Users.php b/src/Module/Admin/Users.php index 7d8574e56b..286bc04452 100644 --- a/src/Module/Admin/Users.php +++ b/src/Module/Admin/Users.php @@ -20,8 +20,6 @@ class Users extends BaseAdminModule { parent::post($parameters); - $a = DI::app(); - $pending = $_POST['pending'] ?? []; $users = $_POST['user'] ?? []; $nu_name = $_POST['new_user_name'] ?? ''; @@ -78,7 +76,7 @@ class Users extends BaseAdminModule Thank you and welcome to %4$s.')); $preamble = sprintf($preamble, $user['username'], Config::get('config', 'sitename')); - $body = sprintf($body, $a->getBaseURL(), $user['nickname'], $result['password'], Config::get('config', 'sitename')); + $body = sprintf($body, DI::baseUrl()->get(), $user['nickname'], $result['password'], Config::get('config', 'sitename')); notification([ 'type' => SYSTEM_EMAIL, @@ -306,7 +304,7 @@ class Users extends BaseAdminModule '$form_security_token' => parent::getFormSecurityToken('admin_users'), // values // - '$baseurl' => $a->getBaseURL(true), + '$baseurl' => DI::baseUrl()->get(true), '$pending' => $pending, 'deleted' => $deleted, diff --git a/src/Module/AllFriends.php b/src/Module/AllFriends.php index 2699990736..14095f4507 100644 --- a/src/Module/AllFriends.php +++ b/src/Module/AllFriends.php @@ -70,7 +70,7 @@ class AllFriends extends BaseModule $friend['id'] = $friend['cid']; $photoMenu = Model\Contact::photoMenu($friend); } else { - $connlnk = $app->getBaseURL() . '/follow/?url=' . $friend['url']; + $connlnk = DI::baseUrl()->get() . '/follow/?url=' . $friend['url']; $photoMenu = [ 'profile' => [L10n::t('View Profile'), Model\Contact::magicLinkbyId($friend['id'], $friend['url'])], 'follow' => [L10n::t('Connect/Follow'), $connlnk] diff --git a/src/Module/BaseSearchModule.php b/src/Module/BaseSearchModule.php index efedca92af..cf0159cc27 100644 --- a/src/Module/BaseSearchModule.php +++ b/src/Module/BaseSearchModule.php @@ -97,8 +97,6 @@ class BaseSearchModule extends BaseModule return ''; } - $a = DI::app(); - $id = 0; $entries = []; foreach ($results->getResults() as $result) { @@ -131,7 +129,7 @@ class BaseSearchModule extends BaseModule $photo_menu = []; } } else { - $connLink = $a->getBaseURL() . '/follow/?url=' . $result->getUrl(); + $connLink = DI::baseUrl()->get() . '/follow/?url=' . $result->getUrl(); $connTxt = L10n::t('Connect'); $photo_menu['profile'] = [L10n::t("View Profile"), Model\Contact::magicLink($result->getUrl())]; diff --git a/src/Module/Bookmarklet.php b/src/Module/Bookmarklet.php index 93f790a37d..c7f4cdae4a 100644 --- a/src/Module/Bookmarklet.php +++ b/src/Module/Bookmarklet.php @@ -30,7 +30,7 @@ class Bookmarklet extends BaseModule } $referer = Strings::normaliseLink($_SERVER['HTTP_REFERER'] ?? ''); - $page = Strings::normaliseLink($app->getBaseURL() . "/bookmarklet"); + $page = Strings::normaliseLink(DI::baseUrl()->get() . "/bookmarklet"); if (!strstr($referer, $page)) { if (empty($_REQUEST["url"])) { diff --git a/src/Module/Contact.php b/src/Module/Contact.php index 45e4900ac2..f7c6680ed4 100644 --- a/src/Module/Contact.php +++ b/src/Module/Contact.php @@ -351,7 +351,7 @@ class Contact extends BaseModule $tpl = Renderer::getMarkupTemplate('contacts-head.tpl'); $a->page['htmlhead'] .= Renderer::replaceMacros($tpl, [ - '$baseurl' => $a->getBaseURL(true), + '$baseurl' => DI::baseUrl()->get(true), ]); $sort_type = 0; @@ -473,7 +473,7 @@ class Contact extends BaseModule $contact = $a->data['contact']; $a->page['htmlhead'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('contact_head.tpl'), [ - '$baseurl' => $a->getBaseURL(true), + '$baseurl' => DI::baseUrl()->get(true), ]); $contact['blocked'] = Model\Contact::isBlockedByUser($contact['id'], local_user()); diff --git a/src/Module/Debug/Localtime.php b/src/Module/Debug/Localtime.php index b762abdbc5..d9e2489790 100644 --- a/src/Module/Debug/Localtime.php +++ b/src/Module/Debug/Localtime.php @@ -40,7 +40,7 @@ class Localtime extends BaseModule $output .= '

' . L10n::t('Converted localtime: %s', $app->data['mod-localtime']) . '

'; } - $output .= '
'; + $output .= ''; $output .= '

' . L10n::t('Please select your timezone:') . '

'; $output .= Temporal::getTimezoneSelect(($_REQUEST['timezone'] ?? '') ?: Installer::DEFAULT_TZ); $output .= '
'; diff --git a/src/Module/Diaspora/Fetch.php b/src/Module/Diaspora/Fetch.php index 9ed8fb109e..c19857fde3 100644 --- a/src/Module/Diaspora/Fetch.php +++ b/src/Module/Diaspora/Fetch.php @@ -47,7 +47,7 @@ class Fetch extends BaseModule } $host = $parts["scheme"] . "://" . $parts["host"]; - if (Strings::normaliseLink($host) != Strings::normaliseLink($app->getBaseURL())) { + if (Strings::normaliseLink($host) != Strings::normaliseLink(DI::baseUrl()->get())) { $location = $host . "/fetch/" . $app->argv[1] . "/" . urlencode($guid); System::externalRedirect($location, 301); } diff --git a/src/Module/Friendica.php b/src/Module/Friendica.php index 4f33fea43a..11773a06d2 100644 --- a/src/Module/Friendica.php +++ b/src/Module/Friendica.php @@ -18,7 +18,6 @@ class Friendica extends BaseModule { public static function content(array $parameters = []) { - $app = DI::app(); $config = DI::config(); $visibleAddonList = Addon::getVisibleList(); @@ -48,7 +47,7 @@ class Friendica extends BaseModule } $tos = ($config->get('system', 'tosdisplay')) ? - L10n::t('Read about the Terms of Service of this node.', $app->getBaseURL()) : + L10n::t('Read about the Terms of Service of this node.', DI::baseUrl()->get()) : ''; $blockList = $config->get('system', 'blocklist'); @@ -75,7 +74,7 @@ class Friendica extends BaseModule return Renderer::replaceMacros($tpl, [ 'about' => L10n::t('This is Friendica, version %s that is running at the web location %s. The database version is %s, the post update version is %s.', '' . FRIENDICA_VERSION . '', - $app->getBaseURL(), + DI::baseUrl()->get(), '' . DB_UPDATE_VERSION . '', '' . $config->get('system', 'post_update_version') . ''), 'friendica' => L10n::t('Please visit Friendi.ca to learn more about the Friendica project.'), @@ -125,7 +124,7 @@ class Friendica extends BaseModule if (!empty($administrator)) { $admin = [ 'name' => $administrator['username'], - 'profile' => $app->getBaseURL() . '/profile/' . $administrator['nickname'], + 'profile' => DI::baseUrl()->get() . '/profile/' . $administrator['nickname'], ]; } } @@ -147,7 +146,7 @@ class Friendica extends BaseModule $data = [ 'version' => FRIENDICA_VERSION, - 'url' => $app->getBaseURL(), + 'url' => DI::baseUrl()->get(), 'addons' => $visible_addons, 'locked_features' => $locked_features, 'explicit_content' => intval($config->get('system', 'explicit_content', 0)), @@ -157,7 +156,7 @@ class Friendica extends BaseModule 'site_name' => $config->get('config', 'sitename'), 'platform' => FRIENDICA_PLATFORM, 'info' => $config->get('config', 'info'), - 'no_scrape_url' => $app->getBaseURL() . '/noscrape', + 'no_scrape_url' => DI::baseUrl()->get() . '/noscrape', ]; header('Content-type: application/json; charset=utf-8'); diff --git a/src/Module/Help.php b/src/Module/Help.php index 70c99a0a6f..d9362712fd 100644 --- a/src/Module/Help.php +++ b/src/Module/Help.php @@ -87,7 +87,7 @@ class Help extends BaseModule $idNum[$level] ++; - $href = $a->getBaseURL() . "/help/{$filename}#{$anchor}"; + $href = DI::baseUrl()->get() . "/help/{$filename}#{$anchor}"; $toc .= "
  • " . strip_tags($line) . "
  • "; $id = implode("_", array_slice($idNum, 1, $level)); $line = "" . $line; diff --git a/src/Module/Home.php b/src/Module/Home.php index fc8817b31b..fbdc252a66 100644 --- a/src/Module/Home.php +++ b/src/Module/Home.php @@ -42,7 +42,7 @@ class Home extends BaseModule $customHome = $homeFilePath; if (file_exists($cssFilePath)) { - $app->page['htmlhead'] .= ''; + $app->page['htmlhead'] .= ''; } } diff --git a/src/Module/Install.php b/src/Module/Install.php index 10a6176e40..537338da15 100644 --- a/src/Module/Install.php +++ b/src/Module/Install.php @@ -71,7 +71,7 @@ class Install extends BaseModule // We overwrite current theme css, because during install we may not have a working mod_rewrite // so we may not have a css at all. Here we set a static css file for the install procedure pages - Renderer::$theme['stylesheet'] = $a->getBaseURL() . '/view/install/style.css'; + Renderer::$theme['stylesheet'] = DI::baseUrl()->get() . '/view/install/style.css'; self::$currentWizardStep = ($_POST['pass'] ?? '') ?: self::SYSTEM_CHECK; } @@ -162,7 +162,7 @@ class Install extends BaseModule case self::SYSTEM_CHECK: $php_path = $configCache->get('config', 'php_path'); - $status = self::$installer->checkEnvironment($a->getBaseURL(), $php_path); + $status = self::$installer->checkEnvironment(DI::baseUrl()->get(), $php_path); $tpl = Renderer::getMarkupTemplate('install_checks.tpl'); $output .= Renderer::replaceMacros($tpl, [ @@ -303,7 +303,7 @@ class Install extends BaseModule '$title' => $install_title, '$checks' => self::$installer->getChecks(), '$pass' => L10n::t('Installation finished'), - '$text' => $db_return_text . self::whatNext($a), + '$text' => $db_return_text . self::whatNext(), ]); break; @@ -315,14 +315,12 @@ class Install extends BaseModule /** * Creates the text for the next steps * - * @param App $a The global App - * * @return string The text for the next steps * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - private static function whatNext($a) + private static function whatNext() { - $baseurl = $a->getBaseUrl(); + $baseurl = DI::baseUrl()->get(); return L10n::t('

    What next

    ') . "

    " . L10n::t('IMPORTANT: You will need to [manually] setup a scheduled task for the worker.') diff --git a/src/Module/Invite.php b/src/Module/Invite.php index 52d9bbcea3..67d26f6fa7 100644 --- a/src/Module/Invite.php +++ b/src/Module/Invite.php @@ -129,14 +129,14 @@ class Invite extends BaseModule if ($config->get('config', 'register_policy') === Register::CLOSED) { $linkTxt = L10n::t('Visit %s for a list of public sites that you can join. Friendica members on other sites can all connect with each other, as well as with members of many other social networks.', $dirLocation . '/servers'); } else { - $linkTxt = L10n::t('To accept this invitation, please visit and register at %s or any other public Friendica website.', $app->getBaseURL()) + $linkTxt = L10n::t('To accept this invitation, please visit and register at %s or any other public Friendica website.', DI::baseUrl()->get()) . "\r\n" . "\r\n" . L10n::t('Friendica sites all inter-connect to create a huge privacy-enhanced social web that is owned and controlled by its members. They can also connect with many traditional social networks. See %s for a list of alternate Friendica sites you can join.', $dirLocation . '/servers'); } } else { // there is no global directory URL defined if ($config->get('config', 'register_policy') === Register::CLOSED) { return L10n::t('Our apologies. This system is not currently configured to connect with other public sites or invite members.'); } else { - $linkTxt = L10n::t('To accept this invitation, please visit and register at %s.', $app->getBaseURL() + $linkTxt = L10n::t('To accept this invitation, please visit and register at %s.', DI::baseUrl()->get() . "\r\n" . "\r\n" . L10n::t('Friendica sites all inter-connect to create a huge privacy-enhanced social web that is owned and controlled by its members. They can also connect with many traditional social networks.')); } } @@ -152,7 +152,7 @@ class Invite extends BaseModule L10n::t('You are cordially invited to join me and other close friends on Friendica - and help us to create a better social web.') . "\r\n" . "\r\n" . $linkTxt . "\r\n" . "\r\n" . (($inviteOnly) ? L10n::t('You will need to supply this invitation code: $invite_code') . "\r\n" . "\r\n" : '') . L10n::t('Once you have registered, please connect with me via my profile page at:') - . "\r\n" . "\r\n" . $app->getBaseURL() . '/profile/' . $app->user['nickname'] + . "\r\n" . "\r\n" . DI::baseUrl()->get() . '/profile/' . $app->user['nickname'] . "\r\n" . "\r\n" . L10n::t('For more information about the Friendica project and why we feel it is important, please visit http://friendi.ca') . "\r\n" . "\r\n", ], '$submit' => L10n::t('Submit') diff --git a/src/Module/Magic.php b/src/Module/Magic.php index b878b0e701..0ac05ccdf8 100644 --- a/src/Module/Magic.php +++ b/src/Module/Magic.php @@ -49,7 +49,7 @@ class Magic extends BaseModule $contact = DBA::selectFirst('contact', ['id', 'nurl', 'url'], ['id' => $cid]); // Redirect if the contact is already authenticated on this site. - if (!empty($a->contact) && array_key_exists('id', $a->contact) && strpos($contact['nurl'], Strings::normaliseLink(DI::app()->getBaseURL())) !== false) { + if (!empty($a->contact) && array_key_exists('id', $a->contact) && strpos($contact['nurl'], Strings::normaliseLink(DI::baseUrl()->get())) !== false) { if ($test) { $ret['success'] = true; $ret['message'] .= 'Local site - you are already authenticated.' . EOL; diff --git a/src/Module/OpenSearch.php b/src/Module/OpenSearch.php index dbf04040b8..e1da674184 100644 --- a/src/Module/OpenSearch.php +++ b/src/Module/OpenSearch.php @@ -22,7 +22,7 @@ class OpenSearch extends BaseModule header('Content-type: application/opensearchdescription+xml'); $hostname = DI::baseUrl()->getHostname()(); - $baseUrl = DI::app()->getBaseURL(); + $baseUrl = DI::baseUrl()->get(); /** @var DOMDocument $xml */ $xml = null; diff --git a/src/Module/ReallySimpleDiscovery.php b/src/Module/ReallySimpleDiscovery.php index 43fdcf102c..382fe12d4f 100644 --- a/src/Module/ReallySimpleDiscovery.php +++ b/src/Module/ReallySimpleDiscovery.php @@ -16,7 +16,6 @@ class ReallySimpleDiscovery extends BaseModule { header('Content-Type: text/xml'); - $app = DI::app(); $xml = null; echo XML::fromArray([ 'rsd' => [ @@ -32,7 +31,7 @@ class ReallySimpleDiscovery extends BaseModule '@attributes' => [ 'name' => 'Twitter', 'preferred' => 'true', - 'apiLink' => $app->getBaseURL(), + 'apiLink' => DI::baseUrl()->get(), 'blogID' => '', ], 'settings' => [ diff --git a/src/Module/Security/Login.php b/src/Module/Security/Login.php index c525778985..cddd014d00 100644 --- a/src/Module/Security/Login.php +++ b/src/Module/Security/Login.php @@ -104,7 +104,7 @@ class Login extends BaseModule $a->page['htmlhead'] .= Renderer::replaceMacros( Renderer::getMarkupTemplate('login_head.tpl'), [ - '$baseurl' => $a->getBaseURL(true) + '$baseurl' => DI::baseUrl()->get(true) ] ); @@ -127,7 +127,7 @@ class Login extends BaseModule $o .= Renderer::replaceMacros( $tpl, [ - '$dest_url' => DI::app()->getBaseURL(true) . '/login', + '$dest_url' => DI::baseUrl()->get(true) . '/login', '$logout' => L10n::t('Logout'), '$login' => L10n::t('Login'), diff --git a/src/Module/WellKnown/HostMeta.php b/src/Module/WellKnown/HostMeta.php index 2e63f300de..2bae006a70 100644 --- a/src/Module/WellKnown/HostMeta.php +++ b/src/Module/WellKnown/HostMeta.php @@ -16,7 +16,6 @@ class HostMeta extends BaseModule { public static function rawContent(array $parameters = []) { - $app = DI::app(); $config = DI::config(); header('Content-type: text/xml'); @@ -31,8 +30,8 @@ class HostMeta extends BaseModule $tpl = Renderer::getMarkupTemplate('xrd_host.tpl'); echo Renderer::replaceMacros($tpl, [ '$zhost' => DI::baseUrl()->getHostname()(), - '$zroot' => $app->getBaseURL(), - '$domain' => $app->getBaseURL(), + '$zroot' => DI::baseUrl()->get(), + '$domain' => DI::baseUrl()->get(), '$bigkey' => Salmon::salmonKey($config->get('system', 'site_pubkey')) ]); diff --git a/src/Module/WellKnown/NodeInfo.php b/src/Module/WellKnown/NodeInfo.php index 4f44e81d9c..d0d2ea7a02 100644 --- a/src/Module/WellKnown/NodeInfo.php +++ b/src/Module/WellKnown/NodeInfo.php @@ -2,7 +2,6 @@ namespace Friendica\Module\WellKnown; -use Friendica\App; use Friendica\BaseModule; use Friendica\DI; @@ -14,26 +13,22 @@ class NodeInfo extends BaseModule { public static function rawContent(array $parameters = []) { - $app = DI::app(); - - self::printWellKnown($app); + self::printWellKnown(); } /** * Prints the well-known nodeinfo redirect * - * @param App $app - * * @throws \Friendica\Network\HTTPException\NotFoundException */ - private static function printWellKnown(App $app) + private static function printWellKnown() { $nodeinfo = [ 'links' => [ ['rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.0', - 'href' => $app->getBaseURL() . '/nodeinfo/1.0'], + 'href' => DI::baseUrl()->get() . '/nodeinfo/1.0'], ['rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.0', - 'href' => $app->getBaseURL() . '/nodeinfo/2.0'], + 'href' => DI::baseUrl()->get() . '/nodeinfo/2.0'], ] ]; diff --git a/src/Module/WellKnown/XSocialRelay.php b/src/Module/WellKnown/XSocialRelay.php index 38a9e12435..f9a806f03c 100644 --- a/src/Module/WellKnown/XSocialRelay.php +++ b/src/Module/WellKnown/XSocialRelay.php @@ -14,7 +14,6 @@ class XSocialRelay extends BaseModule { public static function rawContent(array $parameters = []) { - $app = DI::app(); $config = DI::config(); $subscribe = $config->get('system', 'relay_subscribe', false); @@ -50,10 +49,10 @@ class XSocialRelay extends BaseModule 'tags' => $tagList, 'protocols' => [ 'diaspora' => [ - 'receive' => $app->getBaseURL() . '/receive/public' + 'receive' => DI::baseUrl()->get() . '/receive/public' ], 'dfrn' => [ - 'receive' => $app->getBaseURL() . '/dfrn_notify' + 'receive' => DI::baseUrl()->get() . '/dfrn_notify' ] ] ]; diff --git a/src/Module/Xrd.php b/src/Module/Xrd.php index 63b293daf4..0048350be8 100644 --- a/src/Module/Xrd.php +++ b/src/Module/Xrd.php @@ -75,9 +75,9 @@ class Xrd extends BaseModule } if ($mode == 'xml') { - self::printXML($alias, $app->getBaseURL(), $user, $owner, $avatar); + self::printXML($alias, DI::baseUrl()->get(), $user, $owner, $avatar); } else { - self::printJSON($alias, $app->getBaseURL(), $owner, $avatar); + self::printJSON($alias, DI::baseUrl()->get(), $owner, $avatar); } } diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 398ee3ae8f..d345340f85 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -204,7 +204,7 @@ class Transmitter { return ['type' => 'Service', 'name' => FRIENDICA_PLATFORM . " '" . FRIENDICA_CODENAME . "' " . FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION, - 'url' => DI::app()->getBaseURL()]; + 'url' => DI::baseUrl()->get()]; } /** diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index c20f069567..e058854c94 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -2372,7 +2372,7 @@ class DFRN /// @todo Do we really need this check for HTML elements? (It was copied from the old function) if ((strpos($item['body'], '<') !== false) && (strpos($item['body'], '>') !== false)) { - $base_url = \get_app()->getBaseURL(); + $base_url = DI::baseUrl()->get(); $item['body'] = HTML::relToAbs($item['body'], $base_url); $item['body'] = HTML::toBBCodeVideo($item['body']); From 302cbaa33c8151bffc37891614f2cdcb1e19e955 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Mon, 16 Dec 2019 01:05:34 +0100 Subject: [PATCH 18/34] Remove deprecated App::getScheme() --- src/App.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/App.php b/src/App.php index 35ef04df6e..a8650de389 100644 --- a/src/App.php +++ b/src/App.php @@ -259,18 +259,6 @@ class App } } - /** - * Returns the scheme of the current call - * - * @return string - * - * @deprecated 2019.06 - use BaseURL->getScheme() instead - */ - public function getScheme() - { - return $this->baseURL->getScheme(); - } - /** * Returns the current UserAgent as a String * From c7230932d688def50f752ffcf5f82994b59c8013 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Mon, 16 Dec 2019 01:08:47 +0100 Subject: [PATCH 19/34] Remove deprecated App::registerStylesheet()/FooterScript() - replace with DI::page()->registerStylesheet()/FooterScript() --- doc/Addons.md | 4 ++-- src/App.php | 18 ------------------ 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/doc/Addons.md b/doc/Addons.md index 06b05bdff5..6e97565003 100644 --- a/doc/Addons.md +++ b/doc/Addons.md @@ -104,7 +104,7 @@ function _install() function _head(App $a) { - $a->registerStylesheet(__DIR__ . '/relative/path/to/addon/stylesheet.css'); + \Friendica\DI::page()->registerStylesheet(__DIR__ . '/relative/path/to/addon/stylesheet.css'); } ``` @@ -126,7 +126,7 @@ function _install() function _footer(App $a) { - $a->registerFooterScript(__DIR__ . '/relative/path/to/addon/script.js'); + \Friendica\DI::page()->registerFooterScript(__DIR__ . '/relative/path/to/addon/script.js'); } ``` diff --git a/src/App.php b/src/App.php index a8650de389..5c2118f73d 100644 --- a/src/App.php +++ b/src/App.php @@ -153,24 +153,6 @@ class App return $this->config->getCache()->get('system', 'basepath'); } - /** - * @deprecated 2019.09 - use Page->registerStylesheet instead - * @see Page::registerStylesheet() - */ - public function registerStylesheet($path) - { - $this->page->registerStylesheet($path); - } - - /** - * @deprecated 2019.09 - use Page->registerFooterScript instead - * @see Page::registerFooterScript() - */ - public function registerFooterScript($path) - { - $this->page->registerFooterScript($path); - } - /** * @param Database $database The Friendica Database * @param Configuration $config The Configuration From 26af2feee28b0f4a74115a61c433020fcbce0e55 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Mon, 16 Dec 2019 01:12:07 +0100 Subject: [PATCH 20/34] Remove deprecated App::is_mobile/is_tablet - replace with DI::mode()->isMobile()/isTablet() --- mod/community.php | 3 ++- mod/network.php | 2 +- src/App.php | 7 ------- src/Model/Profile.php | 4 ++-- src/Module/Profile.php | 2 +- view/theme/frio/php/default.php | 2 +- view/theme/frio/theme.php | 2 +- view/theme/vier/theme.php | 4 ++-- 8 files changed, 10 insertions(+), 16 deletions(-) diff --git a/mod/community.php b/mod/community.php index 9bea93f12a..f8336a6230 100644 --- a/mod/community.php +++ b/mod/community.php @@ -15,6 +15,7 @@ use Friendica\Core\PConfig; use Friendica\Core\Renderer; use Friendica\Core\Session; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Item; use Friendica\Model\User; @@ -136,7 +137,7 @@ function community_content(App $a, $update = 0) } // check if we serve a mobile device and get the user settings accordingly - if ($a->is_mobile) { + if (DI::mode()->isMobile()) { $itemspage_network = PConfig::get(local_user(), 'system', 'itemspage_mobile_network', 20); } else { $itemspage_network = PConfig::get(local_user(), 'system', 'itemspage_network', 40); diff --git a/mod/network.php b/mod/network.php index 14f70c9d65..aa4d1a40e0 100644 --- a/mod/network.php +++ b/mod/network.php @@ -228,7 +228,7 @@ function networkPager(App $a, Pager $pager, $update) // check if we serve a mobile device and get the user settings // accordingly - if ($a->is_mobile) { + if (DI::mode()->isMobile()) { $itemspage_network = PConfig::get(local_user(), 'system', 'itemspage_mobile_network'); $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 20); } else { diff --git a/src/App.php b/src/App.php index 5c2118f73d..74638a862d 100644 --- a/src/App.php +++ b/src/App.php @@ -66,10 +66,6 @@ class App public $timezone; public $interactive = true; public $identities; - /** @deprecated 2019.09 - Use App\Mode->isMobile() instead */ - public $is_mobile; - /** @deprecated 2019.09 - Use App\Mode->isTable() instead */ - public $is_tablet; public $theme_info = []; public $category; // Allow themes to control internal parameters @@ -183,9 +179,6 @@ class App $this->module = $module->getName(); $this->page = $page; - $this->is_mobile = $mode->isMobile(); - $this->is_tablet = $mode->isTablet(); - $this->load(); } diff --git a/src/Model/Profile.php b/src/Model/Profile.php index 0ebb400f6e..c050e07f08 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -571,7 +571,7 @@ class Profile $a = \get_app(); $o = ''; - if (!local_user() || $a->is_mobile || $a->is_tablet) { + if (!local_user() || DI::mode()->isMobile() || DI::mode()->isMobile()) { return $o; } @@ -668,7 +668,7 @@ class Profile $a = \get_app(); $o = ''; - if (!local_user() || $a->is_mobile || $a->is_tablet) { + if (!local_user() || DI::mode()->isMobile() || DI::mode()->isMobile()) { return $o; } diff --git a/src/Module/Profile.php b/src/Module/Profile.php index 04364ba0cc..991aa9126b 100644 --- a/src/Module/Profile.php +++ b/src/Module/Profile.php @@ -290,7 +290,7 @@ class Profile extends BaseModule // check if we serve a mobile device and get the user settings // accordingly - if ($a->is_mobile) { + if (DI::mode()->isMobile()) { $itemspage_network = PConfig::get(local_user(), 'system', 'itemspage_mobile_network', 10); } else { $itemspage_network = PConfig::get(local_user(), 'system', 'itemspage_network', 20); diff --git a/view/theme/frio/php/default.php b/view/theme/frio/php/default.php index 73ceea5845..cdb0f16673 100644 --- a/view/theme/frio/php/default.php +++ b/view/theme/frio/php/default.php @@ -22,7 +22,7 @@ if (!isset($minimal)) { $basepath = DI::baseUrl()->getUrlPath() ? "/" . DI::baseUrl()->getUrlPath() . "/" : "/"; $frio = "view/theme/frio"; -$view_mode_class = ($a->is_mobile || $a->is_tablet) ? 'mobile-view' : 'desktop-view'; +$view_mode_class = (DI::mode()->isMobile() || DI::mode()->isMobile()) ? 'mobile-view' : 'desktop-view'; $is_singleuser = Config::get('system', 'singleuser'); $is_singleuser_class = $is_singleuser ? "is-singleuser" : "is-not-singleuser"; ?> diff --git a/view/theme/frio/theme.php b/view/theme/frio/theme.php index 1e255e38b0..5fe0152748 100644 --- a/view/theme/frio/theme.php +++ b/view/theme/frio/theme.php @@ -35,7 +35,7 @@ function frio_init(App $a) // if the device is a mobile device set js is_mobile // variable so the js scripts can use this information - if ($a->is_mobile || $a->is_tablet) { + if (DI::mode()->isMobile() || DI::mode()->isMobile()) { $a->page['htmlhead'] .= <<< EOT EOT; - if ($a->is_mobile || $a->is_tablet) { + if (DI::mode()->isMobile() || DI::mode()->isMobile()) { $a->page['htmlhead'] .= <<< EOT "; } - $o .= conversation($a, [$item], new Pager($a->query_string), 'display', $update_uid, false, 'commented', $item_uid); + $o .= conversation($a, [$item], new Pager(DI::args()->getQueryString()), 'display', $update_uid, false, 'commented', $item_uid); // Preparing the meta header $description = trim(HTML::toPlaintext(BBCode::convert($item["body"], false), 0, true)); diff --git a/mod/item.php b/mod/item.php index 55e4896e75..d6f34e58a8 100644 --- a/mod/item.php +++ b/mod/item.php @@ -667,7 +667,7 @@ function item_post(App $a) { $datarray["item_id"] = -1; $datarray["author-network"] = Protocol::DFRN; - $o = conversation($a, [array_merge($contact_record, $datarray)], new Pager($a->query_string), 'search', false, true); + $o = conversation($a, [array_merge($contact_record, $datarray)], new Pager(DI::args()->getQueryString()), 'search', false, true); Logger::log('preview: ' . $o); echo json_encode(['preview' => $o]); exit(); diff --git a/mod/message.php b/mod/message.php index 6944dfa679..46ed9b0c12 100644 --- a/mod/message.php +++ b/mod/message.php @@ -134,7 +134,7 @@ function message_content(App $a) if (!empty($_REQUEST['confirm'])) { //

    can't take arguments in its "action" parameter // so add any arguments as hidden inputs - $query = explode_querystring($a->query_string); + $query = explode_querystring(DI::args()->getQueryString()); $inputs = []; foreach ($query['args'] as $arg) { if (strpos($arg, 'confirm=') === false) { @@ -265,7 +265,7 @@ function message_content(App $a) } - $_SESSION['return_path'] = $a->query_string; + $_SESSION['return_path'] = DI::args()->getQueryString(); if ($a->argc == 1) { @@ -282,7 +282,7 @@ function message_content(App $a) $total = $r[0]['total']; } - $pager = new Pager($a->query_string); + $pager = new Pager(DI::args()->getQueryString()); $r = get_messages(local_user(), $pager->getStart(), $pager->getItemsPerPage()); diff --git a/mod/network.php b/mod/network.php index aa4d1a40e0..adc315a548 100644 --- a/mod/network.php +++ b/mod/network.php @@ -63,7 +63,7 @@ function network_init(App $a) // convert query string to array. remove friendica args $query_array = []; - parse_str(parse_url($a->query_string, PHP_URL_QUERY), $query_array); + parse_str(parse_url(DI::args()->getQueryString(), PHP_URL_QUERY), $query_array); // fetch last used network view and redirect if needed if (!$is_a_date_query) { @@ -140,7 +140,7 @@ function network_init(App $a) $a->page['aside'] .= ForumManager::widget(local_user(), $cid); $a->page['aside'] .= Widget::postedByYear('network', local_user(), false); $a->page['aside'] .= Widget::networks('network', $_GET['nets'] ?? ''); - $a->page['aside'] .= Widget\SavedSearches::getHTML($a->query_string); + $a->page['aside'] .= Widget\SavedSearches::getHTML(DI::args()->getQueryString()); $a->page['aside'] .= Widget::fileAs('network', $_GET['file'] ?? ''); } @@ -309,7 +309,7 @@ function network_content(App $a, $update = 0, $parent = 0) } /// @TODO Is this really necessary? $a is already available to hooks - $arr = ['query' => $a->query_string]; + $arr = ['query' => DI::args()->getQueryString()]; Hook::callAll('network_content_init', $arr); $flat_mode = false; @@ -389,7 +389,7 @@ function networkFlatView(App $a, $update = 0) } } - $pager = new Pager($a->query_string); + $pager = new Pager(DI::args()->getQueryString()); networkPager($a, $pager, $update); @@ -681,7 +681,7 @@ function networkThreadedView(App $a, $update, $parent) $sql_range = ''; } - $pager = new Pager($a->query_string); + $pager = new Pager(DI::args()->getQueryString()); $pager_sql = networkPager($a, $pager, $update); @@ -869,7 +869,7 @@ function networkThreadedView(App $a, $update, $parent) $date_offset = $_GET['offset']; } - $query_string = $a->query_string; + $query_string = DI::args()->getQueryString(); if ($date_offset && !preg_match('/[?&].offset=/', $query_string)) { $query_string .= '&offset=' . urlencode($date_offset); } diff --git a/mod/notes.php b/mod/notes.php index 1f67e486d6..4a19ab5ca8 100644 --- a/mod/notes.php +++ b/mod/notes.php @@ -8,6 +8,7 @@ use Friendica\Content\Nav; use Friendica\Content\Pager; use Friendica\Core\L10n; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Item; use Friendica\Model\Profile; @@ -53,7 +54,7 @@ function notes_content(App $a, $update = false) $condition = ['uid' => local_user(), 'post-type' => Item::PT_PERSONAL_NOTE, 'gravity' => GRAVITY_PARENT, 'contact-id'=> $a->contact['id']]; - $pager = new Pager($a->query_string, 40); + $pager = new Pager(DI::args()->getQueryString(), 40); $params = ['order' => ['created' => true], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]]; diff --git a/mod/notifications.php b/mod/notifications.php index 7e1d2cff9e..4db4a8a83e 100644 --- a/mod/notifications.php +++ b/mod/notifications.php @@ -116,7 +116,7 @@ function notifications_content(App $a) } // Set the pager - $pager = new Pager($a->query_string, $perpage); + $pager = new Pager(DI::args()->getQueryString(), $perpage); // Add additional informations (needed for json output) $notifs['items_page'] = $pager->getItemsPerPage(); diff --git a/mod/photos.php b/mod/photos.php index fd1d6200f3..6398211c9b 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -984,7 +984,7 @@ function photos_content(App $a) // ACL permissions box '$group_perms' => L10n::t('Show to Groups'), '$contact_perms' => L10n::t('Show to Contacts'), - '$return_path' => $a->query_string, + '$return_path' => DI::args()->getQueryString(), ]); return $o; @@ -1008,7 +1008,7 @@ function photos_content(App $a) $total = count($r); } - $pager = new Pager($a->query_string, 20); + $pager = new Pager(DI::args()->getQueryString(), 20); /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it? $order_field = $_GET['order'] ?? ''; @@ -1030,7 +1030,7 @@ function photos_content(App $a) ); if ($cmd === 'drop') { - $drop_url = $a->query_string; + $drop_url = DI::args()->getQueryString(); return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [ '$method' => 'post', @@ -1137,7 +1137,7 @@ function photos_content(App $a) } if ($cmd === 'drop') { - $drop_url = $a->query_string; + $drop_url = DI::args()->getQueryString(); return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [ '$method' => 'post', @@ -1284,7 +1284,7 @@ function photos_content(App $a) $condition = ["`parent` = ? AND `parent` != `id`", $link_item['parent']]; $total = DBA::count('item', $condition); - $pager = new Pager($a->query_string); + $pager = new Pager(DI::args()->getQueryString()); $params = ['order' => ['id'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]]; $result = Item::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params); @@ -1348,7 +1348,7 @@ function photos_content(App $a) // ACL permissions box '$group_perms' => L10n::t('Show to Groups'), '$contact_perms' => L10n::t('Show to Contacts'), - '$return_path' => $a->query_string, + '$return_path' => DI::args()->getQueryString(), ]); } @@ -1371,7 +1371,7 @@ function photos_content(App $a) '$likethis' => L10n::t("I like this \x28toggle\x29"), '$nolike' => L10n::t("I don't like this \x28toggle\x29"), '$wait' => L10n::t('Please wait'), - '$return_path' => $a->query_string, + '$return_path' => DI::args()->getQueryString(), ]); } @@ -1549,7 +1549,7 @@ function photos_content(App $a) $total = count($r); } - $pager = new Pager($a->query_string, 20); + $pager = new Pager(DI::args()->getQueryString(), 20); $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`, diff --git a/mod/regmod.php b/mod/regmod.php index e08edfbcc9..7aecbc3bdb 100644 --- a/mod/regmod.php +++ b/mod/regmod.php @@ -80,7 +80,7 @@ function regmod_content(App $a) { if (!local_user()) { info(L10n::t('Please login.') . EOL); - return Login::form($a->query_string, intval(Config::get('config', 'register_policy')) === \Friendica\Module\Register::CLOSED ? 0 : 1); + return Login::form(DI::args()->getQueryString(), intval(Config::get('config', 'register_policy')) === \Friendica\Module\Register::CLOSED ? 0 : 1); } if (!is_site_admin() || !empty($_SESSION['submanage'])) { diff --git a/mod/settings.php b/mod/settings.php index 7dad1f04c1..5f28ca6d29 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -1152,7 +1152,7 @@ function settings_content(App $a) $private_post = 0; } - $query_str = $a->query_string; + $query_str = DI::args()->getQueryString(); if (strpos($query_str, 'public=1') !== false) { $query_str = str_replace(['?public=1', '&public=1'], ['', ''], $query_str); } diff --git a/mod/suggest.php b/mod/suggest.php index 86c7f7afdf..daf5de00fc 100644 --- a/mod/suggest.php +++ b/mod/suggest.php @@ -58,7 +58,7 @@ function suggest_content(App $a) if (!empty($_GET['ignore'])) { // can't take arguments in its "action" parameter // so add any arguments as hidden inputs - $query = explode_querystring($a->query_string); + $query = explode_querystring(DI::args()->getQueryString()); $inputs = []; foreach ($query['args'] as $arg) { if (strpos($arg, 'confirm=') === false) { diff --git a/mod/videos.php b/mod/videos.php index c6f342aa70..6d136d7de5 100644 --- a/mod/videos.php +++ b/mod/videos.php @@ -212,7 +212,7 @@ function videos_content(App $a) $total = count($r); } - $pager = new Pager($a->query_string, 20); + $pager = new Pager(DI::args()->getQueryString(), 20); $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`, ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype` diff --git a/src/App.php b/src/App.php index 74638a862d..c028f9d9d8 100644 --- a/src/App.php +++ b/src/App.php @@ -40,8 +40,6 @@ use Psr\Log\LoggerInterface; */ class App { - /** @deprecated 2019.09 - use App\Arguments->getQueryString() */ - public $query_string; /** * @var Page The current page environment */ @@ -175,7 +173,6 @@ class App $this->cmd = $args->getCommand(); $this->argv = $args->getArgv(); $this->argc = $args->getArgc(); - $this->query_string = $args->getQueryString(); $this->module = $module->getName(); $this->page = $page; diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 84481b9fa5..c84f979a98 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -1757,7 +1757,7 @@ class Contact $cid, GRAVITY_PARENT, GRAVITY_COMMENT, local_user()]; } - $pager = new Pager($a->query_string); + $pager = new Pager(DI::args()->getQueryString()); $params = ['order' => ['received' => true], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]]; diff --git a/src/Model/Profile.php b/src/Model/Profile.php index c050e07f08..69ec447951 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -144,7 +144,7 @@ class Profile $user = DBA::selectFirst('user', ['uid'], ['nickname' => $nickname, 'account_removed' => false]); if (!DBA::isResult($user) && empty($profiledata)) { - Logger::log('profile error: ' . $a->query_string, Logger::DEBUG); + Logger::log('profile error: ' . DI::args()->getQueryString(), Logger::DEBUG); return; } @@ -165,7 +165,7 @@ class Profile $pdata = self::getByNickname($nickname, $user['uid'], $profile); if (empty($pdata) && empty($profiledata)) { - Logger::log('profile error: ' . $a->query_string, Logger::DEBUG); + Logger::log('profile error: ' . DI::args()->getQueryString(), Logger::DEBUG); return; } @@ -1077,7 +1077,7 @@ class Profile // Remove the "addr" parameter from the destination. It is later added as separate parameter again. $addr_request = 'addr=' . urlencode($addr); - $query = rtrim(str_replace($addr_request, '', $a->query_string), '?&'); + $query = rtrim(str_replace($addr_request, '', DI::args()->getQueryString()), '?&'); // The other instance needs to know where to redirect. $dest = urlencode(DI::baseUrl()->get() . '/' . $query); @@ -1164,7 +1164,7 @@ class Profile $arr = [ 'visitor' => $visitor, - 'url' => $a->query_string + 'url' => DI::args()->getQueryString() ]; /** * @hooks magic_auth_success diff --git a/src/Module/Admin/Blocklist/Contact.php b/src/Module/Admin/Blocklist/Contact.php index b2e9c50827..7bcdef4687 100644 --- a/src/Module/Admin/Blocklist/Contact.php +++ b/src/Module/Admin/Blocklist/Contact.php @@ -46,13 +46,11 @@ class Contact extends BaseAdminModule { parent::content($parameters); - $a = DI::app(); - $condition = ['uid' => 0, 'blocked' => true]; $total = DBA::count('contact', $condition); - $pager = new Pager($a->query_string, 30); + $pager = new Pager(DI::args()->getQueryString(), 30); $contacts = Model\Contact::selectToArray([], $condition, ['limit' => [$pager->getStart(), $pager->getItemsPerPage()]]); diff --git a/src/Module/Admin/Users.php b/src/Module/Admin/Users.php index 286bc04452..b71f3f7513 100644 --- a/src/Module/Admin/Users.php +++ b/src/Module/Admin/Users.php @@ -179,7 +179,7 @@ class Users extends BaseAdminModule /* get pending */ $pending = Register::getPending(); - $pager = new Pager($a->query_string, 100); + $pager = new Pager(DI::args()->getQueryString(), 100); // @TODO Move below block to Model\User::getUsers($start, $count, $order = 'contact.name', $order_direction = '+') $valid_orders = [ diff --git a/src/Module/AllFriends.php b/src/Module/AllFriends.php index 14095f4507..47d8c3e264 100644 --- a/src/Module/AllFriends.php +++ b/src/Module/AllFriends.php @@ -49,7 +49,7 @@ class AllFriends extends BaseModule $total = Model\GContact::countAllFriends(local_user(), $cid); - $pager = new Pager($app->query_string); + $pager = new Pager(DI::args()->getQueryString()); $friends = Model\GContact::allFriends(local_user(), $cid, $pager->getStart(), $pager->getItemsPerPage()); if (empty($friends)) { diff --git a/src/Module/BaseAdminModule.php b/src/Module/BaseAdminModule.php index 3a5cde24c8..f985b4a495 100644 --- a/src/Module/BaseAdminModule.php +++ b/src/Module/BaseAdminModule.php @@ -55,7 +55,7 @@ abstract class BaseAdminModule extends BaseModule if (!is_site_admin()) { notice(L10n::t('Please login to continue.')); - Session::set('return_path', $a->query_string); + Session::set('return_path', DI::args()->getQueryString()); DI::baseUrl()->redirect('login'); } diff --git a/src/Module/Bookmarklet.php b/src/Module/Bookmarklet.php index c7f4cdae4a..f5627e4354 100644 --- a/src/Module/Bookmarklet.php +++ b/src/Module/Bookmarklet.php @@ -25,7 +25,7 @@ class Bookmarklet extends BaseModule if (!local_user()) { $output = '

    ' . L10n::t('Login') . '

    '; - $output .= Login::form($app->query_string, intval($config->get('config', 'register_policy')) === Register::CLOSED ? false : true); + $output .= Login::form(DI::args()->getQueryString(), intval($config->get('config', 'register_policy')) === Register::CLOSED ? false : true); return $output; } diff --git a/src/Module/Contact.php b/src/Module/Contact.php index f7c6680ed4..c45a27c88a 100644 --- a/src/Module/Contact.php +++ b/src/Module/Contact.php @@ -425,7 +425,7 @@ class Contact extends BaseModule if (!empty($_REQUEST['confirm'])) { // can't take arguments in its 'action' parameter // so add any arguments as hidden inputs - $query = explode_querystring($a->query_string); + $query = explode_querystring(DI::args()->getQueryString()); $inputs = []; foreach ($query['args'] as $arg) { if (strpos($arg, 'confirm=') === false) { @@ -467,7 +467,7 @@ class Contact extends BaseModule } } - $_SESSION['return_path'] = $a->query_string; + $_SESSION['return_path'] = DI::args()->getQueryString(); if (!empty($a->data['contact']) && is_array($a->data['contact'])) { $contact = $a->data['contact']; @@ -776,7 +776,7 @@ class Contact extends BaseModule if (DBA::isResult($r)) { $total = $r[0]['total']; } - $pager = new Pager($a->query_string); + $pager = new Pager(DI::args()->getQueryString()); $contacts = []; diff --git a/src/Module/Directory.php b/src/Module/Directory.php index 4ad9438fb9..fc4c1be4f8 100644 --- a/src/Module/Directory.php +++ b/src/Module/Directory.php @@ -52,7 +52,7 @@ class Directory extends BaseModule $gDirPath = Profile::zrl($dirURL, true); } - $pager = new Pager($app->query_string, 60); + $pager = new Pager(DI::args()->getQueryString(), 60); $profiles = Profile::searchProfiles($pager->getStart(), $pager->getItemsPerPage(), $search); diff --git a/src/Module/Home.php b/src/Module/Home.php index fbdc252a66..3d04849cf4 100644 --- a/src/Module/Home.php +++ b/src/Module/Home.php @@ -46,7 +46,7 @@ class Home extends BaseModule } } - $login = Login::form($app->query_string, $config->get('config', 'register_policy') === Register::CLOSED ? 0 : 1); + $login = Login::form(DI::args()->getQueryString(), $config->get('config', 'register_policy') === Register::CLOSED ? 0 : 1); $content = ''; Hook::callAll('home_content', $content); diff --git a/src/Module/Objects.php b/src/Module/Objects.php index 4113a545d5..e2f21af1a5 100644 --- a/src/Module/Objects.php +++ b/src/Module/Objects.php @@ -25,7 +25,7 @@ class Objects extends BaseModule } if (!ActivityPub::isRequest()) { - DI::baseUrl()->redirect(str_replace('objects/', 'display/', $a->query_string)); + DI::baseUrl()->redirect(str_replace('objects/', 'display/', DI::args()->getQueryString())); } /// @todo Add Authentication to enable fetching of non public content diff --git a/src/Module/Profile.php b/src/Module/Profile.php index 991aa9126b..8232282dfd 100644 --- a/src/Module/Profile.php +++ b/src/Module/Profile.php @@ -258,7 +258,7 @@ class Profile extends BaseModule return ''; } - $pager = new Pager($a->query_string); + $pager = new Pager(DI::args()->getQueryString()); } else { $sql_post_table = ""; @@ -302,7 +302,7 @@ class Profile extends BaseModule $itemspage_network = $a->force_max_items; } - $pager = new Pager($a->query_string, $itemspage_network); + $pager = new Pager(DI::args()->getQueryString(), $itemspage_network); $pager_sql = sprintf(" LIMIT %d, %d ", $pager->getStart(), $pager->getItemsPerPage()); diff --git a/src/Module/Profile/Contacts.php b/src/Module/Profile/Contacts.php index 9d26f1bbef..f848945bcb 100644 --- a/src/Module/Profile/Contacts.php +++ b/src/Module/Profile/Contacts.php @@ -69,7 +69,7 @@ class Contacts extends BaseModule $total = DBA::count('contact', $condition); - $pager = new Pager($a->query_string); + $pager = new Pager(DI::args()->getQueryString()); $params = ['order' => ['name' => false], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]]; diff --git a/src/Module/Security/Login.php b/src/Module/Security/Login.php index cddd014d00..053e17b1b4 100644 --- a/src/Module/Security/Login.php +++ b/src/Module/Security/Login.php @@ -95,7 +95,7 @@ class Login extends BaseModule } if (is_null($return_path)) { - $return_path = $a->query_string; + $return_path = DI::args()->getQueryString(); } if (local_user()) { diff --git a/src/Object/Post.php b/src/Object/Post.php index 38ef122748..032c7ea4d0 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -890,7 +890,7 @@ class Post $template = Renderer::getMarkupTemplate($this->getCommentBoxTemplate()); $comment_box = Renderer::replaceMacros($template, [ - '$return_path' => $a->query_string, + '$return_path' => DI::args()->getQueryString(), '$threaded' => $this->isThreaded(), '$jsreload' => '', '$wall' => ($conv->getMode() === 'profile'), From 33674808dcbb2336466c65ed9915bda661076ae6 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Mon, 16 Dec 2019 01:33:13 +0100 Subject: [PATCH 22/34] Remove deprecated App::cmd - replace with DI::args()->getCommand() --- include/conversation.php | 6 +++--- mod/api.php | 2 +- mod/cal.php | 2 +- mod/dfrn_request.php | 8 ++++---- mod/events.php | 4 ++-- mod/match.php | 3 ++- mod/message.php | 2 +- mod/network.php | 2 +- mod/photos.php | 4 ++-- mod/pubsub.php | 2 +- mod/suggest.php | 2 +- mod/videos.php | 2 +- src/App.php | 3 --- src/Model/Profile.php | 2 +- src/Module/Contact.php | 2 +- src/Object/Post.php | 2 +- 16 files changed, 23 insertions(+), 25 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index 7025cf4cab..bf1f5645b1 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -480,7 +480,7 @@ function conversation(App $a, array $items, Pager $pager, $mode, $update, $previ */ $live_update_div = '
    ' . "\r\n" . "\r\n"; } } elseif ($mode === 'contacts') { @@ -549,7 +549,7 @@ function conversation(App $a, array $items, Pager $pager, $mode, $update, $previ if (!$update) { $live_update_div = '
    ' . "\r\n" - . "\r\n"; } } elseif ($mode === 'search') { diff --git a/mod/api.php b/mod/api.php index b6a2c0b59f..842c1a74dc 100644 --- a/mod/api.php +++ b/mod/api.php @@ -45,7 +45,7 @@ function api_post(App $a) function api_content(App $a) { - if ($a->cmd == 'api/oauth/authorize') { + if (DI::args()->getCommand() == 'api/oauth/authorize') { /* * api/oauth/authorize interact with the user. return a standard page */ diff --git a/mod/cal.php b/mod/cal.php index 5a4f0a9c51..62508fbef7 100644 --- a/mod/cal.php +++ b/mod/cal.php @@ -221,7 +221,7 @@ function cal_content(App $a) foreach ($r as $rr) { $j = $rr['adjust'] ? DateTimeFormat::local($rr['start'], 'j') : DateTimeFormat::utc($rr['start'], 'j'); if (empty($links[$j])) { - $links[$j] = System::baseUrl() . '/' . $a->cmd . '#link-' . $j; + $links[$j] = System::baseUrl() . '/' . DI::args()->getCommand() . '#link-' . $j; } } } diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index f7dc5f55cd..7f0ad805a7 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -335,19 +335,19 @@ function dfrn_request_post(App $a) $url = Network::isUrlValid($url); if (!$url) { notice(L10n::t('Invalid profile URL.') . EOL); - DI::baseUrl()->redirect($a->cmd); + DI::baseUrl()->redirect(DI::args()->getCommand()); return; // NOTREACHED } if (!Network::isUrlAllowed($url)) { notice(L10n::t('Disallowed profile URL.') . EOL); - DI::baseUrl()->redirect($a->cmd); + DI::baseUrl()->redirect(DI::args()->getCommand()); return; // NOTREACHED } if (Network::isUrlBlocked($url)) { notice(L10n::t('Blocked domain') . EOL); - DI::baseUrl()->redirect($a->cmd); + DI::baseUrl()->redirect(DI::args()->getCommand()); return; // NOTREACHED } @@ -355,7 +355,7 @@ function dfrn_request_post(App $a) if (!count($parms)) { notice(L10n::t('Profile location is not valid or does not contain profile information.') . EOL); - DI::baseUrl()->redirect($a->cmd); + DI::baseUrl()->redirect(DI::args()->getCommand()); } else { if (empty($parms['fn'])) { notice(L10n::t('Warning: profile location has no identifiable owner name.') . EOL); diff --git a/mod/events.php b/mod/events.php index ddcac1bd15..991d0cef7b 100644 --- a/mod/events.php +++ b/mod/events.php @@ -217,7 +217,7 @@ function events_content(App $a) } if ($a->argc == 1) { - $_SESSION['return_path'] = $a->cmd; + $_SESSION['return_path'] = DI::args()->getCommand(); } if (($a->argc > 2) && ($a->argv[1] === 'ignore') && intval($a->argv[2])) { @@ -350,7 +350,7 @@ function events_content(App $a) foreach ($r as $rr) { $j = $rr['adjust'] ? DateTimeFormat::local($rr['start'], 'j') : DateTimeFormat::utc($rr['start'], 'j'); if (empty($links[$j])) { - $links[$j] = System::baseUrl() . '/' . $a->cmd . '#link-' . $j; + $links[$j] = System::baseUrl() . '/' . DI::args()->getCommand() . '#link-' . $j; } } } diff --git a/mod/match.php b/mod/match.php index 41346bc89d..189210f4b5 100644 --- a/mod/match.php +++ b/mod/match.php @@ -11,6 +11,7 @@ use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Profile; use Friendica\Util\Network; @@ -38,7 +39,7 @@ function match_content(App $a) $a->page['aside'] .= Widget::findPeople(); $a->page['aside'] .= Widget::follow(); - $_SESSION['return_path'] = $a->cmd; + $_SESSION['return_path'] = DI::args()->getCommand(); $profile = Profile::getByUID(local_user()); diff --git a/mod/message.php b/mod/message.php index 46ed9b0c12..4c6aa3d848 100644 --- a/mod/message.php +++ b/mod/message.php @@ -89,7 +89,7 @@ function message_post(App $a) $a->argc = 2; $a->argv[1] = 'new'; } else { - DI::baseUrl()->redirect($a->cmd . '/' . $ret); + DI::baseUrl()->redirect(DI::args()->getCommand() . '/' . $ret); } } diff --git a/mod/network.php b/mod/network.php index adc315a548..be121540c1 100644 --- a/mod/network.php +++ b/mod/network.php @@ -914,7 +914,7 @@ function network_tabs(App $a) $all_active = 'active'; } - $cmd = $a->cmd; + $cmd = DI::args()->getCommand(); // tabs $tabs = [ diff --git a/mod/photos.php b/mod/photos.php index 6398211c9b..a0a1be9327 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -846,7 +846,7 @@ function photos_content(App $a) $phototypes = Images::supportedTypes(); - $_SESSION['photo_return'] = $a->cmd; + $_SESSION['photo_return'] = DI::args()->getCommand(); // Parse arguments $datum = null; @@ -1362,7 +1362,7 @@ function photos_content(App $a) if (!empty($link_item['id']) && !empty($link_item['uri'])) { $cmnt_tpl = Renderer::getMarkupTemplate('comment_item.tpl'); $tpl = Renderer::getMarkupTemplate('photo_item.tpl'); - $return_path = $a->cmd; + $return_path = DI::args()->getCommand(); if ($cmd === 'view' && ($can_post || Security::canWriteToUserWall($owner_uid))) { $like_tpl = Renderer::getMarkupTemplate('like_noshare.tpl'); diff --git a/mod/pubsub.php b/mod/pubsub.php index c008fb09da..4c1c2759d8 100644 --- a/mod/pubsub.php +++ b/mod/pubsub.php @@ -86,7 +86,7 @@ function pubsub_post(App $a) { $xml = Network::postdata(); - Logger::log('Feed arrived from ' . $_SERVER['REMOTE_ADDR'] . ' for ' . $a->cmd . ' with user-agent: ' . $_SERVER['HTTP_USER_AGENT']); + Logger::log('Feed arrived from ' . $_SERVER['REMOTE_ADDR'] . ' for ' . DI::args()->getCommand() . ' with user-agent: ' . $_SERVER['HTTP_USER_AGENT']); Logger::log('Data: ' . $xml, Logger::DATA); $nick = (($a->argc > 1) ? Strings::escapeTags(trim($a->argv[1])) : ''); diff --git a/mod/suggest.php b/mod/suggest.php index daf5de00fc..15370d25a9 100644 --- a/mod/suggest.php +++ b/mod/suggest.php @@ -41,7 +41,7 @@ function suggest_content(App $a) return; } - $_SESSION['return_path'] = $a->cmd; + $_SESSION['return_path'] = DI::args()->getCommand(); $a->page['aside'] .= Widget::findPeople(); $a->page['aside'] .= Widget::follow(); diff --git a/mod/videos.php b/mod/videos.php index 6d136d7de5..b6f6b1d8e7 100644 --- a/mod/videos.php +++ b/mod/videos.php @@ -124,7 +124,7 @@ function videos_content(App $a) //$phototypes = Photo::supportedTypes(); - $_SESSION['video_return'] = $a->cmd; + $_SESSION['video_return'] = DI::args()->getCommand(); // // Parse arguments diff --git a/src/App.php b/src/App.php index c028f9d9d8..892039dc5a 100644 --- a/src/App.php +++ b/src/App.php @@ -53,8 +53,6 @@ class App public $page_contact; public $content; public $data = []; - /** @deprecated 2019.09 - use App\Arguments->getCommand() */ - public $cmd = ''; /** @deprecated 2019.09 - use App\Arguments->getArgv() or Arguments->get() */ public $argv; /** @deprecated 2019.09 - use App\Arguments->getArgc() */ @@ -170,7 +168,6 @@ class App $this->args = $args; $this->process = $process; - $this->cmd = $args->getCommand(); $this->argv = $args->getArgv(); $this->argc = $args->getArgc(); $this->module = $module->getName(); diff --git a/src/Model/Profile.php b/src/Model/Profile.php index 69ec447951..a08cdade12 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -1047,7 +1047,7 @@ class Profile $addr = $_GET['addr'] ?? $my_url; - $arr = ['zrl' => $my_url, 'url' => $a->cmd]; + $arr = ['zrl' => $my_url, 'url' => DI::args()->getCommand()]; Hook::callAll('zrl_init', $arr); // Try to find the public contact entry of the visitor. diff --git a/src/Module/Contact.php b/src/Module/Contact.php index c45a27c88a..d307652b63 100644 --- a/src/Module/Contact.php +++ b/src/Module/Contact.php @@ -819,7 +819,7 @@ class Contact extends BaseModule '$desc' => L10n::t('Search your contacts'), '$finding' => $searching ? L10n::t('Results for: %s', $search) : '', '$submit' => L10n::t('Find'), - '$cmd' => $a->cmd, + '$cmd' => DI::args()->getCommand(), '$contacts' => $contacts, '$contact_drop_confirm' => L10n::t('Do you really want to delete this contact?'), 'multiselect' => 1, diff --git a/src/Object/Post.php b/src/Object/Post.php index 032c7ea4d0..fd99a206de 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -453,7 +453,7 @@ class Post 'received' => $item['received'], 'commented' => $item['commented'], 'created_date' => $item['created'], - 'return' => ($a->cmd) ? bin2hex($a->cmd) : '', + 'return' => (DI::args()->getCommand()) ? bin2hex(DI::args()->getCommand()) : '', 'delivery' => [ 'queue_count' => $item['delivery_queue_count'], 'queue_done' => $item['delivery_queue_done'] + $item['delivery_queue_failed'], /// @todo Possibly display it separately in the future From 4835f1185f7aa028948c3817c51f1aac6e9cbfb1 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Mon, 16 Dec 2019 01:35:26 +0100 Subject: [PATCH 23/34] Remove deprecated App::module - replace with DI::module()->getName() --- include/api.php | 26 +++++---- src/App.php | 5 +- src/App/Authentication.php | 3 +- src/Content/Nav.php | 4 +- src/Core/ACL.php | 8 +-- tests/include/ApiTest.php | 70 +++++++++++++++-------- tests/src/Core/Lock/SemaphoreLockTest.php | 3 +- view/theme/frio/php/default.php | 2 +- 8 files changed, 72 insertions(+), 49 deletions(-) diff --git a/include/api.php b/include/api.php index e4a47cf42a..048d07d0a2 100644 --- a/include/api.php +++ b/include/api.php @@ -283,30 +283,35 @@ function api_check_method($method) * @brief Main API entry point * * @param App $a App + * @param App\Arguments $args The app arguments (optional, will retrieved by the DI-Container in case of missing) * @return string|array API call result * @throws Exception */ -function api_call(App $a) +function api_call(App $a, App\Arguments $args = null) { global $API, $called_api; + if ($args == null) { + $args = DI::args(); + } + $type = "json"; - if (strpos(DI::args()->getQueryString(), ".xml") > 0) { + if (strpos($args->getQueryString(), ".xml") > 0) { $type = "xml"; } - if (strpos(DI::args()->getQueryString(), ".json") > 0) { + if (strpos($args->getQueryString(), ".json") > 0) { $type = "json"; } - if (strpos(DI::args()->getQueryString(), ".rss") > 0) { + if (strpos($args->getQueryString(), ".rss") > 0) { $type = "rss"; } - if (strpos(DI::args()->getQueryString(), ".atom") > 0) { + if (strpos($args->getQueryString(), ".atom") > 0) { $type = "atom"; } try { foreach ($API as $p => $info) { - if (strpos(DI::args()->getQueryString(), $p) === 0) { + if (strpos($args->getQueryString(), $p) === 0) { if (!api_check_method($info['method'])) { throw new MethodNotAllowedException(); } @@ -369,7 +374,7 @@ function api_call(App $a) throw new NotImplementedException(); } catch (HTTPException $e) { header("HTTP/1.1 {$e->getCode()} {$e->httpdesc}"); - return api_error($type, $e); + return api_error($type, $e, $args); } } @@ -378,18 +383,17 @@ function api_call(App $a) * * @param string $type Return type (xml, json, rss, as) * @param object $e HTTPException Error object + * @param App\Arguments $args The App arguments * @return string|array error message formatted as $type */ -function api_error($type, $e) +function api_error($type, $e, App\Arguments $args) { - $a = \get_app(); - $error = ($e->getMessage() !== "" ? $e->getMessage() : $e->httpdesc); /// @TODO: https://dev.twitter.com/overview/api/response-codes $error = ["error" => $error, "code" => $e->getCode() . " " . $e->httpdesc, - "request" => DI::args()->getQueryString()]; + "request" => $args->getQueryString()]; $return = api_format_data('status', $type, ['status' => $error]); diff --git a/src/App.php b/src/App.php index 892039dc5a..75fa4f197b 100644 --- a/src/App.php +++ b/src/App.php @@ -57,8 +57,6 @@ class App public $argv; /** @deprecated 2019.09 - use App\Arguments->getArgc() */ public $argc; - /** @deprecated 2019.09 - Use App\Module->getName() instead */ - public $module; public $timezone; public $interactive = true; public $identities; @@ -156,7 +154,7 @@ class App * @param App\Arguments $args The Friendica Arguments of the call * @param Core\Process $process The process methods */ - public function __construct(Database $database, Configuration $config, App\Mode $mode, BaseURL $baseURL, LoggerInterface $logger, Profiler $profiler, L10n $l10n, Arguments $args, App\Module $module, App\Page $page, Core\Process $process) + public function __construct(Database $database, Configuration $config, App\Mode $mode, BaseURL $baseURL, LoggerInterface $logger, Profiler $profiler, L10n $l10n, Arguments $args, App\Page $page, Core\Process $process) { $this->database = $database; $this->config = $config; @@ -170,7 +168,6 @@ class App $this->argv = $args->getArgv(); $this->argc = $args->getArgc(); - $this->module = $module->getName(); $this->page = $page; $this->load(); diff --git a/src/App/Authentication.php b/src/App/Authentication.php index b8073698f2..22d429c76b 100644 --- a/src/App/Authentication.php +++ b/src/App/Authentication.php @@ -15,6 +15,7 @@ use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Database\Database; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\User; use Friendica\Network\HTTPException; use Friendica\Util\DateTimeFormat; @@ -378,7 +379,7 @@ class Authentication if ($login_initial) { Hook::callAll('logged_in', $a->user); - if ($a->module !== 'home' && $this->session->exists('return_path')) { + if (DI::module()->getName() !== 'home' && $this->session->exists('return_path')) { $this->baseUrl->redirect($this->session->get('return_path')); } } diff --git a/src/Content/Nav.php b/src/Content/Nav.php index 6fca7beb91..3594bae50e 100644 --- a/src/Content/Nav.php +++ b/src/Content/Nav.php @@ -153,7 +153,7 @@ class Nav if (Session::isAuthenticated()) { $nav['logout'] = ['logout', L10n::t('Logout'), '', L10n::t('End this session')]; } else { - $nav['login'] = ['login', L10n::t('Login'), ($a->module == 'login' ? 'selected' : ''), L10n::t('Sign in')]; + $nav['login'] = ['login', L10n::t('Login'), (DI::module()->getName() == 'login' ? 'selected' : ''), L10n::t('Sign in')]; } if (local_user()) { @@ -179,7 +179,7 @@ class Nav $homelink = Session::get('visitor_home', ''); } - if (($a->module != 'home') && (! (local_user()))) { + if ((DI::module()->getName() != 'home') && (! (local_user()))) { $nav['home'] = [$homelink, L10n::t('Home'), '', L10n::t('Home Page')]; } diff --git a/src/Core/ACL.php b/src/Core/ACL.php index d48ef3fa51..a4b4a99190 100644 --- a/src/Core/ACL.php +++ b/src/Core/ACL.php @@ -109,7 +109,7 @@ class ACL $arr = ['contact' => $contacts, 'entry' => $o]; // e.g. 'network_pre_contact_deny', 'profile_pre_contact_allow' - Hook::callAll($a->module . '_pre_' . $selname, $arr); + Hook::callAll(DI::module()->getName() . '_pre_' . $selname, $arr); if (DBA::isResult($contacts)) { foreach ($contacts as $contact) { @@ -127,7 +127,7 @@ class ACL $o .= '' . PHP_EOL; - Hook::callAll($a->module . '_post_' . $selname, $o); + Hook::callAll(DI::module()->getName() . '_post_' . $selname, $o); return $o; } @@ -175,7 +175,7 @@ class ACL $arr = ['contact' => $contacts, 'entry' => $o]; // e.g. 'network_pre_contact_deny', 'profile_pre_contact_allow' - Hook::callAll($a->module . '_pre_' . $selname, $arr); + Hook::callAll(DI::module()->getName() . '_pre_' . $selname, $arr); $receiverlist = []; @@ -201,7 +201,7 @@ class ACL $o .= implode(', ', $receiverlist); } - Hook::callAll($a->module . '_post_' . $selname, $o); + Hook::callAll(DI::module()->getName() . '_post_' . $selname, $o); return $o; } diff --git a/tests/include/ApiTest.php b/tests/include/ApiTest.php index dcd98fcce9..74c220d849 100644 --- a/tests/include/ApiTest.php +++ b/tests/include/ApiTest.php @@ -115,8 +115,7 @@ class ApiTest extends DatabaseTest // User ID that we know is not in the database $this->wrongUserId = 666; - $session = DI::session(); - $session->start(); + DI::session()->start(); // Most API require login so we force the session $_SESSION = [ @@ -433,12 +432,14 @@ class ApiTest extends DatabaseTest } ]; $_SERVER['REQUEST_METHOD'] = 'method'; + $_SERVER['QUERY_STRING'] = 'q=api_path'; $_GET['callback'] = 'callback_name'; - $this->app->query_string = 'api_path'; + $args = DI::args()->determine($_SERVER, $_GET); + $this->assertEquals( 'callback_name(["some_data"])', - api_call($this->app) + api_call($this->app, $args) ); } @@ -457,7 +458,12 @@ class ApiTest extends DatabaseTest return ['data' => ['some_data']]; } ]; + $_SERVER['REQUEST_METHOD'] = 'method'; + $_SERVER['QUERY_STRING'] = 'q=api_path'; + + $args = DI::args()->determine($_SERVER, $_GET); + $this->config->set('system', 'profiler', true); $this->config->set('rendertime', 'callstack', true); $this->app->callstack = [ @@ -468,10 +474,9 @@ class ApiTest extends DatabaseTest 'network' => ['some_function' => 200] ]; - $this->app->query_string = 'api_path'; $this->assertEquals( '["some_data"]', - api_call($this->app) + api_call($this->app, $args) ); } @@ -491,11 +496,13 @@ class ApiTest extends DatabaseTest } ]; $_SERVER['REQUEST_METHOD'] = 'method'; + $_SERVER['QUERY_STRING'] = 'q=api_path'; + + $args = DI::args()->determine($_SERVER, $_GET); - $this->app->query_string = 'api_path'; $this->assertEquals( '{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}', - api_call($this->app) + api_call($this->app, $args) ); } @@ -529,11 +536,13 @@ class ApiTest extends DatabaseTest } ]; $_SERVER['REQUEST_METHOD'] = 'method'; + $_SERVER['QUERY_STRING'] = 'q=api_path.json'; + + $args = DI::args()->determine($_SERVER, $_GET); - $this->app->query_string = 'api_path.json'; $this->assertEquals( '["some_data"]', - api_call($this->app) + api_call($this->app, $args) ); } @@ -553,11 +562,13 @@ class ApiTest extends DatabaseTest } ]; $_SERVER['REQUEST_METHOD'] = 'method'; + $_SERVER['QUERY_STRING'] = 'q=api_path.xml'; + + $args = DI::args()->determine($_SERVER, $_GET); - $this->app->query_string = 'api_path.xml'; $this->assertEquals( 'some_data', - api_call($this->app) + api_call($this->app, $args) ); } @@ -577,12 +588,14 @@ class ApiTest extends DatabaseTest } ]; $_SERVER['REQUEST_METHOD'] = 'method'; + $_SERVER['QUERY_STRING'] = 'q=api_path.rss'; + + $args = DI::args()->determine($_SERVER, $_GET); - $this->app->query_string = 'api_path.rss'; $this->assertEquals( '' . "\n" . 'some_data', - api_call($this->app) + api_call($this->app, $args) ); } @@ -602,12 +615,14 @@ class ApiTest extends DatabaseTest } ]; $_SERVER['REQUEST_METHOD'] = 'method'; + $_SERVER['QUERY_STRING'] = 'q=api_path.atom'; + + $args = DI::args()->determine($_SERVER, $_GET); - $this->app->query_string = 'api_path.atom'; $this->assertEquals( '' . "\n" . 'some_data', - api_call($this->app) + api_call($this->app, $args) ); } @@ -622,10 +637,13 @@ class ApiTest extends DatabaseTest global $API; $API['api_path'] = ['method' => 'method']; - $this->app->query_string = 'api_path'; + $_SERVER['QUERY_STRING'] = 'q=api_path'; + + $args = DI::args()->determine($_SERVER, $_GET); + $this->assertEquals( '{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}', - api_call($this->app) + api_call($this->app, $args) ); } @@ -642,13 +660,15 @@ class ApiTest extends DatabaseTest 'method' => 'method', 'auth' => true ]; - $_SERVER['REQUEST_METHOD'] = 'method'; $_SESSION['authenticated'] = false; + $_SERVER['REQUEST_METHOD'] = 'method'; + $_SERVER['QUERY_STRING'] = 'q=api_path'; + + $args = DI::args()->determine($_SERVER, $_GET); - $this->app->query_string = 'api_path'; $this->assertEquals( '{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}', - api_call($this->app) + api_call($this->app, $args) ); } @@ -662,7 +682,7 @@ class ApiTest extends DatabaseTest { $this->assertEquals( '{"status":{"error":"error_message","code":"200 OK","request":""}}', - api_error('json', new HTTPException\OKException('error_message')) + api_error('json', new HTTPException\OKException('error_message'), DI::args()) ); } @@ -683,7 +703,7 @@ class ApiTest extends DatabaseTest ' 200 OK' . "\n" . ' ' . "\n" . '' . "\n", - api_error('xml', new HTTPException\OKException('error_message')) + api_error('xml', new HTTPException\OKException('error_message'), DI::args()) ); } @@ -704,7 +724,7 @@ class ApiTest extends DatabaseTest ' 200 OK' . "\n" . ' ' . "\n" . '' . "\n", - api_error('rss', new HTTPException\OKException('error_message')) + api_error('rss', new HTTPException\OKException('error_message'), DI::args()) ); } @@ -725,7 +745,7 @@ class ApiTest extends DatabaseTest ' 200 OK' . "\n" . ' ' . "\n" . '' . "\n", - api_error('atom', new HTTPException\OKException('error_message')) + api_error('atom', new HTTPException\OKException('error_message'), DI::args()) ); } diff --git a/tests/src/Core/Lock/SemaphoreLockTest.php b/tests/src/Core/Lock/SemaphoreLockTest.php index 8a4baa4fa9..040cdeb521 100644 --- a/tests/src/Core/Lock/SemaphoreLockTest.php +++ b/tests/src/Core/Lock/SemaphoreLockTest.php @@ -5,6 +5,7 @@ namespace Friendica\Test\src\Core\Lock; use Dice\Dice; use Friendica\App; use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\JitConfiguration; use Friendica\Core\Lock\SemaphoreLock; use Friendica\DI; @@ -18,7 +19,7 @@ class SemaphoreLockTest extends LockTest $app->shouldReceive('getHostname')->andReturn('friendica.local'); $dice->shouldReceive('create')->with(App::class)->andReturn($app); - $configMock = \Mockery::mock(Configuration::class); + $configMock = \Mockery::mock(JitConfiguration::class); $configMock ->shouldReceive('get') ->with('system', 'temppath', NULL, false) diff --git a/view/theme/frio/php/default.php b/view/theme/frio/php/default.php index cdb0f16673..5579680a33 100644 --- a/view/theme/frio/php/default.php +++ b/view/theme/frio/php/default.php @@ -66,7 +66,7 @@ $is_singleuser_class = $is_singleuser ? "is-singleuser" : "is-not-singleuser"; ?> - "> + "> Skip to main content Date: Thu, 19 Dec 2019 20:11:07 +0100 Subject: [PATCH 24/34] Creating interfaces for Config/PConfig & fix tests --- index.php | 2 +- src/App.php | 14 ++-- src/App/Authentication.php | 8 +- src/App/BaseURL.php | 8 +- src/App/Module.php | 4 +- src/App/Page.php | 16 ++-- src/Console/AutomaticInstallation.php | 4 +- src/Console/Config.php | 6 +- src/Console/Maintenance.php | 6 +- src/Console/PostUpdate.php | 6 +- src/Console/ServerBlock.php | 18 ++-- src/Console/Typo.php | 6 +- src/Core/Cache/MemcacheCache.php | 4 +- src/Core/Cache/MemcachedCache.php | 4 +- src/Core/Cache/RedisCache.php | 4 +- src/Core/Config/Configuration.php | 62 +------------- src/Core/Config/IConfiguration.php | 73 +++++++++++++++++ src/Core/Config/IPConfiguration.php | 82 +++++++++++++++++++ src/Core/Config/PConfiguration.php | 66 +-------------- src/Core/L10n/L10n.php | 4 +- src/Core/Process.php | 6 +- src/DI.php | 12 +-- src/Factory/CacheFactory.php | 6 +- src/Factory/ConfigFactory.php | 4 +- src/Factory/LockFactory.php | 6 +- src/Factory/LoggerFactory.php | 10 +-- src/Factory/SessionFactory.php | 7 +- src/Model/Notify.php | 6 +- src/Model/User/Cookie.php | 4 +- src/Module/Diaspora/Receive.php | 3 - src/Util/Profiler.php | 6 +- static/dependencies.config.php | 4 +- tests/Util/AppMockTrait.php | 12 +-- tests/bootstrap.php | 7 ++ tests/functional/DependencyCheckTest.php | 12 +-- tests/include/ApiTest.php | 16 ++-- tests/phpunit-local.xml | 26 ++++++ tests/src/App/ModuleTest.php | 4 +- tests/src/Console/ConfigConsoleTest.php | 4 +- tests/src/Console/ServerBlockConsoleTest.php | 4 +- tests/src/Content/Text/BBCodeTest.php | 4 +- tests/src/Core/Cache/MemcacheCacheTest.php | 4 +- tests/src/Core/Cache/MemcachedCacheTest.php | 4 +- tests/src/Core/Cache/RedisCacheTest.php | 4 +- tests/src/Core/Config/ConfigurationTest.php | 7 +- tests/src/Core/InstallerTest.php | 8 +- tests/src/Core/Lock/MemcacheCacheLockTest.php | 4 +- .../src/Core/Lock/MemcachedCacheLockTest.php | 4 +- tests/src/Core/Lock/RedisCacheLockTest.php | 4 +- tests/src/Core/Lock/SemaphoreLockTest.php | 8 +- tests/src/Model/User/CookieTest.php | 6 +- tests/src/Network/CurlResultTest.php | 3 +- tests/src/Util/BaseURLTest.php | 14 ++-- tests/src/Util/ProfilerTest.php | 4 +- 54 files changed, 349 insertions(+), 285 deletions(-) create mode 100644 src/Core/Config/IConfiguration.php create mode 100644 src/Core/Config/IPConfiguration.php create mode 100644 tests/phpunit-local.xml diff --git a/index.php b/index.php index b558e86c8e..8400ca820f 100644 --- a/index.php +++ b/index.php @@ -22,6 +22,6 @@ $a = \Friendica\DI::app(); $a->runFrontend( $dice->create(\Friendica\App\Module::class), $dice->create(\Friendica\App\Router::class), - $dice->create(\Friendica\Core\Config\PConfiguration::class), + $dice->create(\Friendica\Core\Config\IPConfiguration::class), $dice->create(\Friendica\App\Authentication::class) ); diff --git a/src/App.php b/src/App.php index 75fa4f197b..71b64bdb64 100644 --- a/src/App.php +++ b/src/App.php @@ -10,8 +10,8 @@ use Friendica\App\BaseURL; use Friendica\App\Page; use Friendica\App\Authentication; use Friendica\Core\Config\Cache\ConfigCache; -use Friendica\Core\Config\Configuration; -use Friendica\Core\Config\PConfiguration; +use Friendica\Core\Config\IConfiguration; +use Friendica\Core\Config\IPConfiguration; use Friendica\Core\L10n\L10n; use Friendica\Core\System; use Friendica\Core\Theme; @@ -88,7 +88,7 @@ class App private $currentMobileTheme; /** - * @var Configuration The config + * @var IConfiguration The config */ private $config; @@ -145,7 +145,7 @@ class App /** * @param Database $database The Friendica Database - * @param Configuration $config The Configuration + * @param IConfiguration $config The Configuration * @param App\Mode $mode The mode of this Friendica app * @param BaseURL $baseURL The full base URL of this Friendica app * @param LoggerInterface $logger The current app logger @@ -154,7 +154,7 @@ class App * @param App\Arguments $args The Friendica Arguments of the call * @param Core\Process $process The process methods */ - public function __construct(Database $database, Configuration $config, App\Mode $mode, BaseURL $baseURL, LoggerInterface $logger, Profiler $profiler, L10n $l10n, Arguments $args, App\Page $page, Core\Process $process) + public function __construct(Database $database, IConfiguration $config, App\Mode $mode, BaseURL $baseURL, LoggerInterface $logger, Profiler $profiler, L10n $l10n, Arguments $args, App\Page $page, Core\Process $process) { $this->database = $database; $this->config = $config; @@ -433,12 +433,12 @@ class App * * @param App\Module $module The determined module * @param App\Router $router - * @param PConfiguration $pconfig + * @param IPConfiguration $pconfig * @param Authentication $auth The Authentication backend of the node * @throws HTTPException\InternalServerErrorException * @throws \ImagickException */ - public function runFrontend(App\Module $module, App\Router $router, PConfiguration $pconfig, Authentication $auth) + public function runFrontend(App\Module $module, App\Router $router, IPConfiguration $pconfig, Authentication $auth) { $moduleName = $module->getName(); diff --git a/src/App/Authentication.php b/src/App/Authentication.php index 22d429c76b..cb07d7afc2 100644 --- a/src/App/Authentication.php +++ b/src/App/Authentication.php @@ -8,7 +8,7 @@ namespace Friendica\App; use Exception; use Friendica\App; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; use Friendica\Core\Hook; use Friendica\Core\PConfig; use Friendica\Core\Session; @@ -30,7 +30,7 @@ use Psr\Log\LoggerInterface; */ class Authentication { - /** @var Configuration */ + /** @var IConfiguration */ private $config; /** @var App\Mode */ private $mode; @@ -50,7 +50,7 @@ class Authentication /** * Authentication constructor. * - * @param Configuration $config + * @param IConfiguration $config * @param App\Mode $mode * @param App\BaseURL $baseUrl * @param L10n $l10n @@ -59,7 +59,7 @@ class Authentication * @param User\Cookie $cookie * @param Session\ISession $session */ - public function __construct(Configuration $config, App\Mode $mode, App\BaseURL $baseUrl, L10n $l10n, Database $dba, LoggerInterface $logger, User\Cookie $cookie, Session\ISession $session) + public function __construct(IConfiguration $config, App\Mode $mode, App\BaseURL $baseUrl, L10n $l10n, Database $dba, LoggerInterface $logger, User\Cookie $cookie, Session\ISession $session) { $this->config = $config; $this->mode = $mode; diff --git a/src/App/BaseURL.php b/src/App/BaseURL.php index 501e5fbd3b..ea7d9ec74a 100644 --- a/src/App/BaseURL.php +++ b/src/App/BaseURL.php @@ -2,7 +2,7 @@ namespace Friendica\App; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; use Friendica\Core\System; use Friendica\Util\Network; use Friendica\Util\Strings; @@ -37,7 +37,7 @@ class BaseURL /** * The Friendica Config * - * @var Configuration + * @var IConfiguration */ private $config; @@ -253,10 +253,10 @@ class BaseURL } /** - * @param Configuration $config The Friendica configuration + * @param IConfiguration $config The Friendica IConfiguration * @param array $server The $_SERVER array */ - public function __construct(Configuration $config, array $server) + public function __construct(IConfiguration $config, array $server) { $this->config = $config; $this->server = $server; diff --git a/src/App/Module.php b/src/App/Module.php index 51be234937..7c81b6a7ea 100644 --- a/src/App/Module.php +++ b/src/App/Module.php @@ -151,13 +151,13 @@ class Module * * @param Arguments $args The Friendica execution arguments * @param Router $router The Friendica routing instance - * @param Core\Config\Configuration $config The Friendica Configuration + * @param Core\Config\IConfiguration $config The Friendica Configuration * * @return Module The determined module of this call * * @throws \Exception */ - public function determineClass(Arguments $args, Router $router, Core\Config\Configuration $config) + public function determineClass(Arguments $args, Router $router, Core\Config\IConfiguration $config) { $printNotAllowedAddon = false; diff --git a/src/App/Page.php b/src/App/Page.php index ca98bb6b23..5efb9f7ca3 100644 --- a/src/App/Page.php +++ b/src/App/Page.php @@ -7,8 +7,8 @@ use DOMDocument; use DOMXPath; use Friendica\App; use Friendica\Content\Nav; -use Friendica\Core\Config\Configuration; -use Friendica\Core\Config\PConfiguration; +use Friendica\Core\Config\IConfiguration; +use Friendica\Core\Config\IPConfiguration; use Friendica\Core\Hook; use Friendica\Core\L10n\L10n; use Friendica\Core\Renderer; @@ -171,12 +171,12 @@ class Page implements ArrayAccess * @param App $app The Friendica App instance * @param Module $module The loaded Friendica module * @param L10n $l10n The l10n language instance - * @param Configuration $config The Friendica configuration - * @param PConfiguration $pConfig The Friendica personal configuration (for user) + * @param IConfiguration $config The Friendica configuration + * @param IPConfiguration $pConfig The Friendica personal configuration (for user) * * @throws HTTPException\InternalServerErrorException */ - private function initHead(App $app, Module $module, L10n $l10n, Configuration $config, PConfiguration $pConfig) + private function initHead(App $app, Module $module, L10n $l10n, IConfiguration $config, IPConfiguration $pConfig) { $interval = ((local_user()) ? $pConfig->get(local_user(), 'system', 'update_interval') : 40000); @@ -347,12 +347,12 @@ class Page implements ArrayAccess * @param Mode $mode The current node mode * @param Module $module The loaded Friendica module * @param L10n $l10n The l10n language class - * @param Configuration $config The Configuration of this node - * @param PConfiguration $pconfig The personal/user configuration + * @param IConfiguration $config The Configuration of this node + * @param IPConfiguration $pconfig The personal/user configuration * * @throws HTTPException\InternalServerErrorException */ - public function run(App $app, BaseURL $baseURL, Mode $mode, Module $module, L10n $l10n, Configuration $config, PConfiguration $pconfig) + public function run(App $app, BaseURL $baseURL, Mode $mode, Module $module, L10n $l10n, IConfiguration $config, IPConfiguration $pconfig) { $moduleName = $module->getName(); diff --git a/src/Console/AutomaticInstallation.php b/src/Console/AutomaticInstallation.php index 8815b98799..1d378b9deb 100644 --- a/src/Console/AutomaticInstallation.php +++ b/src/Console/AutomaticInstallation.php @@ -25,7 +25,7 @@ class AutomaticInstallation extends Console private $configCache; /** - * @var Config\Configuration + * @var Config\IConfiguration */ private $config; @@ -89,7 +89,7 @@ Examples HELP; } - public function __construct(App\Mode $appMode, Config\Cache\ConfigCache $configCache, Config\Configuration $config, Database $dba, array $argv = null) + public function __construct(App\Mode $appMode, Config\Cache\ConfigCache $configCache, Config\IConfiguration $config, Database $dba, array $argv = null) { parent::__construct($argv); diff --git a/src/Console/Config.php b/src/Console/Config.php index 797f639491..38c60a1e2b 100644 --- a/src/Console/Config.php +++ b/src/Console/Config.php @@ -4,7 +4,7 @@ namespace Friendica\Console; use Asika\SimpleConsole\CommandArgsException; use Friendica\App; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; use RuntimeException; /** @@ -40,7 +40,7 @@ class Config extends \Asika\SimpleConsole\Console */ private $appMode; /** - * @var Configuration + * @var IConfiguration */ private $config; @@ -78,7 +78,7 @@ HELP; return $help; } - public function __construct(App\Mode $appMode, Configuration $config, array $argv = null) + public function __construct(App\Mode $appMode, IConfiguration $config, array $argv = null) { parent::__construct($argv); diff --git a/src/Console/Maintenance.php b/src/Console/Maintenance.php index 26b77a9741..9633a50e9d 100644 --- a/src/Console/Maintenance.php +++ b/src/Console/Maintenance.php @@ -3,7 +3,7 @@ namespace Friendica\Console; use Friendica\App; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; /** * @brief Sets maintenance mode for this node @@ -19,7 +19,7 @@ class Maintenance extends \Asika\SimpleConsole\Console */ private $appMode; /** - * @var Configuration + * @var IConfiguration */ private $config; @@ -52,7 +52,7 @@ HELP; return $help; } - public function __construct(App\Mode $appMode, Configuration $config, $argv = null) + public function __construct(App\Mode $appMode, IConfiguration $config, $argv = null) { parent::__construct($argv); diff --git a/src/Console/PostUpdate.php b/src/Console/PostUpdate.php index f6a7f69d22..f3e81c1af5 100644 --- a/src/Console/PostUpdate.php +++ b/src/Console/PostUpdate.php @@ -3,7 +3,7 @@ namespace Friendica\Console; use Friendica\App; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; use Friendica\Core\L10n\L10n; use Friendica\Core\Update; @@ -24,7 +24,7 @@ class PostUpdate extends \Asika\SimpleConsole\Console */ private $appMode; /** - * @var Configuration + * @var IConfiguration */ private $config; /** @@ -46,7 +46,7 @@ HELP; return $help; } - public function __construct(App\Mode $appMode, Configuration $config, L10n $l10n, array $argv = null) + public function __construct(App\Mode $appMode, IConfiguration $config, L10n $l10n, array $argv = null) { parent::__construct($argv); diff --git a/src/Console/ServerBlock.php b/src/Console/ServerBlock.php index 322f8f6ee3..f94c24dbd9 100644 --- a/src/Console/ServerBlock.php +++ b/src/Console/ServerBlock.php @@ -5,7 +5,7 @@ namespace Friendica\Console; use Asika\SimpleConsole\CommandArgsException; use Asika\SimpleConsole\Console; use Console_Table; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; /** * @brief Manage blocked servers @@ -20,7 +20,7 @@ class ServerBlock extends Console protected $helpOptions = ['h', 'help', '?']; /** - * @var Configuration + * @var IConfiguration */ private $config; @@ -49,7 +49,7 @@ HELP; return $help; } - public function __construct(Configuration $config, $argv = null) + public function __construct(IConfiguration $config, $argv = null) { parent::__construct($argv); @@ -77,9 +77,9 @@ HELP; /** * Prints the whole list of blocked domains including the reason * - * @param Configuration $config + * @param IConfiguration $config */ - private function printBlockedServers(Configuration $config) + private function printBlockedServers(IConfiguration $config) { $table = new Console_Table(); $table->setHeaders(['Domain', 'Reason']); @@ -93,11 +93,11 @@ HELP; /** * Adds a server to the blocked list * - * @param Configuration $config + * @param IConfiguration $config * * @return int The return code (0 = success, 1 = failed) */ - private function addBlockedServer(Configuration $config) + private function addBlockedServer(IConfiguration $config) { if (count($this->args) < 2 || count($this->args) > 3) { throw new CommandArgsException('Add needs a domain and optional a reason.'); @@ -145,11 +145,11 @@ HELP; /** * Removes a server from the blocked list * - * @param Configuration $config + * @param IConfiguration $config * * @return int The return code (0 = success, 1 = failed) */ - private function removeBlockedServer(Configuration $config) + private function removeBlockedServer(IConfiguration $config) { if (count($this->args) !== 2) { throw new CommandArgsException('Remove needs a second parameter.'); diff --git a/src/Console/Typo.php b/src/Console/Typo.php index 855c1705c2..a0b6e3691c 100644 --- a/src/Console/Typo.php +++ b/src/Console/Typo.php @@ -2,7 +2,7 @@ namespace Friendica\Console; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; /** * Tired of chasing typos and finding them after a commit. @@ -15,7 +15,7 @@ class Typo extends \Asika\SimpleConsole\Console protected $helpOptions = ['h', 'help', '?']; /** - * @var Configuration + * @var IConfiguration */ private $config; @@ -36,7 +36,7 @@ HELP; return $help; } - public function __construct(Configuration $config, array $argv = null) + public function __construct(IConfiguration $config, array $argv = null) { parent::__construct($argv); diff --git a/src/Core/Cache/MemcacheCache.php b/src/Core/Cache/MemcacheCache.php index 6797a70c2b..5bf231b398 100644 --- a/src/Core/Cache/MemcacheCache.php +++ b/src/Core/Cache/MemcacheCache.php @@ -3,7 +3,7 @@ namespace Friendica\Core\Cache; use Exception; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; use Memcache; /** @@ -25,7 +25,7 @@ class MemcacheCache extends Cache implements IMemoryCache /** * @throws Exception */ - public function __construct(string $hostname, Configuration $config) + public function __construct(string $hostname, IConfiguration $config) { if (!class_exists('Memcache', false)) { throw new Exception('Memcache class isn\'t available'); diff --git a/src/Core/Cache/MemcachedCache.php b/src/Core/Cache/MemcachedCache.php index 95bfae39f2..5476e3766a 100644 --- a/src/Core/Cache/MemcachedCache.php +++ b/src/Core/Cache/MemcachedCache.php @@ -3,7 +3,7 @@ namespace Friendica\Core\Cache; use Exception; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; use Memcached; use Psr\Log\LoggerInterface; @@ -39,7 +39,7 @@ class MemcachedCache extends Cache implements IMemoryCache * * @throws \Exception */ - public function __construct(string $hostname, Configuration $config, LoggerInterface $logger) + public function __construct(string $hostname, IConfiguration $config, LoggerInterface $logger) { if (!class_exists('Memcached', false)) { throw new Exception('Memcached class isn\'t available'); diff --git a/src/Core/Cache/RedisCache.php b/src/Core/Cache/RedisCache.php index 3558a38464..7af9f3d236 100644 --- a/src/Core/Cache/RedisCache.php +++ b/src/Core/Cache/RedisCache.php @@ -3,7 +3,7 @@ namespace Friendica\Core\Cache; use Exception; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; use Redis; /** @@ -22,7 +22,7 @@ class RedisCache extends Cache implements IMemoryCache /** * @throws Exception */ - public function __construct(string $hostname, Configuration $config) + public function __construct(string $hostname, IConfiguration $config) { if (!class_exists('Redis', false)) { throw new Exception('Redis class isn\'t available'); diff --git a/src/Core/Config/Configuration.php b/src/Core/Config/Configuration.php index c54fbb27e7..9094441bf6 100644 --- a/src/Core/Config/Configuration.php +++ b/src/Core/Config/Configuration.php @@ -10,7 +10,7 @@ use Friendica\Model; * - The Config-Files (loaded into the FileCache @see Cache\ConfigCache) * - The Config-DB-Table (per Config-DB-model @see Model\Config\Config) */ -abstract class Configuration +abstract class Configuration implements IConfiguration { /** * @var Cache\ConfigCache @@ -33,68 +33,10 @@ abstract class Configuration } /** - * Returns the Config Cache - * - * @return Cache\ConfigCache + * {@inheritDoc} */ public function getCache() { return $this->configCache; } - - /** - * @brief Loads all configuration values of family into a cached storage. - * - * All configuration values of the system are stored in the cache ( @see ConfigCache ) - * - * @param string $cat The category of the configuration value - * - * @return void - */ - abstract public function load(string $cat = 'config'); - - /** - * @brief Get a particular user's config variable given the category name - * ($cat) and a $key. - * - * Get a particular config value from the given category ($cat) - * and the $key from a cached storage either from the $this->configAdapter - * (@see IConfigAdapter) or from the $this->configCache (@see ConfigCache). - * - * @param string $cat The category of the configuration value - * @param string $key The configuration key to query - * @param mixed $default_value optional, The value to return if key is not set (default: null) - * @param boolean $refresh optional, If true the config is loaded from the db and not from the cache (default: false) - * - * @return mixed Stored value or null if it does not exist - */ - abstract public function get(string $cat, string $key, $default_value = null, bool $refresh = false); - - /** - * @brief Sets a configuration value for system config - * - * Stores a config value ($value) in the category ($cat) under the key ($key) - * - * Note: Please do not store booleans - convert to 0/1 integer values! - * - * @param string $cat The category of the configuration value - * @param string $key The configuration key to set - * @param mixed $value The value to store - * - * @return bool Operation success - */ - abstract public function set(string $cat, string $key, $value); - - /** - * @brief Deletes the given key from the system configuration. - * - * Removes the configured value from the stored cache in $this->configCache - * (@see ConfigCache) and removes it from the database (@see IConfigAdapter). - * - * @param string $cat The category of the configuration value - * @param string $key The configuration key to delete - * - * @return bool - */ - abstract public function delete(string $cat, string $key); } diff --git a/src/Core/Config/IConfiguration.php b/src/Core/Config/IConfiguration.php new file mode 100644 index 0000000000..4bd44f0999 --- /dev/null +++ b/src/Core/Config/IConfiguration.php @@ -0,0 +1,73 @@ +configAdapter + * (@see IConfigAdapter) or from the $this->configCache (@see ConfigCache). + * + * @param string $cat The category of the configuration value + * @param string $key The configuration key to query + * @param mixed $default_value optional, The value to return if key is not set (default: null) + * @param boolean $refresh optional, If true the config is loaded from the db and not from the cache (default: false) + * + * @return mixed Stored value or null if it does not exist + */ + function get(string $cat, string $key, $default_value = null, bool $refresh = false); + + /** + * @brief Sets a configuration value for system config + * + * Stores a config value ($value) in the category ($cat) under the key ($key) + * + * Note: Please do not store booleans - convert to 0/1 integer values! + * + * @param string $cat The category of the configuration value + * @param string $key The configuration key to set + * @param mixed $value The value to store + * + * @return bool Operation success + */ + function set(string $cat, string $key, $value); + + /** + * @brief Deletes the given key from the system configuration. + * + * Removes the configured value from the stored cache in $this->configCache + * (@see ConfigCache) and removes it from the database (@see IConfigAdapter). + * + * @param string $cat The category of the configuration value + * @param string $key The configuration key to delete + * + * @return bool + */ + function delete(string $cat, string $key); + + /** + * Returns the Config Cache + * + * @return Cache\ConfigCache + */ + function getCache(); +} diff --git a/src/Core/Config/IPConfiguration.php b/src/Core/Config/IPConfiguration.php new file mode 100644 index 0000000000..23d75ebc62 --- /dev/null +++ b/src/Core/Config/IPConfiguration.php @@ -0,0 +1,82 @@ +configAdapter + * (@see IConfigAdapter) or from the $this->configCache (@see PConfigCache). + * + * @param int $uid The user_id + * @param string $cat The category of the configuration value + * @param string $key The configuration key to query + * @param mixed $default_value optional, The value to return if key is not set (default: null) + * @param boolean $refresh optional, If true the config is loaded from the db and not from the cache (default: false) + * + * @return mixed Stored value or null if it does not exist + */ + function get(int $uid, string $cat, string $key, $default_value = null, bool $refresh = false); + + /** + * Sets a configuration value for a user + * + * Stores a config value ($value) in the category ($family) under the key ($key) + * for the user_id $uid. + * + * @note Please do not store booleans - convert to 0/1 integer values! + * + * @param int $uid The user_id + * @param string $cat The category of the configuration value + * @param string $key The configuration key to set + * @param mixed $value The value to store + * + * @return bool Operation success + */ + function set(int $uid, string $cat, string $key, $value); + + /** + * Deletes the given key from the users's configuration. + * + * Removes the configured value from the stored cache in $this->configCache + * (@see ConfigCache) and removes it from the database (@see IConfigAdapter) + * with the given $uid. + * + * @param int $uid The user_id + * @param string $cat The category of the configuration value + * @param string $key The configuration key to delete + * + * @return bool + */ + function delete(int $uid, string $cat, string $key); + + + /** + * Returns the Config Cache + * + * @return Cache\PConfigCache + */ + function getCache(); +} diff --git a/src/Core/Config/PConfiguration.php b/src/Core/Config/PConfiguration.php index c54fc31220..ee90be3225 100644 --- a/src/Core/Config/PConfiguration.php +++ b/src/Core/Config/PConfiguration.php @@ -11,7 +11,7 @@ use Friendica\Model; * The configuration cache (@see Cache\PConfigCache) is used for temporary caching of database calls. This will * increase the performance. */ -abstract class PConfiguration +abstract class PConfiguration implements IPConfiguration { /** * @var Cache\PConfigCache @@ -42,68 +42,4 @@ abstract class PConfiguration { return $this->configCache; } - - /** - * Loads all configuration values of a user's config family into a cached storage. - * - * All configuration values of the given user are stored with the $uid in the cache - * - * @param int $uid The user_id - * @param string $cat The category of the configuration value - * - * @return void - * @see PConfigCache - * - */ - abstract public function load(int $uid, string $cat = 'config'); - - /** - * Get a particular user's config variable given the category name - * ($cat) and a key. - * - * Get a particular user's config value from the given category ($cat) - * and the $key with the $uid from a cached storage either from the $this->configAdapter - * (@see IConfigAdapter) or from the $this->configCache (@see PConfigCache). - * - * @param int $uid The user_id - * @param string $cat The category of the configuration value - * @param string $key The configuration key to query - * @param mixed $default_value optional, The value to return if key is not set (default: null) - * @param boolean $refresh optional, If true the config is loaded from the db and not from the cache (default: false) - * - * @return mixed Stored value or null if it does not exist - */ - abstract public function get(int $uid, string $cat, string $key, $default_value = null, bool $refresh = false); - - /** - * Sets a configuration value for a user - * - * Stores a config value ($value) in the category ($family) under the key ($key) - * for the user_id $uid. - * - * @note Please do not store booleans - convert to 0/1 integer values! - * - * @param int $uid The user_id - * @param string $cat The category of the configuration value - * @param string $key The configuration key to set - * @param mixed $value The value to store - * - * @return bool Operation success - */ - abstract public function set(int $uid, string $cat, string $key, $value); - - /** - * Deletes the given key from the users's configuration. - * - * Removes the configured value from the stored cache in $this->configCache - * (@see ConfigCache) and removes it from the database (@see IConfigAdapter) - * with the given $uid. - * - * @param int $uid The user_id - * @param string $cat The category of the configuration value - * @param string $key The configuration key to delete - * - * @return bool - */ - abstract public function delete(int $uid, string $cat, string $key); } diff --git a/src/Core/L10n/L10n.php b/src/Core/L10n/L10n.php index ad4f653716..8b2238c7ae 100644 --- a/src/Core/L10n/L10n.php +++ b/src/Core/L10n/L10n.php @@ -2,7 +2,7 @@ namespace Friendica\Core\L10n; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; use Friendica\Core\Hook; use Friendica\Core\Session\ISession; use Friendica\Database\Database; @@ -41,7 +41,7 @@ class L10n */ private $logger; - public function __construct(Configuration $config, Database $dba, LoggerInterface $logger, ISession $session, array $server, array $get) + public function __construct(IConfiguration $config, Database $dba, LoggerInterface $logger, ISession $session, array $server, array $get) { $this->dba = $dba; $this->logger = $logger; diff --git a/src/Core/Process.php b/src/Core/Process.php index 035f4bf0af..a7f8de2866 100644 --- a/src/Core/Process.php +++ b/src/Core/Process.php @@ -3,7 +3,7 @@ namespace Friendica\Core; use Friendica\App; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; use Psr\Log\LoggerInterface; /** @@ -28,7 +28,7 @@ final class Process private $mode; /** - * @var Configuration + * @var IConfiguration */ private $config; @@ -37,7 +37,7 @@ final class Process */ private $basePath; - public function __construct(LoggerInterface $logger, App\Mode $mode, Configuration $config, string $basepath) + public function __construct(LoggerInterface $logger, App\Mode $mode, IConfiguration $config, string $basepath) { $this->logger = $logger; $this->mode = $mode; diff --git a/src/DI.php b/src/DI.php index c3f6d07f9c..09969f29a9 100644 --- a/src/DI.php +++ b/src/DI.php @@ -4,8 +4,8 @@ namespace Friendica; use Dice\Dice; use Friendica\Core\Cache\ICache; -use Friendica\Core\Config\Configuration; -use Friendica\Core\Config\PConfiguration; +use Friendica\Core\Config\IConfiguration; +use Friendica\Core\Config\IPConfiguration; use Friendica\Core\L10n\L10n; use Friendica\Core\Lock\ILock; use Friendica\Core\Process; @@ -34,8 +34,8 @@ use Psr\Log\LoggerInterface; * @method static Content\Text\BBCode\Video bbCodeVideo() * @method static DateTimeFormat dtFormat() * @method static ICache cache() - * @method static Configuration config() - * @method static PConfiguration pConfig() + * @method static IConfiguration config() + * @method static IPConfiguration pConfig() * @method static ILock lock() * @method static L10n l10n() * @method static LoggerInterface logger() @@ -73,8 +73,8 @@ class DI 'bbCodeVideo' => Content\Text\BBCode\Video::class, 'dtFormat' => DateTimeFormat::class, 'cache' => ICache::class, - 'config' => Configuration::class, - 'pConfig' => PConfiguration::class, + 'config' => IConfiguration::class, + 'pConfig' => IPConfiguration::class, 'l10n' => L10n::class, 'lock' => ILock::class, 'logger' => LoggerInterface::class, diff --git a/src/Factory/CacheFactory.php b/src/Factory/CacheFactory.php index 39b0b94ff7..4e4fc67915 100644 --- a/src/Factory/CacheFactory.php +++ b/src/Factory/CacheFactory.php @@ -5,7 +5,7 @@ namespace Friendica\Factory; use Friendica\App\BaseURL; use Friendica\Core\Cache; use Friendica\Core\Cache\ICache; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; use Friendica\Database\Database; use Friendica\Util\Profiler; use Psr\Log\LoggerInterface; @@ -25,7 +25,7 @@ class CacheFactory const DEFAULT_TYPE = Cache\Cache::TYPE_DATABASE; /** - * @var Configuration The configuration to read parameters out of the config + * @var IConfiguration The IConfiguration to read parameters out of the config */ private $config; @@ -49,7 +49,7 @@ class CacheFactory */ private $logger; - public function __construct(BaseURL $baseURL, Configuration $config, Database $dba, Profiler $profiler, LoggerInterface $logger) + public function __construct(BaseURL $baseURL, IConfiguration $config, Database $dba, Profiler $profiler, LoggerInterface $logger) { $this->hostname = $baseURL->getHostname(); $this->config = $config; diff --git a/src/Factory/ConfigFactory.php b/src/Factory/ConfigFactory.php index 494a5c7209..ecec1e2a73 100644 --- a/src/Factory/ConfigFactory.php +++ b/src/Factory/ConfigFactory.php @@ -27,7 +27,7 @@ class ConfigFactory * @param Cache\ConfigCache $configCache The config cache of this adapter * @param ConfigModel $configModel The configuration model * - * @return Config\Configuration + * @return Config\IConfiguration */ public function createConfig(Cache\ConfigCache $configCache, ConfigModel $configModel) { @@ -46,7 +46,7 @@ class ConfigFactory * @param Cache\PConfigCache $pConfigCache The personal config cache * @param PConfigModel $configModel The configuration model * - * @return Config\PConfiguration + * @return Config\IPConfiguration */ public function createPConfig(Cache\ConfigCache $configCache, Cache\PConfigCache $pConfigCache, PConfigModel $configModel) { diff --git a/src/Factory/LockFactory.php b/src/Factory/LockFactory.php index cee01fe1e9..a7e9bf429b 100644 --- a/src/Factory/LockFactory.php +++ b/src/Factory/LockFactory.php @@ -4,7 +4,7 @@ namespace Friendica\Factory; use Friendica\Core\Cache\Cache; use Friendica\Core\Cache\IMemoryCache; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; use Friendica\Core\Lock; use Friendica\Database\Database; use Psr\Log\LoggerInterface; @@ -24,7 +24,7 @@ class LockFactory const DEFAULT_DRIVER = 'default'; /** - * @var Configuration The configuration to read parameters out of the config + * @var IConfiguration The configuration to read parameters out of the config */ private $config; @@ -43,7 +43,7 @@ class LockFactory */ private $logger; - public function __construct(CacheFactory $cacheFactory, Configuration $config, Database $dba, LoggerInterface $logger) + public function __construct(CacheFactory $cacheFactory, IConfiguration $config, Database $dba, LoggerInterface $logger) { $this->cacheFactory = $cacheFactory; $this->config = $config; diff --git a/src/Factory/LoggerFactory.php b/src/Factory/LoggerFactory.php index f21fe9b7f5..0dae19a250 100644 --- a/src/Factory/LoggerFactory.php +++ b/src/Factory/LoggerFactory.php @@ -2,7 +2,7 @@ namespace Friendica\Factory; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; use Friendica\Core\Logger; use Friendica\Database\Database; use Friendica\Network\HTTPException\InternalServerErrorException; @@ -50,13 +50,13 @@ class LoggerFactory * Creates a new PSR-3 compliant logger instances * * @param Database $database The Friendica Database instance - * @param Configuration $config The config + * @param IConfiguration $config The config * @param Profiler $profiler The profiler of the app * @param FileSystem $fileSystem FileSystem utils * * @return LoggerInterface The PSR-3 compliant logger instance */ - public function create(Database $database, Configuration $config, Profiler $profiler, FileSystem $fileSystem) + public function create(Database $database, IConfiguration $config, Profiler $profiler, FileSystem $fileSystem) { if (empty($config->get('system', 'debugging', false))) { $logger = new VoidLogger(); @@ -137,7 +137,7 @@ class LoggerFactory * * It should never get filled during normal usage of Friendica * - * @param Configuration $config The config + * @param IConfiguration $config The config * @param Profiler $profiler The profiler of the app * @param FileSystem $fileSystem FileSystem utils * @@ -146,7 +146,7 @@ class LoggerFactory * @throws InternalServerErrorException * @throws \Exception */ - public static function createDev(Configuration $config, Profiler $profiler, FileSystem $fileSystem) + public static function createDev(IConfiguration $config, Profiler $profiler, FileSystem $fileSystem) { $debugging = $config->get('system', 'debugging'); $stream = $config->get('system', 'dlogfile'); diff --git a/src/Factory/SessionFactory.php b/src/Factory/SessionFactory.php index eb2371d452..c03f429dc9 100644 --- a/src/Factory/SessionFactory.php +++ b/src/Factory/SessionFactory.php @@ -5,7 +5,7 @@ namespace Friendica\Factory; use Friendica\App; use Friendica\Core\Cache\Cache; use Friendica\Core\Cache\ICache; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Database\Database; @@ -29,7 +29,8 @@ class SessionFactory /** * @param App\Mode $mode * @param App\BaseURL $baseURL - * @param Configuration $config + * @param IConfiguration $config + * @param Cookie $cookie * @param Database $dba * @param ICache $cache * @param LoggerInterface $logger @@ -37,7 +38,7 @@ class SessionFactory * * @return Session\ISession */ - public function createSession(App\Mode $mode, App\BaseURL $baseURL, Configuration $config, Database $dba, ICache $cache, LoggerInterface $logger, Profiler $profiler, array $server = []) + public function createSession(App\Mode $mode, App\BaseURL $baseURL, IConfiguration $config, Database $dba, ICache $cache, LoggerInterface $logger, Profiler $profiler, array $server = []) { $stamp1 = microtime(true); $session = null; diff --git a/src/Model/Notify.php b/src/Model/Notify.php index 160d261b16..10ece48e2d 100644 --- a/src/Model/Notify.php +++ b/src/Model/Notify.php @@ -6,7 +6,7 @@ use Exception; use Friendica\App; use Friendica\Content\Text\BBCode; use Friendica\Content\Text\HTML; -use Friendica\Core\Config\PConfiguration; +use Friendica\Core\Config\IPConfiguration; use Friendica\Core\L10n\L10n; use Friendica\Core\Protocol; use Friendica\Core\System; @@ -71,13 +71,13 @@ final class Notify private $args; /** @var App\BaseURL */ private $baseUrl; - /** @var PConfiguration */ + /** @var IPConfiguration */ private $pConfig; /** @var LoggerInterface */ private $logger; public function __construct(Database $dba, L10n $l10n, App\Arguments $args, App\BaseURL $baseUrl, - PConfiguration $pConfig, LoggerInterface $logger) + IPConfiguration $pConfig, LoggerInterface $logger) { $this->dba = $dba; $this->l10n = $l10n; diff --git a/src/Model/User/Cookie.php b/src/Model/User/Cookie.php index 0fc90222f1..e065d33e2e 100644 --- a/src/Model/User/Cookie.php +++ b/src/Model/User/Cookie.php @@ -3,7 +3,7 @@ namespace Friendica\Model\User; use Friendica\App; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; /** * Interacting with the Friendica Cookie of a user @@ -32,7 +32,7 @@ class Cookie /** @var array The $_COOKIE array */ private $cookie; - public function __construct(Configuration $config, App\BaseURL $baseURL, array $server = [], array $cookie = []) + public function __construct(IConfiguration $config, App\BaseURL $baseURL, array $server = [], array $cookie = []) { if (!empty($server['REMOTE_ADDR'])) { $this->remoteAddr = $server['REMOTE_ADDR']; diff --git a/src/Module/Diaspora/Receive.php b/src/Module/Diaspora/Receive.php index 4b6bb2a52e..dbfb7f549f 100644 --- a/src/Module/Diaspora/Receive.php +++ b/src/Module/Diaspora/Receive.php @@ -2,10 +2,7 @@ namespace Friendica\Module\Diaspora; -use Friendica\App; use Friendica\BaseModule; -use Friendica\Core\Config\Configuration; -use Friendica\Core\L10n\L10n; use Friendica\DI; use Friendica\Model\User; use Friendica\Network\HTTPException; diff --git a/src/Util/Profiler.php b/src/Util/Profiler.php index e745a8bbdf..d166210e33 100644 --- a/src/Util/Profiler.php +++ b/src/Util/Profiler.php @@ -3,7 +3,7 @@ namespace Friendica\Util; use Friendica\Core\Config\Cache\ConfigCache; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; @@ -47,9 +47,9 @@ class Profiler implements ContainerInterface /** * Updates the enabling of the current profiler * - * @param Configuration $config + * @param IConfiguration $config */ - public function update(Configuration $config) + public function update(IConfiguration $config) { $this->enabled = $config->get('system', 'profiler'); $this->rendertime = $config->get('rendertime', 'callstack'); diff --git a/static/dependencies.config.php b/static/dependencies.config.php index ea9830679f..512d0e7a2c 100644 --- a/static/dependencies.config.php +++ b/static/dependencies.config.php @@ -68,13 +68,13 @@ return [ ['determine', [], Dice::CHAIN_CALL], ], ], - Config\Configuration::class => [ + Config\IConfiguration::class => [ 'instanceOf' => Factory\ConfigFactory::class, 'call' => [ ['createConfig', [], Dice::CHAIN_CALL], ], ], - Config\PConfiguration::class => [ + Config\IPConfiguration::class => [ 'instanceOf' => Factory\ConfigFactory::class, 'call' => [ ['createPConfig', [], Dice::CHAIN_CALL], diff --git a/tests/Util/AppMockTrait.php b/tests/Util/AppMockTrait.php index f9a9cb25de..7948f09f60 100644 --- a/tests/Util/AppMockTrait.php +++ b/tests/Util/AppMockTrait.php @@ -22,7 +22,7 @@ trait AppMockTrait protected $app; /** - * @var MockInterface|Config\Configuration The mocked Config Cache + * @var MockInterface|Config\IConfiguration The mocked Config Cache */ protected $configMock; @@ -54,11 +54,11 @@ trait AppMockTrait $this->configMock = \Mockery::mock(Config\Cache\ConfigCache::class); $this->dice->shouldReceive('create') - ->with(Config\Cache\ConfigCache::class) + ->with(Config\Cache\ConfigCache::class, []) ->andReturn($this->configMock); $this->mode = \Mockery::mock(App\Mode::class); $this->dice->shouldReceive('create') - ->with(App\Mode::class) + ->with(App\Mode::class, []) ->andReturn($this->mode); $configModel= \Mockery::mock(\Friendica\Model\Config\Config::class); // Disable the adapter @@ -66,13 +66,13 @@ trait AppMockTrait $config = new Config\JitConfiguration($this->configMock, $configModel); $this->dice->shouldReceive('create') - ->with(Config\Configuration::class) + ->with(Config\IConfiguration::class, []) ->andReturn($config); // Mocking App and most used functions $this->app = \Mockery::mock(App::class); $this->dice->shouldReceive('create') - ->with(App::class) + ->with(App::class, []) ->andReturn($this->app); $this->app ->shouldReceive('getBasePath') @@ -85,7 +85,7 @@ trait AppMockTrait $this->profilerMock = \Mockery::mock(Profiler::class); $this->profilerMock->shouldReceive('saveTimestamp'); $this->dice->shouldReceive('create') - ->with(Profiler::class) + ->with(Profiler::class, []) ->andReturn($this->profilerMock); $this->app diff --git a/tests/bootstrap.php b/tests/bootstrap.php index a839dbed73..8b4b8ade1e 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -3,9 +3,16 @@ * This file is loaded by PHPUnit before any test. */ +use Dice\Dice; +use Friendica\DI; use PHPUnit\Framework\TestCase; // Backward compatibility if (!class_exists(TestCase::class)) { class_alias(PHPUnit_Framework_TestCase::class, TestCase::class); } + +$dice = new Dice(); +$dice = $dice->addRules(include __DIR__ . '/../static/dependencies.config.php'); + +DI::init($dice); diff --git a/tests/functional/DependencyCheckTest.php b/tests/functional/DependencyCheckTest.php index 336a34c344..4e05845f29 100644 --- a/tests/functional/DependencyCheckTest.php +++ b/tests/functional/DependencyCheckTest.php @@ -7,7 +7,7 @@ use Friendica\App; use Friendica\Core\Cache\ICache; use Friendica\Core\Cache\IMemoryCache; use Friendica\Core\Config\Cache\ConfigCache; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; use Friendica\Core\Lock\ILock; use Friendica\Database\Database; use Friendica\Test\Util\VFSTrait; @@ -115,10 +115,10 @@ class dependencyCheck extends TestCase public function testConfiguration() { - /** @var Configuration $config */ - $config = $this->dice->create(Configuration::class); + /** @var IConfiguration $config */ + $config = $this->dice->create(IConfiguration::class); - $this->assertInstanceOf(Configuration::class, $config); + $this->assertInstanceOf(IConfiguration::class, $config); $this->assertNotEmpty($config->get('database', 'username')); } @@ -133,8 +133,8 @@ class dependencyCheck extends TestCase public function testDevLogger() { - /** @var Configuration $config */ - $config = $this->dice->create(Configuration::class); + /** @var IConfiguration $config */ + $config = $this->dice->create(IConfiguration::class); $config->set('system', 'dlogfile', $this->root->url() . '/friendica.log'); /** @var LoggerInterface $logger */ diff --git a/tests/include/ApiTest.php b/tests/include/ApiTest.php index 74c220d849..8fce36955d 100644 --- a/tests/include/ApiTest.php +++ b/tests/include/ApiTest.php @@ -7,8 +7,8 @@ namespace Friendica\Test; use Dice\Dice; use Friendica\App; -use Friendica\Core\Config\Configuration; -use Friendica\Core\Config\PConfiguration; +use Friendica\Core\Config\IConfiguration; +use Friendica\Core\Config\IPConfiguration; use Friendica\Core\Protocol; use Friendica\Core\Session; use Friendica\Core\Session\ISession; @@ -47,7 +47,7 @@ class ApiTest extends DatabaseTest /** @var App */ protected $app; - /** @var Configuration */ + /** @var IConfiguration */ protected $config; /** @var Dice */ @@ -69,8 +69,8 @@ class ApiTest extends DatabaseTest /** @var Database $dba */ $dba = $this->dice->create(Database::class); - /** @var Configuration $config */ - $this->config = $this->dice->create(Configuration::class); + /** @var IConfiguration $config */ + $this->config = $this->dice->create(IConfiguration::class); $this->config->set('system', 'url', 'http://localhost'); $this->config->set('system', 'hostname', 'localhost'); @@ -827,7 +827,7 @@ class ApiTest extends DatabaseTest */ public function testApiGetUserWithFrioSchema() { - $pConfig = $this->dice->create(PConfiguration::class); + $pConfig = $this->dice->create(IPConfiguration::class); $pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red'); $user = api_get_user($this->app); $this->assertSelfUser($user); @@ -843,7 +843,7 @@ class ApiTest extends DatabaseTest */ public function testApiGetUserWithCustomFrioSchema() { - $pConfig = $this->dice->create(PConfiguration::class); + $pConfig = $this->dice->create(IPConfiguration::class); $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---'); $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456'); $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456'); @@ -862,7 +862,7 @@ class ApiTest extends DatabaseTest */ public function testApiGetUserWithEmptyFrioSchema() { - $pConfig = $this->dice->create(PConfiguration::class); + $pConfig = $this->dice->create(IPConfiguration::class); $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---'); $user = api_get_user($this->app); $this->assertSelfUser($user); diff --git a/tests/phpunit-local.xml b/tests/phpunit-local.xml new file mode 100644 index 0000000000..7bf174aba9 --- /dev/null +++ b/tests/phpunit-local.xml @@ -0,0 +1,26 @@ + + + + functional/ + include/ + src/ + ./ + + + + + .. + + config/ + doc/ + images/ + library/ + spec/ + tests/ + view/ + + + + diff --git a/tests/src/App/ModuleTest.php b/tests/src/App/ModuleTest.php index ce2a40b806..f1ac6bb92e 100644 --- a/tests/src/App/ModuleTest.php +++ b/tests/src/App/ModuleTest.php @@ -3,7 +3,7 @@ namespace Friendica\Test\src\App; use Friendica\App; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; use Friendica\LegacyModule; use Friendica\Module\HTTPException\PageNotFound; use Friendica\Module\WellKnown\HostMeta; @@ -149,7 +149,7 @@ class ModuleTest extends DatabaseTest */ public function testModuleClass($assert, string $name, string $command, bool $privAdd) { - $config = \Mockery::mock(Configuration::class); + $config = \Mockery::mock(IConfiguration::class); $config->shouldReceive('get')->with('config', 'private_addons', false)->andReturn($privAdd)->atMost()->once(); $router = (new App\Router([]))->loadRoutes(include __DIR__ . '/../../../static/routes.config.php'); diff --git a/tests/src/Console/ConfigConsoleTest.php b/tests/src/Console/ConfigConsoleTest.php index e4206af414..51342bf169 100644 --- a/tests/src/Console/ConfigConsoleTest.php +++ b/tests/src/Console/ConfigConsoleTest.php @@ -5,7 +5,7 @@ namespace Friendica\Test\src\Console; use Friendica\App; use Friendica\App\Mode; use Friendica\Console\Config; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; use Mockery\MockInterface; class ConfigConsoleTest extends ConsoleTest @@ -29,7 +29,7 @@ class ConfigConsoleTest extends ConsoleTest $this->appMode->shouldReceive('has') ->andReturn(true); - $this->configMock = \Mockery::mock(Configuration::class); + $this->configMock = \Mockery::mock(IConfiguration::class); } function testSetGetKeyValue() diff --git a/tests/src/Console/ServerBlockConsoleTest.php b/tests/src/Console/ServerBlockConsoleTest.php index d671020e6f..ef6cc0dacb 100644 --- a/tests/src/Console/ServerBlockConsoleTest.php +++ b/tests/src/Console/ServerBlockConsoleTest.php @@ -3,7 +3,7 @@ namespace Friendica\Test\src\Console; use Friendica\Console\ServerBlock; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; class ServerBlockConsoleTest extends ConsoleTest { @@ -22,7 +22,7 @@ class ServerBlockConsoleTest extends ConsoleTest { parent::setUp(); - $this->configMock = \Mockery::mock(Configuration::class); + $this->configMock = \Mockery::mock(IConfiguration::class); } /** diff --git a/tests/src/Content/Text/BBCodeTest.php b/tests/src/Content/Text/BBCodeTest.php index ed33306edf..52d01401e6 100644 --- a/tests/src/Content/Text/BBCodeTest.php +++ b/tests/src/Content/Text/BBCodeTest.php @@ -43,13 +43,13 @@ class BBCodeTest extends MockedTest $l10nMock = \Mockery::mock(L10n::class); $l10nMock->shouldReceive('t')->withAnyArgs()->andReturnUsing(function ($args) { return $args; }); $this->dice->shouldReceive('create') - ->with(L10n::class) + ->with(L10n::class, []) ->andReturn($l10nMock); $baseUrlMock = \Mockery::mock(BaseURL::class); $baseUrlMock->shouldReceive('get')->withAnyArgs()->andReturn('friendica.local'); $this->dice->shouldReceive('create') - ->with(BaseURL::class) + ->with(BaseURL::class, []) ->andReturn($baseUrlMock); } diff --git a/tests/src/Core/Cache/MemcacheCacheTest.php b/tests/src/Core/Cache/MemcacheCacheTest.php index 2865effb17..be7946717e 100644 --- a/tests/src/Core/Cache/MemcacheCacheTest.php +++ b/tests/src/Core/Cache/MemcacheCacheTest.php @@ -3,7 +3,7 @@ namespace Friendica\Test\src\Core\Cache; use Friendica\Core\Cache\MemcacheCache; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; /** * @requires extension memcache @@ -13,7 +13,7 @@ class MemcacheCacheTest extends MemoryCacheTest { protected function getInstance() { - $configMock = \Mockery::mock(Configuration::class); + $configMock = \Mockery::mock(IConfiguration::class); $host = $_SERVER['MEMCACHE_HOST'] ?? 'localhost'; diff --git a/tests/src/Core/Cache/MemcachedCacheTest.php b/tests/src/Core/Cache/MemcachedCacheTest.php index c9eb02be6e..addbde6275 100644 --- a/tests/src/Core/Cache/MemcachedCacheTest.php +++ b/tests/src/Core/Cache/MemcachedCacheTest.php @@ -4,7 +4,7 @@ namespace Friendica\Test\src\Core\Cache; use Friendica\Core\Cache\MemcachedCache; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; use Psr\Log\NullLogger; /** @@ -15,7 +15,7 @@ class MemcachedCacheTest extends MemoryCacheTest { protected function getInstance() { - $configMock = \Mockery::mock(Configuration::class); + $configMock = \Mockery::mock(IConfiguration::class); $host = $_SERVER['MEMCACHED_HOST'] ?? 'localhost'; diff --git a/tests/src/Core/Cache/RedisCacheTest.php b/tests/src/Core/Cache/RedisCacheTest.php index 75891cd1b8..53c2ecc833 100644 --- a/tests/src/Core/Cache/RedisCacheTest.php +++ b/tests/src/Core/Cache/RedisCacheTest.php @@ -4,7 +4,7 @@ namespace Friendica\Test\src\Core\Cache; use Friendica\Core\Cache\RedisCache; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; /** * @requires extension redis @@ -14,7 +14,7 @@ class RedisCacheTest extends MemoryCacheTest { protected function getInstance() { - $configMock = \Mockery::mock(Configuration::class); + $configMock = \Mockery::mock(IConfiguration::class); $host = $_SERVER['REDIS_HOST'] ?? 'localhost'; diff --git a/tests/src/Core/Config/ConfigurationTest.php b/tests/src/Core/Config/ConfigurationTest.php index 2191d86f1c..15c96ca936 100644 --- a/tests/src/Core/Config/ConfigurationTest.php +++ b/tests/src/Core/Config/ConfigurationTest.php @@ -3,8 +3,7 @@ namespace Friendica\Test\src\Core\Config; use Friendica\Core\Config\Cache\ConfigCache; -use Friendica\Core\Config\Configuration; -use Friendica\Core\Config\JitConfiguration; +use Friendica\Core\Config\IConfiguration; use Friendica\Model\Config\Config as ConfigModel; use Friendica\Test\MockedTest; use Mockery\MockInterface; @@ -18,7 +17,7 @@ abstract class ConfigurationTest extends MockedTest /** @var ConfigCache */ protected $configCache; - /** @var Configuration */ + /** @var IConfiguration */ protected $testedConfig; /** @@ -47,7 +46,7 @@ abstract class ConfigurationTest extends MockedTest } /** - * @return Configuration + * @return IConfiguration */ public abstract function getInstance(); diff --git a/tests/src/Core/InstallerTest.php b/tests/src/Core/InstallerTest.php index b2ef92b450..674195c128 100644 --- a/tests/src/Core/InstallerTest.php +++ b/tests/src/Core/InstallerTest.php @@ -34,7 +34,7 @@ class InstallerTest extends MockedTest $dice = $dice->addRules(include __DIR__ . '/../../../static/dependencies.config.php'); $dice->shouldReceive('create') - ->with(\Friendica\Core\L10n\L10n::class) + ->with(\Friendica\Core\L10n\L10n::class, []) ->andReturn($this->l10nMock); DI::init($dice); @@ -362,7 +362,7 @@ class InstallerTest extends MockedTest $this->assertTrue($install->checkImagick()); $this->assertCheckExist(1, - L10n::t('ImageMagick supports GIF'), + $this->l10nMock->t('ImageMagick supports GIF'), '', true, false, @@ -385,9 +385,9 @@ class InstallerTest extends MockedTest // even there is no supported type, Imagick should return true (because it is not required) $this->assertTrue($install->checkImagick()); $this->assertCheckExist(1, - L10n::t('ImageMagick supports GIF'), + $this->l10nMock->t('ImageMagick supports GIF'), '', - false, + true, false, $install->getChecks()); } diff --git a/tests/src/Core/Lock/MemcacheCacheLockTest.php b/tests/src/Core/Lock/MemcacheCacheLockTest.php index e66c4725c1..9e111fbb92 100644 --- a/tests/src/Core/Lock/MemcacheCacheLockTest.php +++ b/tests/src/Core/Lock/MemcacheCacheLockTest.php @@ -4,7 +4,7 @@ namespace Friendica\Test\src\Core\Lock; use Friendica\Core\Cache\MemcacheCache; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; use Friendica\Core\Lock\CacheLock; /** @@ -15,7 +15,7 @@ class MemcacheCacheLockTest extends LockTest { protected function getInstance() { - $configMock = \Mockery::mock(Configuration::class); + $configMock = \Mockery::mock(IConfiguration::class); $host = $_SERVER['MEMCACHE_HOST'] ?? 'localhost'; diff --git a/tests/src/Core/Lock/MemcachedCacheLockTest.php b/tests/src/Core/Lock/MemcachedCacheLockTest.php index c217b47f59..41b16abc7f 100644 --- a/tests/src/Core/Lock/MemcachedCacheLockTest.php +++ b/tests/src/Core/Lock/MemcachedCacheLockTest.php @@ -4,7 +4,7 @@ namespace Friendica\Test\src\Core\Lock; use Friendica\Core\Cache\MemcachedCache; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; use Friendica\Core\Lock\CacheLock; use Psr\Log\NullLogger; @@ -16,7 +16,7 @@ class MemcachedCacheLockTest extends LockTest { protected function getInstance() { - $configMock = \Mockery::mock(Configuration::class); + $configMock = \Mockery::mock(IConfiguration::class); $host = $_SERVER['MEMCACHED_HOST'] ?? 'localhost'; diff --git a/tests/src/Core/Lock/RedisCacheLockTest.php b/tests/src/Core/Lock/RedisCacheLockTest.php index 95f7206e2c..bfda18b24d 100644 --- a/tests/src/Core/Lock/RedisCacheLockTest.php +++ b/tests/src/Core/Lock/RedisCacheLockTest.php @@ -4,7 +4,7 @@ namespace Friendica\Test\src\Core\Lock; use Friendica\Core\Cache\RedisCache; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; use Friendica\Core\Lock\CacheLock; /** @@ -15,7 +15,7 @@ class RedisCacheLockTest extends LockTest { protected function getInstance() { - $configMock = \Mockery::mock(Configuration::class); + $configMock = \Mockery::mock(IConfiguration::class); $host = $_SERVER['REDIS_HOST'] ?? 'localhost'; diff --git a/tests/src/Core/Lock/SemaphoreLockTest.php b/tests/src/Core/Lock/SemaphoreLockTest.php index 040cdeb521..51d3866fe7 100644 --- a/tests/src/Core/Lock/SemaphoreLockTest.php +++ b/tests/src/Core/Lock/SemaphoreLockTest.php @@ -4,27 +4,29 @@ namespace Friendica\Test\src\Core\Lock; use Dice\Dice; use Friendica\App; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; use Friendica\Core\Config\JitConfiguration; use Friendica\Core\Lock\SemaphoreLock; use Friendica\DI; +use Mockery\MockInterface; class SemaphoreLockTest extends LockTest { public function setUp() { + /** @var MockInterface|Dice $dice */ $dice = \Mockery::mock(Dice::class)->makePartial(); $app = \Mockery::mock(App::class); $app->shouldReceive('getHostname')->andReturn('friendica.local'); - $dice->shouldReceive('create')->with(App::class)->andReturn($app); + $dice->shouldReceive('create')->with(App::class, [])->andReturn($app); $configMock = \Mockery::mock(JitConfiguration::class); $configMock ->shouldReceive('get') ->with('system', 'temppath', NULL, false) ->andReturn('/tmp/'); - $dice->shouldReceive('create')->with(Configuration::class)->andReturn($configMock); + $dice->shouldReceive('create')->with(IConfiguration::class, [])->andReturn($configMock); // @todo Because "get_temppath()" is using static methods, we have to initialize the BaseObject DI::init($dice); diff --git a/tests/src/Model/User/CookieTest.php b/tests/src/Model/User/CookieTest.php index b689fc97c8..f66e5a6ae6 100644 --- a/tests/src/Model/User/CookieTest.php +++ b/tests/src/Model/User/CookieTest.php @@ -3,7 +3,7 @@ namespace Friendica\Testsrc\Model\User; use Friendica\App\BaseURL; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; use Friendica\Model\User\Cookie; use Friendica\Test\DatabaseTest; use Friendica\Test\Util\StaticCookie; @@ -11,7 +11,7 @@ use Mockery\MockInterface; class CookieTest extends DatabaseTest { - /** @var MockInterface|Configuration */ + /** @var MockInterface|IConfiguration */ private $config; /** @var MockInterface|BaseURL */ private $baseUrl; @@ -22,7 +22,7 @@ class CookieTest extends DatabaseTest parent::setUp(); - $this->config = \Mockery::mock(Configuration::class); + $this->config = \Mockery::mock(IConfiguration::class); $this->baseUrl = \Mockery::mock(BaseURL::class); } diff --git a/tests/src/Network/CurlResultTest.php b/tests/src/Network/CurlResultTest.php index 7f2754a0e5..294be6b0b2 100644 --- a/tests/src/Network/CurlResultTest.php +++ b/tests/src/Network/CurlResultTest.php @@ -16,14 +16,13 @@ class CurlResultTest extends TestCase { parent::setUp(); - /** @var Dice|MockInterface $dice */ $dice = \Mockery::mock(Dice::class)->makePartial(); $dice = $dice->addRules(include __DIR__ . '/../../../static/dependencies.config.php'); $logger = new NullLogger(); $dice->shouldReceive('create') - ->with(LoggerInterface::class) + ->with(LoggerInterface::class, []) ->andReturn($logger); DI::init($dice); diff --git a/tests/src/Util/BaseURLTest.php b/tests/src/Util/BaseURLTest.php index 7f63027fcb..47f80f36ea 100644 --- a/tests/src/Util/BaseURLTest.php +++ b/tests/src/Util/BaseURLTest.php @@ -2,7 +2,7 @@ namespace Friendica\Test\src\Util; use Friendica\App\BaseURL; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; use Friendica\Test\MockedTest; class BaseURLTest extends MockedTest @@ -173,7 +173,7 @@ class BaseURLTest extends MockedTest */ public function testCheck($server, $input, $assert) { - $configMock = \Mockery::mock(Configuration::class); + $configMock = \Mockery::mock(IConfiguration::class); $configMock->shouldReceive('get')->with('config', 'hostname')->andReturn($input['hostname']); $configMock->shouldReceive('get')->with('system', 'urlpath')->andReturn($input['urlPath']); $configMock->shouldReceive('get')->with('system', 'ssl_policy')->andReturn($input['sslPolicy']); @@ -295,7 +295,7 @@ class BaseURLTest extends MockedTest */ public function testSave($input, $save, $url) { - $configMock = \Mockery::mock(Configuration::class); + $configMock = \Mockery::mock(IConfiguration::class); $configMock->shouldReceive('get')->with('config', 'hostname')->andReturn($input['hostname']); $configMock->shouldReceive('get')->with('system', 'urlpath')->andReturn($input['urlPath']); $configMock->shouldReceive('get')->with('system', 'ssl_policy')->andReturn($input['sslPolicy']); @@ -333,7 +333,7 @@ class BaseURLTest extends MockedTest */ public function testSaveByUrl($input, $save, $url) { - $configMock = \Mockery::mock(Configuration::class); + $configMock = \Mockery::mock(IConfiguration::class); $configMock->shouldReceive('get')->with('config', 'hostname')->andReturn($input['hostname']); $configMock->shouldReceive('get')->with('system', 'urlpath')->andReturn($input['urlPath']); $configMock->shouldReceive('get')->with('system', 'ssl_policy')->andReturn($input['sslPolicy']); @@ -409,7 +409,7 @@ class BaseURLTest extends MockedTest */ public function testGetURL($sslPolicy, $ssl, $url, $assert) { - $configMock = \Mockery::mock(Configuration::class); + $configMock = \Mockery::mock(IConfiguration::class); $configMock->shouldReceive('get')->with('config', 'hostname')->andReturn('friendica.local'); $configMock->shouldReceive('get')->with('system', 'urlpath')->andReturn('new/test'); $configMock->shouldReceive('get')->with('system', 'ssl_policy')->andReturn($sslPolicy); @@ -467,7 +467,7 @@ class BaseURLTest extends MockedTest */ public function testCheckRedirectHTTPS($server, $forceSSL, $sslPolicy, $url, $redirect) { - $configMock = \Mockery::mock(Configuration::class); + $configMock = \Mockery::mock(IConfiguration::class); $configMock->shouldReceive('get')->with('config', 'hostname')->andReturn('friendica.local'); $configMock->shouldReceive('get')->with('system', 'urlpath')->andReturn('new/test'); $configMock->shouldReceive('get')->with('system', 'ssl_policy')->andReturn($sslPolicy); @@ -503,7 +503,7 @@ class BaseURLTest extends MockedTest */ public function testWrongSave($fail) { - $configMock = \Mockery::mock(Configuration::class); + $configMock = \Mockery::mock(IConfiguration::class); $configMock->shouldReceive('get')->with('config', 'hostname')->andReturn('friendica.local'); $configMock->shouldReceive('get')->with('system', 'urlpath')->andReturn('new/test'); $configMock->shouldReceive('get')->with('system', 'ssl_policy')->andReturn(BaseURL::DEFAULT_SSL_SCHEME); diff --git a/tests/src/Util/ProfilerTest.php b/tests/src/Util/ProfilerTest.php index 0790bc30ac..ba47858a09 100644 --- a/tests/src/Util/ProfilerTest.php +++ b/tests/src/Util/ProfilerTest.php @@ -3,7 +3,7 @@ namespace Friendica\Test\src\Util; use Friendica\Core\Config\Cache\ConfigCache; -use Friendica\Core\Config\Configuration; +use Friendica\Core\Config\IConfiguration; use Friendica\Test\MockedTest; use Friendica\Util\Profiler; use Mockery\MockInterface; @@ -235,7 +235,7 @@ class ProfilerTest extends MockedTest $profiler->saveTimestamp(time(), 'network', 'test1'); - $config = \Mockery::mock(Configuration::class); + $config = \Mockery::mock(IConfiguration::class); $config->shouldReceive('get') ->with('system', 'profiler') ->andReturn(false) From 8a072b7fb33e05f9b9e905fb7946f84cd4e9438e Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Sat, 21 Dec 2019 21:15:16 +0100 Subject: [PATCH 25/34] Fix mock test (remove "implicit" usage of previous Dice-setups) --- tests/src/Core/SystemTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/src/Core/SystemTest.php b/tests/src/Core/SystemTest.php index a385d1b352..af8d2f8f73 100644 --- a/tests/src/Core/SystemTest.php +++ b/tests/src/Core/SystemTest.php @@ -2,11 +2,26 @@ namespace Friendica\Test\src\Core; +use Dice\Dice; +use Friendica\App\BaseURL; use Friendica\Core\System; +use Friendica\DI; use PHPUnit\Framework\TestCase; class SystemTest extends TestCase { + protected function setUp() + { + parent::setUp(); + + $baseUrl = \Mockery::mock(BaseURL::class); + $baseUrl->shouldReceive('getHostname')->andReturn('friendica.local')->once(); + $dice = \Mockery::mock(Dice::class); + $dice->shouldReceive('create')->with(BaseURL::class, [])->andReturn($baseUrl); + + DI::init($dice); + } + private function assertGuid($guid, $length, $prefix = '') { $length -= strlen($prefix); From 9cb48b0e12a61666ad712d9ed6ed46996c70ae45 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Sun, 22 Dec 2019 00:22:43 +0100 Subject: [PATCH 26/34] Adapt test for mockery assertion --- tests/src/Core/SystemTest.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/src/Core/SystemTest.php b/tests/src/Core/SystemTest.php index af8d2f8f73..2f01df3446 100644 --- a/tests/src/Core/SystemTest.php +++ b/tests/src/Core/SystemTest.php @@ -10,10 +10,8 @@ use PHPUnit\Framework\TestCase; class SystemTest extends TestCase { - protected function setUp() + private function useBaseUrl() { - parent::setUp(); - $baseUrl = \Mockery::mock(BaseURL::class); $baseUrl->shouldReceive('getHostname')->andReturn('friendica.local')->once(); $dice = \Mockery::mock(Dice::class); @@ -30,21 +28,27 @@ class SystemTest extends TestCase function testGuidWithoutParameter() { + $this->useBaseUrl(); $guid = System::createGUID(); $this->assertGuid($guid, 16); } - function testGuidWithSize32() { + function testGuidWithSize32() + { + $this->useBaseUrl(); $guid = System::createGUID(32); $this->assertGuid($guid, 32); } - function testGuidWithSize64() { + function testGuidWithSize64() + { + $this->useBaseUrl(); $guid = System::createGUID(64); $this->assertGuid($guid, 64); } - function testGuidWithPrefix() { + function testGuidWithPrefix() + { $guid = System::createGUID(23, 'test'); $this->assertGuid($guid, 23, 'test'); } From e428bccefb1587582515cffd3d14f55c6ae611a2 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Sun, 22 Dec 2019 00:36:29 +0100 Subject: [PATCH 27/34] Add output for installerTest --- tests/src/Core/InstallerTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/src/Core/InstallerTest.php b/tests/src/Core/InstallerTest.php index 674195c128..f787e0ce5a 100644 --- a/tests/src/Core/InstallerTest.php +++ b/tests/src/Core/InstallerTest.php @@ -73,13 +73,15 @@ class InstallerTest extends MockedTest private function assertCheckExist($position, $title, $help, $status, $required, $assertionArray) { - $this->assertArraySubset([$position => [ + $subSet = [$position => [ 'title' => $title, 'status' => $status, 'required' => $required, 'error_msg' => null, 'help' => $help] - ], $assertionArray); + ]; + + $this->assertArraySubset($subSet, $assertionArray, false, "expected subset: " . PHP_EOL . print_r($subSet, true) . PHP_EOL . "current subset: " . print_r($assertionArray, true)); } /** From 04d1827eae5ccf9e83b914a395390a16a4dcd112 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Sun, 22 Dec 2019 13:04:35 +0100 Subject: [PATCH 28/34] Fix test --- tests/src/Core/InstallerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/Core/InstallerTest.php b/tests/src/Core/InstallerTest.php index f787e0ce5a..dd7790e739 100644 --- a/tests/src/Core/InstallerTest.php +++ b/tests/src/Core/InstallerTest.php @@ -389,7 +389,7 @@ class InstallerTest extends MockedTest $this->assertCheckExist(1, $this->l10nMock->t('ImageMagick supports GIF'), '', - true, + false, false, $install->getChecks()); } From 987b29d9638c7339c12c3429c7841082658efda4 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Sun, 22 Dec 2019 20:49:42 +0100 Subject: [PATCH 29/34] Alphabetic sort DI-container per namespace --- src/DI.php | 84 ++++++++++++++++++++++-------------------------------- 1 file changed, 34 insertions(+), 50 deletions(-) diff --git a/src/DI.php b/src/DI.php index 09969f29a9..0ce28f3aef 100644 --- a/src/DI.php +++ b/src/DI.php @@ -3,22 +3,6 @@ namespace Friendica; use Dice\Dice; -use Friendica\Core\Cache\ICache; -use Friendica\Core\Config\IConfiguration; -use Friendica\Core\Config\IPConfiguration; -use Friendica\Core\L10n\L10n; -use Friendica\Core\Lock\ILock; -use Friendica\Core\Process; -use Friendica\Core\Session\ISession; -use Friendica\Database\Database; -use Friendica\Model\Notify; -use Friendica\Protocol\Activity; -use Friendica\Util\ACLFormatter; -use Friendica\Content; -use Friendica\Util\DateTimeFormat; -use Friendica\Util\FileSystem; -use Friendica\Util\Logger\WorkerLogger; -use Friendica\Util\Profiler; use Psr\Log\LoggerInterface; /** @@ -27,22 +11,6 @@ use Psr\Log\LoggerInterface; * There has to be a "method" phpDoc for each new class, containing result class for a proper matching * * @method static App app() - * @method static ACLFormatter aclFormatter() - * @method static Notify notify() - * @method static Activity activity() - * @method static Content\Item contentItem() - * @method static Content\Text\BBCode\Video bbCodeVideo() - * @method static DateTimeFormat dtFormat() - * @method static ICache cache() - * @method static IConfiguration config() - * @method static IPConfiguration pConfig() - * @method static ILock lock() - * @method static L10n l10n() - * @method static LoggerInterface logger() - * @method static LoggerInterface devLogger() - * @method static LoggerInterface workerLogger() - * @method static Profiler profiler() - * @method static ISession session() * @method static App\Authentication auth() * @method static App\Arguments args() * @method static App\BaseURL baseUrl() @@ -50,16 +18,31 @@ use Psr\Log\LoggerInterface; * @method static App\Module module() * @method static App\Page page() * @method static App\Router router() - * @method static Database dba() - * @method static FileSystem fs() - * @method static Process process() + * @method static Content\Item contentItem() + * @method static Content\Text\BBCode\Video bbCodeVideo() + * @method static Core\Cache\ICache cache() + * @method static Core\Config\IConfiguration config() + * @method static Core\Config\IPConfiguration pConfig() + * @method static Core\Lock\ILock lock() + * @method static Core\L10n\L10n l10n() + * @method static Core\Process process() + * @method static Core\Session\ISession session() + * @method static Database\Database dba() + * @method static Model\Notify notify() + * @method static Protocol\Activity activity() + * @method static Util\ACLFormatter aclFormatter() + * @method static Util\DateTimeFormat dtFormat() + * @method static Util\FileSystem fs() + * @method static Util\Profiler profiler() + * @method static LoggerInterface logger() + * @method static LoggerInterface devLogger() + * @method static LoggerInterface workerLogger() * */ class DI { const CLASS_MAPPING = [ 'app' => App::class, - 'aclFormatter' => ACLFormatter::class, 'auth' => App\Authentication::class, 'args' => App\Arguments::class, 'baseUrl' => App\BaseURL::class, @@ -67,24 +50,25 @@ class DI 'module' => App\Module::class, 'page' => App\Page::class, 'router' => App\Router::class, - 'notify' => Notify::class, - 'activity' => Activity::class, 'contentItem' => Content\Item::class, 'bbCodeVideo' => Content\Text\BBCode\Video::class, - 'dtFormat' => DateTimeFormat::class, - 'cache' => ICache::class, - 'config' => IConfiguration::class, - 'pConfig' => IPConfiguration::class, - 'l10n' => L10n::class, - 'lock' => ILock::class, + 'cache' => Core\Cache\ICache::class, + 'config' => Core\Config\IConfiguration::class, + 'pConfig' => Core\Config\IPConfiguration::class, + 'l10n' => Core\L10n\L10n::class, + 'lock' => Core\Lock\ILock::class, + 'process' => Core\Process::class, + 'session' => Core\Session\ISession::class, + 'dba' => Database\Database::class, + 'notify' => Model\Notify::class, + 'activity' => Protocol\Activity::class, + 'aclFormatter' => Util\ACLFormatter::class, + 'dtFormat' => Util\DateTimeFormat::class, + 'fs' => Util\FileSystem::class, + 'workerLogger' => Util\Logger\WorkerLogger::class, + 'profiler' => Util\Profiler::class, 'logger' => LoggerInterface::class, - 'workerLogger' => WorkerLogger::class, 'devLogger' => '$devLogger', - 'session' => ISession::class, - 'dba' => Database::class, - 'fs' => FileSystem::class, - 'profiler' => Profiler::class, - 'process' => Process::class, ]; /** @var Dice */ From 2cb449a0d5823d6df7b9f65505d4290d519ca960 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Sun, 22 Dec 2019 21:25:29 +0100 Subject: [PATCH 30/34] make the DI abstract so no instance is possible --- src/DI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DI.php b/src/DI.php index 0ce28f3aef..557e98a801 100644 --- a/src/DI.php +++ b/src/DI.php @@ -39,7 +39,7 @@ use Psr\Log\LoggerInterface; * @method static LoggerInterface workerLogger() * */ -class DI +abstract class DI { const CLASS_MAPPING = [ 'app' => App::class, From df0c05d6356c8e06cd07be5bf81eb1d860b3d9a5 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Fri, 27 Dec 2019 15:20:09 +0100 Subject: [PATCH 31/34] Add Model\Introduction class to DI registry --- mod/notifications.php | 4 +--- src/BaseModel.php | 11 +++++------ src/DI.php | 2 ++ src/Module/Api/Mastodon/FollowRequests.php | 4 +--- src/Module/FollowConfirm.php | 4 +--- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/mod/notifications.php b/mod/notifications.php index 4db4a8a83e..73730b50a5 100644 --- a/mod/notifications.php +++ b/mod/notifications.php @@ -31,9 +31,7 @@ function notifications_post(App $a) } if ($request_id) { - /** @var Introduction $Intro */ - $Intro = \Friendica\BaseObject::getClass(Introduction::class); - $Intro->fetch(['id' => $request_id, 'uid' => local_user()]); + $Intro = DI::intro()->fetch(['id' => $request_id, 'uid' => local_user()]); switch ($_POST['submit']) { case L10n::t('Discard'): diff --git a/src/BaseModel.php b/src/BaseModel.php index 32011c7db2..f8cef0c13e 100644 --- a/src/BaseModel.php +++ b/src/BaseModel.php @@ -32,10 +32,11 @@ abstract class BaseModel */ private $data = []; - public function __construct(Database $dba, LoggerInterface $logger) + public function __construct(Database $dba, LoggerInterface $logger, $data = []) { $this->dba = $dba; $this->logger = $logger; + $this->data = $data; } /** @@ -71,15 +72,13 @@ abstract class BaseModel */ public function fetch(array $condition) { - $intro = $this->dba->selectFirst(static::$table_name, [], $condition); + $data = $this->dba->selectFirst(static::$table_name, [], $condition); - if (!$intro) { + if (!$data) { throw new HTTPException\NotFoundException(static::class . ' record not found.'); } - $this->data = $intro; - - return $this; + return new static($this->dba, $this->logger, $data); } /** diff --git a/src/DI.php b/src/DI.php index 557e98a801..e328a1fdd3 100644 --- a/src/DI.php +++ b/src/DI.php @@ -29,6 +29,7 @@ use Psr\Log\LoggerInterface; * @method static Core\Session\ISession session() * @method static Database\Database dba() * @method static Model\Notify notify() + * @method static Model\Introduction intro() * @method static Protocol\Activity activity() * @method static Util\ACLFormatter aclFormatter() * @method static Util\DateTimeFormat dtFormat() @@ -61,6 +62,7 @@ abstract class DI 'session' => Core\Session\ISession::class, 'dba' => Database\Database::class, 'notify' => Model\Notify::class, + 'intro' => Model\Introduction::class, 'activity' => Protocol\Activity::class, 'aclFormatter' => Util\ACLFormatter::class, 'dtFormat' => Util\DateTimeFormat::class, diff --git a/src/Module/Api/Mastodon/FollowRequests.php b/src/Module/Api/Mastodon/FollowRequests.php index a8d6cb52ea..6cafb44a66 100644 --- a/src/Module/Api/Mastodon/FollowRequests.php +++ b/src/Module/Api/Mastodon/FollowRequests.php @@ -30,9 +30,7 @@ class FollowRequests extends Api { parent::post($parameters); - /** @var Introduction $Intro */ - $Intro = self::getClass(Introduction::class); - $Intro->fetch(['id' => $parameters['id'], 'uid' => self::$current_user_id]); + $Intro = DI::intro()->fetch(['id' => $parameters['id'], 'uid' => self::$current_user_id]); $contactId = $Intro->{'contact-id'}; diff --git a/src/Module/FollowConfirm.php b/src/Module/FollowConfirm.php index b97b00944c..e54032c850 100644 --- a/src/Module/FollowConfirm.php +++ b/src/Module/FollowConfirm.php @@ -23,9 +23,7 @@ class FollowConfirm extends BaseModule $duplex = intval($_POST['duplex'] ?? 0); $hidden = intval($_POST['hidden'] ?? 0); - /** @var Introduction $Intro */ - $Intro = self::getClass(Introduction::class); - $Intro->fetch(['id' => $intro_id, 'uid' => local_user()]); + $Intro = DI::intro()->fetch(['id' => $intro_id, 'uid' => local_user()]); $cid = $Intro->{'contact-id'}; From 2660edbb48a313a18fd8e06bbf649ccf08063898 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Fri, 27 Dec 2019 15:20:40 +0100 Subject: [PATCH 32/34] Use DI::baseUrl() for Search\Index.php --- src/Module/Search/Index.php | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/Module/Search/Index.php b/src/Module/Search/Index.php index c53c6439c9..87f0193c32 100644 --- a/src/Module/Search/Index.php +++ b/src/Module/Search/Index.php @@ -40,9 +40,6 @@ class Index extends BaseSearchModule throw $e; } - /** @var BaseURL $baseURL */ - $baseURL = self::getClass(BaseURL::class); - if (Config::get('system', 'permit_crawling') && !Session::isAuthenticated()) { // Default values: // 10 requests are "free", after the 11th only a call per minute is allowed @@ -97,13 +94,13 @@ class Index extends BaseSearchModule $search = substr($search, 1); } - self::tryRedirectToProfile($baseURL, $search); + self::tryRedirectToProfile($search); if (strpos($search, '@') === 0 || strpos($search, '!') === 0) { return self::performContactSearch($search); } - self::tryRedirectToPost($baseURL, $search); + self::tryRedirectToPost($search); if (!empty($_GET['search-option'])) { switch ($_GET['search-option']) { @@ -207,12 +204,11 @@ class Index extends BaseSearchModule * - user@domain * - Any fully-formed URL * - * @param BaseURL $baseURL * @param string $search * @throws HTTPException\InternalServerErrorException * @throws \ImagickException */ - private static function tryRedirectToProfile(BaseURL $baseURL, string $search) + private static function tryRedirectToProfile(string $search) { $isUrl = !empty(parse_url($search, PHP_URL_SCHEME)); $isAddr = (bool)preg_match('/^@?([a-z0-9.-_]+@[a-z0-9.-_:]+)$/i', trim($search), $matches); @@ -246,18 +242,17 @@ class Index extends BaseSearchModule } if (!empty($contact_id)) { - $baseURL->redirect('contact/' . $contact_id); + DI::baseUrl()->redirect('contact/' . $contact_id); } } /** * Fetch/search a post by URL and redirects to its local representation if it was found. * - * @param BaseURL $baseURL * @param string $search * @throws HTTPException\InternalServerErrorException */ - private static function tryRedirectToPost(BaseURL $baseURL, string $search) + private static function tryRedirectToPost(string $search) { if (parse_url($search, PHP_URL_SCHEME) == '') { return; @@ -278,7 +273,7 @@ class Index extends BaseSearchModule if (!empty($item_id)) { $item = Item::selectFirst(['guid'], ['id' => $item_id]); if (DBA::isResult($item)) { - $baseURL->redirect('display/' . $item['guid']); + DI::baseUrl()->redirect('display/' . $item['guid']); } } } From 651d693270816bdae57a73f1fea6e365e1e03e16 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Sun, 29 Dec 2019 16:48:15 +0100 Subject: [PATCH 33/34] Rebase for OpenId & Hovercard --- src/Module/HoverCard.php | 15 ++++-------- src/Module/Security/OpenID.php | 42 ++++++++++++---------------------- 2 files changed, 20 insertions(+), 37 deletions(-) diff --git a/src/Module/HoverCard.php b/src/Module/HoverCard.php index 2106809220..d4d53184fc 100644 --- a/src/Module/HoverCard.php +++ b/src/Module/HoverCard.php @@ -9,6 +9,7 @@ use Friendica\BaseModule; use Friendica\Core\Config\Configuration; use Friendica\Core\L10n\L10n; use Friendica\Core\Session; +use Friendica\DI; use Friendica\Model\Profile; use Friendica\Model\User; use Friendica\Network\HTTPException\NotFoundException; @@ -31,15 +32,12 @@ class HoverCard extends BaseModule $nickname = $parameters['profile']; $profile = 0; } else { - /** @var L10n $l10n */ - $l10n = self::getClass(L10n::class); - throw new NotFoundException($l10n->t('No profile')); + throw new NotFoundException(DI::l10n()->t('No profile')); } Profile::load($a, $nickname, $profile); - /** @var Page $page */ - $page = self::getClass(Page::class); + $page = DI::page(); if (!empty($a->profile['page-flags']) && ($a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY)) { $page['htmlhead'] .= ''; @@ -52,10 +50,8 @@ class HoverCard extends BaseModule $page['htmlhead'] .= '' . "\r\n"; } - /** @var Configuration $config */ - $config = self::getClass(Configuration::class); // check if blocked - if ($config->get('system', 'block_public') && !Session::isAuthenticated()) { + if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) { $keywords = $a->profile['pub_keywords'] ?? ''; $keywords = str_replace([',', ' ', ',,'], [' ', ',', ','], $keywords); if (strlen($keywords)) { @@ -63,8 +59,7 @@ class HoverCard extends BaseModule } } - /** @var BaseURL $baseUrl */ - $baseUrl = self::getClass(BaseURL::class); + $baseUrl = DI::baseUrl(); $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $baseUrl->getHostname() . ($baseUrl->getUrlPath() ? '/' . $baseUrl->getUrlPath() : '')); diff --git a/src/Module/Security/OpenID.php b/src/Module/Security/OpenID.php index b11afa1b98..3d458cac48 100644 --- a/src/Module/Security/OpenID.php +++ b/src/Module/Security/OpenID.php @@ -9,6 +9,7 @@ use Friendica\Core\Config\Configuration; use Friendica\Core\L10n\L10n; use Friendica\Core\Session\ISession; use Friendica\Database\Database; +use Friendica\DI; use Friendica\Util\Strings; use LightOpenID; use Psr\Log\LoggerInterface; @@ -20,37 +21,26 @@ class OpenID extends BaseModule { public static function content(array $parameters = []) { - /** @var Configuration $config */ - $config = self::getClass(Configuration::class); - - /** @var BaseURL $baseUrl */ - $baseUrl = self::getClass(BaseURL::class); - - if ($config->get('system', 'no_openid')) { - $baseUrl->redirect(); + if (DI::config()->get('system', 'no_openid')) { + DI::baseUrl()->redirect(); } - /** @var LoggerInterface $logger */ - $logger = self::getClass(LoggerInterface::class); + DI::logger()->debug('mod_openid.', ['request' => $_REQUEST]); - $logger->debug('mod_openid.', ['request' => $_REQUEST]); - - /** @var ISession $session */ - $session = self::getClass(ISession::class); + $session = DI::session(); if (!empty($_GET['openid_mode']) && !empty($session->get('openid'))) { - $openid = new LightOpenID($baseUrl->getHostname()); + $openid = new LightOpenID(DI::baseUrl()->getHostname()); - /** @var L10n $l10n */ - $l10n = self::getClass(L10n::class); + $l10n = DI::l10n(); if ($openid->validate()) { $authId = $openid->data['openid_identity']; if (empty($authId)) { - $logger->info($l10n->t('OpenID protocol error. No ID returned')); - $baseUrl->redirect(); + DI::logger()->info($l10n->t('OpenID protocol error. No ID returned')); + DI::baseUrl()->redirect(); } // NOTE: we search both for normalised and non-normalised form of $authid @@ -61,7 +51,7 @@ class OpenID extends BaseModule $condition = ['blocked' => false, 'account_expired' => false, 'account_removed' => false, 'verified' => true, 'openid' => [$authId, Strings::normaliseOpenID($authId)]]; - $dba = self::getClass(Database::class); + $dba = DI::dba(); $user = $dba->selectFirst('user', [], $condition); if ($dba->isResult($user)) { @@ -69,13 +59,11 @@ class OpenID extends BaseModule // successful OpenID login $session->remove('openid'); - /** @var Authentication $auth */ - $auth = self::getClass(Authentication::class); - $auth->setForUser(self::getApp(), $user, true, true); + DI::auth()->setForUser(self::getApp(), $user, true, true); // just in case there was no return url set // and we fell through - $baseUrl->redirect(); + DI::baseUrl()->redirect(); } // Successful OpenID login - but we can't match it to an existing account. @@ -84,17 +72,17 @@ class OpenID extends BaseModule $session->set('openid_identity', $authId); // Detect the server URL - $open_id_obj = new LightOpenID($baseUrl->getHostName()); + $open_id_obj = new LightOpenID(DI::baseUrl()->getHostName()); $open_id_obj->identity = $authId; $session->set('openid_server', $open_id_obj->discover($open_id_obj->identity)); - if (intval($config->get('config', 'register_policy')) === \Friendica\Module\Register::CLOSED) { + if (intval(DI::config()->get('config', 'register_policy')) === \Friendica\Module\Register::CLOSED) { notice($l10n->t('Account not found. Please login to your existing account to add the OpenID to it.')); } else { notice($l10n->t('Account not found. Please register a new account or login to your existing account to add the OpenID to it.')); } - $baseUrl->redirect('login'); + DI::baseUrl()->redirect('login'); } } } From f2d4a5eb7d0b5c153f73c4cc4e7bcb63dce1bb06 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Sun, 29 Dec 2019 16:48:41 +0100 Subject: [PATCH 34/34] Remove namespaces --- src/Module/HoverCard.php | 5 ----- src/Module/Security/OpenID.php | 7 ------- 2 files changed, 12 deletions(-) diff --git a/src/Module/HoverCard.php b/src/Module/HoverCard.php index d4d53184fc..e8570d73d2 100644 --- a/src/Module/HoverCard.php +++ b/src/Module/HoverCard.php @@ -2,12 +2,7 @@ namespace Friendica\Module; -use Friendica\App\Arguments; -use Friendica\App\BaseURL; -use Friendica\App\Page; use Friendica\BaseModule; -use Friendica\Core\Config\Configuration; -use Friendica\Core\L10n\L10n; use Friendica\Core\Session; use Friendica\DI; use Friendica\Model\Profile; diff --git a/src/Module/Security/OpenID.php b/src/Module/Security/OpenID.php index 3d458cac48..0baa8bb543 100644 --- a/src/Module/Security/OpenID.php +++ b/src/Module/Security/OpenID.php @@ -2,17 +2,10 @@ namespace Friendica\Module\Security; -use Friendica\App\Authentication; -use Friendica\App\BaseURL; use Friendica\BaseModule; -use Friendica\Core\Config\Configuration; -use Friendica\Core\L10n\L10n; -use Friendica\Core\Session\ISession; -use Friendica\Database\Database; use Friendica\DI; use Friendica\Util\Strings; use LightOpenID; -use Psr\Log\LoggerInterface; /** * Performs an login with OpenID