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 948829c1bf..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\BaseObject::setDependencyInjection($dice); -$a = \Friendica\BaseObject::getApp(); +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 469dcb001e..b2d97cc115 100755 --- a/bin/worker.php +++ b/bin/worker.php @@ -7,10 +7,10 @@ use Dice\Dice; use Friendica\App; -use Friendica\BaseObject; use Friendica\Core\Config; use Friendica\Core\Update; use Friendica\Core\Worker; +use Friendica\DI; use Psr\Log\LoggerInterface; // Get options @@ -35,18 +35,18 @@ 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); -$a = BaseObject::getApp(); +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; } -$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/boot.php b/boot.php index fd87576725..fa99a7bb39 100644 --- a/boot.php +++ b/boot.php @@ -18,13 +18,12 @@ */ use Friendica\App; -use Friendica\BaseObject; 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 +240,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(); } /** @@ -483,8 +482,6 @@ function get_server() function get_temppath() { - $a = \get_app(); - $temppath = Config::get("system", "temppath"); if (($temppath != "") && System::isDirectoryUsable($temppath)) { @@ -501,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/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/include/api.php b/include/api.php index 4b7a1f742f..048d07d0a2 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; @@ -287,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($a->query_string, ".xml") > 0) { + if (strpos($args->getQueryString(), ".xml") > 0) { $type = "xml"; } - if (strpos($a->query_string, ".json") > 0) { + if (strpos($args->getQueryString(), ".json") > 0) { $type = "json"; } - if (strpos($a->query_string, ".rss") > 0) { + if (strpos($args->getQueryString(), ".rss") > 0) { $type = "rss"; } - if (strpos($a->query_string, ".atom") > 0) { + if (strpos($args->getQueryString(), ".atom") > 0) { $type = "atom"; } try { foreach ($API as $p => $info) { - if (strpos($a->query_string, $p) === 0) { + if (strpos($args->getQueryString(), $p) === 0) { if (!api_check_method($info['method'])) { throw new MethodNotAllowedException(); } @@ -332,7 +333,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'); + DI::profiler()->saveLog(DI::logger(), API_LOG_PREFIX . 'performance'); if (false === $return) { /* @@ -369,11 +370,11 @@ function api_call(App $a) } } - Logger::warning(API_LOG_PREFIX . 'not implemented', ['module' => 'api', 'action' => 'call', 'query' => $a->query_string]); + Logger::warning(API_LOG_PREFIX . 'not implemented', ['module' => 'api', 'action' => 'call', 'query' => DI::args()->getQueryString()]); 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); } } @@ -382,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" => $a->query_string]; + "request" => $args->getQueryString()]; $return = api_format_data('status', $type, ['status' => $error]); @@ -438,7 +438,7 @@ function api_rss_extra(App $a, $arr, $user_info) $arr['$user'] = $user_info; $arr['$rss'] = [ 'alternate' => $user_info['url'], - 'self' => System::baseUrl() . "/" . $a->query_string, + 'self' => System::baseUrl() . "/" . DI::args()->getQueryString(), 'base' => System::baseUrl(), 'updated' => api_date(null), 'atom_updated' => DateTimeFormat::utcNow(DateTimeFormat::ATOM), @@ -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); @@ -3567,10 +3567,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'; @@ -5909,10 +5907,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 +5949,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..bf1f5645b1 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; @@ -483,7 +480,7 @@ function conversation(App $a, array $items, Pager $pager, $mode, $update, $previ */ $live_update_div = '
' . "\r\n" . "\r\n"; } } elseif ($mode === 'contacts') { @@ -552,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') { @@ -562,7 +559,7 @@ function conversation(App $a, array $items, Pager $pager, $mode, $update, $previ $page_dropping = ((local_user() && local_user() == $profile_owner) ? true : false); if (!$update) { - $_SESSION['return_path'] = $a->query_string; + $_SESSION['return_path'] = DI::args()->getQueryString(); } $cb = ['items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview]; @@ -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']); @@ -786,7 +780,7 @@ function conversation(App $a, array $items, Pager $pager, $mode, $update, $previ $o = Renderer::replaceMacros($page_template, [ '$baseurl' => System::baseUrl($ssl_state), - '$return_path' => $a->query_string, + '$return_path' => DI::args()->getQueryString(), '$live_update' => $live_update_div, '$remove' => L10n::t('remove'), '$mode' => $mode, @@ -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); @@ -1202,7 +1193,7 @@ function status_editor(App $a, $x, $notes_cid = 0, $popup = false) $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/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/include/items.php b/include/items.php index 3868db40a2..8dd6793d2c 100644 --- a/include/items.php +++ b/include/items.php @@ -3,27 +3,23 @@ * @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; use Friendica\Core\Session; use Friendica\Database\DBA; +use Friendica\DI; 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'; @@ -344,7 +340,7 @@ function drop_items(array $items) function drop_item($id, $return = '') { - $a = BaseObject::getApp(); + $a = DI::app(); // locate item to be deleted @@ -353,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']) { @@ -372,7 +368,7 @@ function drop_item($id, $return = '') 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) { @@ -394,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; @@ -416,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/index.php b/index.php index dbdac5fcbf..8400ca820f 100644 --- a/index.php +++ b/index.php @@ -15,13 +15,13 @@ 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\BaseObject::getApp(); +$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/mod/api.php b/mod/api.php index 929832480a..842c1a74dc 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'; @@ -44,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 */ @@ -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(); } @@ -93,7 +94,7 @@ function api_content(App $a) if (!local_user()) { /// @TODO We need login form to redirect to this page notice(L10n::t('Please login to continue.') . EOL); - return Login::form($a->query_string, false, $request->get_parameters()); + return Login::form(DI::args()->getQueryString(), false, $request->get_parameters()); } //FKOAuth1::loginUser(4); diff --git a/mod/cal.php b/mod/cal.php index 51d17a10a4..62508fbef7 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; @@ -222,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; } } } @@ -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/common.php b/mod/common.php index 4f033de14e..c66da03850 100644 --- a/mod/common.php +++ b/mod/common.php @@ -9,6 +9,7 @@ use Friendica\Content\Pager; use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model; use Friendica\Module; use Friendica\Util\Proxy as ProxyUtils; @@ -91,7 +92,7 @@ function common_content(App $a) return $o; } - $pager = new Pager($a->query_string); + $pager = new Pager(DI::args()->getQueryString()); if ($cid) { $common_friends = Model\GContact::commonFriends($uid, $cid, $pager->getStart(), $pager->getItemsPerPage()); diff --git a/mod/community.php b/mod/community.php index 9bea93f12a..461dd2f9e0 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); @@ -148,7 +149,7 @@ function community_content(App $a, $update = 0) $itemspage_network = $a->force_max_items; } - $pager = new Pager($a->query_string, $itemspage_network); + $pager = new Pager(DI::args()->getQueryString(), $itemspage_network); $r = community_getitems($pager->getStart(), $pager->getItemsPerPage(), $content, $accounttype); 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 0641b9177b..002ddf924b 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'; @@ -94,7 +91,7 @@ function dfrn_poll_init(App $a) $my_id = '0:' . $dfrn_id; break; default: - $a->internalRedirect(); + DI::baseUrl()->redirect(); break; // NOTREACHED } @@ -141,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) { @@ -328,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 } @@ -448,7 +445,7 @@ function dfrn_poll_content(App $a) $my_id = '0:' . $dfrn_id; break; default: - $a->internalRedirect(); + DI::baseUrl()->redirect(); break; // NOTREACHED } @@ -544,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..7f0ad805a7 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(DI::args()->getCommand()); return; // NOTREACHED } if (!Network::isUrlAllowed($url)) { notice(L10n::t('Disallowed profile URL.') . EOL); - $a->internalRedirect($a->cmd); + DI::baseUrl()->redirect(DI::args()->getCommand()); return; // NOTREACHED } if (Network::isUrlBlocked($url)) { notice(L10n::t('Blocked domain') . EOL); - $a->internalRedirect($a->cmd); + DI::baseUrl()->redirect(DI::args()->getCommand()); 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(DI::args()->getCommand()); } else { if (empty($parms['fn'])) { notice(L10n::t('Warning: profile location has no identifiable owner name.') . EOL); @@ -436,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" @@ -454,10 +455,10 @@ 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 ($a->getURLPath()) { - $uri .= '/' . $a->getURLPath(); + if (DI::baseUrl()->getUrlPath()) { + $uri .= '/' . DI::baseUrl()->getUrlPath(); } $uri = urlencode($uri); @@ -609,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/display.php b/mod/display.php index de46cce0cb..fa2127aaec 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; @@ -319,14 +320,14 @@ function display_content(App $a, $update = false, $update_uid = 0) $o .= ""; } - $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)); $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/events.php b/mod/events.php index 6547a9b9ce..991d0cef7b 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; @@ -16,9 +15,11 @@ 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; +use Friendica\Module\Login; use Friendica\Module\Security\Login; use Friendica\Util\ACLFormatter; use Friendica\Util\DateTimeFormat; @@ -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,8 +151,7 @@ function events_post(App $a) if ($share) { - /** @var ACLFormatter $aclFormatter */ - $aclFormatter = BaseObject::getClass(ACLFormatter::class); + $aclFormatter = DI::aclFormatter(); $str_group_allow = $aclFormatter->toString($_POST['group_allow'] ?? ''); $str_contact_allow = $aclFormatter->toString($_POST['contact_allow'] ?? ''); @@ -206,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) @@ -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; } } } @@ -579,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 93da70e40e..d6f34e58a8 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; @@ -126,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(); } @@ -174,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(); @@ -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'] ?? ''); @@ -329,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(); } @@ -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); @@ -671,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(); @@ -682,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]; @@ -717,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(); } @@ -737,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 @@ -859,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]; @@ -882,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])) { @@ -893,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/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/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/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 8efe825cd9..4c6aa3d848 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(DI::args()->getCommand() . '/' . $ret); } } @@ -133,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) { @@ -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'); } } @@ -264,7 +265,7 @@ function message_content(App $a) } - $_SESSION['return_path'] = $a->query_string; + $_SESSION['return_path'] = DI::args()->getQueryString(); if ($a->argc == 1) { @@ -281,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 5d8656cd35..be121540c1 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; } @@ -66,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) { @@ -131,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); } } @@ -143,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'] ?? ''); } @@ -231,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 { @@ -312,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; @@ -392,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); @@ -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 { @@ -593,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 } @@ -647,7 +641,7 @@ function networkThreadedView(App $a, $update, $parent) } } else { notice(L10n::t('Invalid contact.') . EOL); - $a->internalRedirect('network'); + DI::baseUrl()->redirect('network'); // NOTREACHED } } @@ -687,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); @@ -875,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); } @@ -920,7 +914,7 @@ function network_tabs(App $a) $all_active = 'active'; } - $cmd = $a->cmd; + $cmd = DI::args()->getCommand(); // tabs $tabs = [ 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 502a2397de..73730b50a5 100644 --- a/mod/notifications.php +++ b/mod/notifications.php @@ -13,14 +13,15 @@ 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\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); @@ -30,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'): @@ -43,7 +42,7 @@ function notifications_post(App $a) break; } - $a->internalRedirect('notifications/intros'); + DI::baseUrl()->redirect('notifications/intros'); } } @@ -61,8 +60,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 @@ -112,11 +110,11 @@ 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 - $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/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 1d7ce7b3de..a0a1be9327 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; @@ -174,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 } @@ -190,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 @@ -210,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 } @@ -253,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'])) { @@ -283,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 } } @@ -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']) : ''; @@ -593,7 +591,7 @@ function photos_post(App $a) } } } - $a->internalRedirect($_SESSION['photo_return']); + DI::baseUrl()->redirect($_SESSION['photo_return']); return; // NOTREACHED } @@ -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)); @@ -820,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 } @@ -849,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; @@ -987,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; @@ -997,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); @@ -1011,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'] ?? ''; @@ -1033,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', @@ -1140,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', @@ -1287,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); @@ -1351,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(), ]); } @@ -1365,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'); @@ -1374,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(), ]); } @@ -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)) && @@ -1553,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/profile_photo.php b/mod/profile_photo.php index 97d2da349c..6d625cedeb 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; @@ -125,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()); @@ -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..18fe636d3d 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']); } } @@ -654,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/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/redir.php b/mod/redir.php index 9d86f27a96..6083117b40 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']; @@ -59,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 @@ -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..7aecbc3bdb 100644 --- a/mod/regmod.php +++ b/mod/regmod.php @@ -9,14 +9,13 @@ 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; function user_allow($hash) { - $a = \get_app(); - $register = Register::getByHash($hash); if (!DBA::isResult($register)) { return false; @@ -44,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' ); @@ -81,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'])) { @@ -98,11 +97,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..ecf65c04c1 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(); @@ -79,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/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 ad83b68210..5f28ca6d29 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; @@ -175,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; } @@ -221,7 +219,7 @@ function settings_post(App $a) ); } } - $a->internalRedirect('settings/oauth/', true); + DI::baseUrl()->redirect('settings/oauth/', true); return; } @@ -385,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 } @@ -421,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); @@ -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']) : ''; @@ -641,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 } @@ -708,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; } @@ -724,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'), @@ -1130,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() . $a->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'); @@ -1155,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 4b67dd6eb8..15370d25a9 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) @@ -40,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(); @@ -57,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/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..b6f6b1d8e7 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) @@ -123,7 +124,7 @@ function videos_content(App $a) //$phototypes = Photo::supportedTypes(); - $_SESSION['video_return'] = $a->cmd; + $_SESSION['video_return'] = DI::args()->getCommand(); // // Parse arguments @@ -211,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/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 3ea7d05f0c..71b64bdb64 100644 --- a/src/App.php +++ b/src/App.php @@ -10,15 +10,13 @@ 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\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; @@ -42,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 */ @@ -57,21 +53,13 @@ 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() */ public $argc; - /** @deprecated 2019.09 - Use App\Module->getName() instead */ - public $module; 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 @@ -100,7 +88,7 @@ class App private $currentMobileTheme; /** - * @var Configuration The config + * @var IConfiguration The config */ private $config; @@ -144,16 +132,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 * @@ -165,67 +143,9 @@ 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 - * - * @return Profiler - */ - public function getProfiler() - { - return $this->profiler; - } - - /** - * Returns the Mode of the Application - * - * @return App\Mode The Application Mode - */ - public function getMode() - { - return $this->mode; - } - - /** - * Returns the Database of the Application - * - * @return Database - */ - public function getDBA() - { - return $this->database; - } - - /** - * @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 + * @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 @@ -234,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, 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; @@ -246,16 +166,10 @@ class App $this->args = $args; $this->process = $process; - $this->cmd = $args->getCommand(); $this->argv = $args->getArgv(); $this->argc = $args->getArgc(); - $this->query_string = $args->getQueryString(); - $this->module = $module->getName(); $this->page = $page; - $this->is_mobile = $mode->isMobile(); - $this->is_tablet = $mode->isTablet(); - $this->load(); } @@ -311,85 +225,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(); - } - - /** - * 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); - } - - /** - * @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 hostname - * - * @return string - * - * @deprecated 2019.06 - use BaseURL->getHostname() instead - */ - public function getHostName() - { - 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(); - } - - /** - * @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 * @@ -403,31 +238,7 @@ class App FRIENDICA_CODENAME . "' " . FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION . '; ' . - $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(); + $this->baseURL->get(); } /** @@ -593,25 +404,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 - * - * @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 @@ -626,8 +418,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()); } } @@ -641,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(); @@ -731,9 +523,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); @@ -743,35 +535,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 @@ -782,7 +574,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); } @@ -790,15 +582,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 b88690415c..cb07d7afc2 100644 --- a/src/App/Authentication.php +++ b/src/App/Authentication.php @@ -8,13 +8,14 @@ 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; 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; @@ -29,8 +30,10 @@ use Psr\Log\LoggerInterface; */ class Authentication { - /** @var Configuration */ + /** @var IConfiguration */ private $config; + /** @var App\Mode */ + private $mode; /** @var App\BaseURL */ private $baseUrl; /** @var L10n */ @@ -47,7 +50,8 @@ class Authentication /** * Authentication constructor. * - * @param Configuration $config + * @param IConfiguration $config + * @param App\Mode $mode * @param App\BaseURL $baseUrl * @param L10n $l10n * @param Database $dba @@ -55,9 +59,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(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; $this->baseUrl = $baseUrl; $this->l10n = $l10n; $this->dba = $dba; @@ -351,7 +356,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'); } @@ -374,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')); } } @@ -404,10 +409,10 @@ 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 { - $a->internalRedirect('2fa'); + $this->baseUrl->redirect('2fa'); } } } 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 a8648d0aa0..7c81b6a7ea 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; @@ -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; @@ -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/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/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/BaseModule.php b/src/BaseModule.php index be53289e52..dcacce78bb 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() @@ -140,7 +140,7 @@ abstract class BaseModule extends BaseObject 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/BaseObject.php b/src/BaseObject.php deleted file mode 100644 index 2048188451..0000000000 --- a/src/BaseObject.php +++ /dev/null @@ -1,69 +0,0 @@ -create($name); - } else { - throw new InternalServerErrorException('Class \'' . $name . '\' isn\'t valid.'); - } - } -} 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 fb640a0b0e..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); @@ -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/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/Content/Nav.php b/src/Content/Nav.php index ff1680ab3f..3594bae50e 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; @@ -152,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()) { @@ -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'], ]; } @@ -178,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/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 3617470df4..ada0a0f35a 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; @@ -19,6 +18,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; @@ -33,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 @@ -1093,7 +1093,7 @@ class BBCode extends BaseObject $text = Cache::get($cache_key); if (is_null($text)) { - $a = self::getApp(); + $a = DI::app(); $stamp1 = microtime(true); @@ -1104,7 +1104,7 @@ class BBCode extends BaseObject @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]"; @@ -1149,10 +1149,10 @@ 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/'); + $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]'; @@ -1178,7 +1178,7 @@ class BBCode extends BaseObject @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/') { @@ -1253,7 +1253,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 +2010,7 @@ class BBCode extends BaseObject */ public static function toMarkdown($text, $for_diaspora = true) { - $a = self::getApp(); + $a = DI::app(); $original_text = $text; @@ -2061,7 +2061,7 @@ class BBCode extends BaseObject // 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 a715de7e97..8d363675fc 100644 --- a/src/Content/Text/Markdown.php +++ b/src/Content/Text/Markdown.php @@ -6,8 +6,8 @@ namespace Friendica\Content\Text; -use Friendica\BaseObject; use Friendica\Core\System; +use Friendica\DI; use Friendica\Model\Contact; /** @@ -15,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 @@ -43,7 +43,7 @@ class Markdown extends BaseObject $html = $MarkdownParser->transform($text); - self::getApp()->getProfiler()->saveTimestamp($stamp1, "parser", System::callstack()); + DI::profiler()->saveTimestamp($stamp1, "parser", System::callstack()); return $html; } diff --git a/src/Core/ACL.php b/src/Core/ACL.php index 64e03d4719..a4b4a99190 100644 --- a/src/Core/ACL.php +++ b/src/Core/ACL.php @@ -7,8 +7,8 @@ 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; @@ -17,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 @@ -35,7 +35,7 @@ class ACL extends BaseObject */ public static function getSuggestContactSelectHTML($selname, $selclass, array $options = [], array $preselected = []) { - $a = self::getApp(); + $a = DI::app(); $networks = null; @@ -109,7 +109,7 @@ class ACL extends BaseObject $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 extends BaseObject $o .= '' . PHP_EOL; - Hook::callAll($a->module . '_post_' . $selname, $o); + Hook::callAll(DI::module()->getName() . '_post_' . $selname, $o); return $o; } @@ -145,7 +145,7 @@ class ACL extends BaseObject */ public static function getMessageContactSelectHTML($selname, $selclass, array $preselected = [], $size = 4, $tabindex = null) { - $a = self::getApp(); + $a = DI::app(); $o = ''; @@ -175,7 +175,7 @@ class ACL extends BaseObject $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 extends BaseObject $o .= implode(', ', $receiverlist); } - Hook::callAll($a->module . '_post_' . $selname, $o); + Hook::callAll(DI::module()->getName() . '_post_' . $selname, $o); return $o; } diff --git a/src/Core/Addon.php b/src/Core/Addon.php index 2ec46b71c1..252acd31f0 100644 --- a/src/Core/Addon.php +++ b/src/Core/Addon.php @@ -5,14 +5,14 @@ namespace Friendica\Core; -use Friendica\BaseObject; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Util\Strings; /** * Some functions to handle addons */ -class Addon extends BaseObject +class Addon { /** * The addon sub-directory @@ -177,7 +177,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 +234,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 +267,7 @@ class Addon extends BaseObject */ public static function getInfo($addon) { - $a = self::getApp(); + $a = DI::app(); $addon = Strings::sanitizeFilePathItem($addon); @@ -286,7 +286,7 @@ class Addon extends BaseObject $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/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/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.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/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/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 5caa543194..b8ad0fb8bd 100644 --- a/src/Core/Hook.php +++ b/src/Core/Hook.php @@ -5,14 +5,14 @@ namespace Friendica\Core; use Friendica\App; -use Friendica\BaseObject; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Util\Strings; /** * Some functions to handle hooks */ -class Hook extends BaseObject +class Hook { /** * Array of registered hooks @@ -75,7 +75,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 +98,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 +148,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 +175,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/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/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/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/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/Core/Renderer.php b/src/Core/Renderer.php index d9d913050f..32247310cf 100644 --- a/src/Core/Renderer.php +++ b/src/Core/Renderer.php @@ -6,14 +6,14 @@ namespace Friendica\Core; use Exception; -use Friendica\BaseObject; +use Friendica\DI; use Friendica\Render\FriendicaSmarty; 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') @@ -61,10 +61,9 @@ class Renderer extends BaseObject public static function replaceMacros($s, array $vars = []) { $stamp1 = microtime(true); - $a = self::getApp(); // 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(); @@ -75,7 +74,7 @@ class Renderer extends BaseObject exit(); } - $a->getProfiler()->saveTimestamp($stamp1, "rendering", System::callstack()); + DI::profiler()->saveTimestamp($stamp1, "rendering", System::callstack()); return $output; } @@ -92,7 +91,7 @@ class Renderer extends BaseObject public static function getMarkupTemplate($s, $root = '') { $stamp1 = microtime(true); - $a = self::getApp(); + $a = DI::app(); $t = self::getTemplateEngine(); try { @@ -102,7 +101,7 @@ class Renderer extends BaseObject exit(); } - $a->getProfiler()->saveTimestamp($stamp1, "file", System::callstack()); + DI::profiler()->saveTimestamp($stamp1, "file", System::callstack()); return $template; } diff --git a/src/Core/Search.php b/src/Core/Search.php index e43e621d29..ab06a51a7d 100644 --- a/src/Core/Search.php +++ b/src/Core/Search.php @@ -2,8 +2,8 @@ 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; @@ -20,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'; @@ -92,8 +92,7 @@ class Search extends BaseObject */ public static function getContactsFromGlobalDirectory($search, $type = self::TYPE_ALL, $page = 1) { - $config = self::getApp()->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 extends BaseObject */ public static function getContactsFromLocalDirectory($search, $type = self::TYPE_ALL, $start = 0, $itemPage = 80) { - $config = self::getApp()->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/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 7aba0653e1..d5902c003a 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -4,8 +4,7 @@ */ namespace Friendica\Core; -use Friendica\App\BaseURL; -use Friendica\BaseObject; +use Friendica\DI; use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Util\XML; @@ -19,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); } /** @@ -43,7 +41,7 @@ class System extends BaseObject */ public static function removedBaseUrl(string $orig_url) { - return self::getApp()->removeBaseURL($orig_url); + return DI::baseUrl()->remove($orig_url); } /** @@ -184,7 +182,7 @@ class System extends BaseObject if (is_bool($prefix) && !$prefix) { $prefix = ''; } elseif (empty($prefix)) { - $prefix = hash('crc32', self::getApp()->getHostName()); + $prefix = hash('crc32', DI::baseUrl()->getHostname()); } while (strlen($prefix) < ($size - 13)) { diff --git a/src/Core/Theme.php b/src/Core/Theme.php index 4f870687ce..a4dfe2f9fa 100644 --- a/src/Core/Theme.php +++ b/src/Core/Theme.php @@ -6,7 +6,7 @@ namespace Friendica\Core; -use Friendica\BaseObject; +use Friendica\DI; use Friendica\Model\Profile; use Friendica\Util\Strings; @@ -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); @@ -194,7 +193,7 @@ class Theme */ public static function getPathForFile($file) { - $a = BaseObject::getApp(); + $a = DI::app(); $theme = $a->getCurrentTheme(); @@ -232,7 +231,7 @@ class Theme return 'view/theme/' . $theme . '/style.css'; } - $a = BaseObject::getApp(); + $a = DI::app(); $query_params = []; 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/Core/Worker.php b/src/Core/Worker.php index c64b0ebc6b..62f7bd4c6a 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -4,9 +4,9 @@ */ 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; @@ -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; } @@ -386,7 +384,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 +441,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); + DI::profiler()->saveLog(DI::logger(), "ID " . $queue["id"] . ": " . $funcname); $cooldown = Config::get("system", "worker_cooldown", 0); @@ -1086,7 +1084,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(DI::logger(), DI::mode(), DI::config(), $a->getBasePath()); $process->run($command, $args); // after spawning we have to remove the flag. @@ -1129,7 +1127,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; @@ -1232,11 +1230,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..e328a1fdd3 --- /dev/null +++ b/src/DI.php @@ -0,0 +1,88 @@ + App::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, + 'contentItem' => Content\Item::class, + 'bbCodeVideo' => Content\Text\BBCode\Video::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, + 'intro' => Model\Introduction::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, + 'devLogger' => '$devLogger', + ]; + + /** @var Dice */ + private static $dice; + + public static function init(Dice $dice) + { + self::$dice = $dice; + } + + public static function __callStatic($name, $arguments) + { + return self::$dice->create(self::CLASS_MAPPING[$name], $arguments); + } +} 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/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/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/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 0073a6ed3f..c1d5c033bd 100644 --- a/src/Model/Attach.php +++ b/src/Model/Attach.php @@ -6,11 +6,11 @@ */ namespace Friendica\Model; -use Friendica\BaseObject; 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; @@ -20,7 +20,7 @@ use Friendica\Util\Security; /** * Class to handle attach dabatase table */ -class Attach extends BaseObject +class Attach { /** @@ -31,7 +31,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..c84f979a98 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; @@ -16,8 +15,8 @@ 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; use Friendica\Protocol\ActivityPub; use Friendica\Protocol\DFRN; @@ -32,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 @@ -1733,7 +1732,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); @@ -1758,7 +1757,7 @@ class Contact extends BaseObject $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()]]; @@ -2267,13 +2266,13 @@ class Contact extends BaseObject 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()); + $myaddr = bin2hex($a->user['nickname'] . '@' . DI::baseUrl()->getHostname()); } - $a->internalRedirect($ret['request'] . "&addr=$myaddr"); + DI::baseUrl()->redirect($ret['request'] . "&addr=$myaddr"); // NOTREACHED } 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 ebee91ffc2..16a6a0a24c 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; @@ -21,11 +20,11 @@ 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; use Friendica\Protocol\OStatus; -use Friendica\Util\ACLFormatter; use Friendica\Util\DateTimeFormat; use Friendica\Util\Map; use Friendica\Util\Network; @@ -35,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; @@ -1280,7 +1279,7 @@ class Item extends BaseObject 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 = ''; @@ -1441,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']); @@ -2513,7 +2511,7 @@ class Item extends BaseObject $guid = System::createUUID(); } - return self::getApp()->getBaseURL() . '/objects/' . $guid; + return DI::baseUrl()->get() . '/objects/' . $guid; } /** @@ -2754,8 +2752,6 @@ class Item extends BaseObject public static function isRemoteSelf($contact, &$datarray) { - $a = \get_app(); - if (!$contact['remote_self']) { return false; } @@ -2767,7 +2763,7 @@ class Item extends BaseObject } // 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; } @@ -2979,8 +2975,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); @@ -3474,7 +3469,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 +3504,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 +3642,7 @@ class Item extends BaseObject */ public static function getPlink($item) { - $a = self::getApp(); + $a = DI::app(); if ($a->user['nickname'] != "") { $ret = [ @@ -3658,7 +3653,7 @@ class Item extends BaseObject ]; 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/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 60eba2713a..6d9c77154a 100644 --- a/src/Model/Nodeinfo.php +++ b/src/Model/Nodeinfo.php @@ -2,14 +2,14 @@ namespace Friendica\Model; -use Friendica\BaseObject; use Friendica\Core\Addon; use Friendica\Database\DBA; +use Friendica\DI; /** * Model interaction for the nodeinfo */ -class Nodeinfo extends BaseObject +class Nodeinfo { /** * Updates the info about the current node @@ -18,9 +18,8 @@ class Nodeinfo extends BaseObject */ public static function update() { - $app = self::getApp(); - $config = $app->getConfig(); - $logger = $app->getLogger(); + $config = DI::config(); + $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/Model/Notify.php b/src/Model/Notify.php index eef481ad8f..10ece48e2d 100644 --- a/src/Model/Notify.php +++ b/src/Model/Notify.php @@ -4,14 +4,14 @@ 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; +use Friendica\Core\Config\IPConfiguration; 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; @@ -25,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; @@ -71,13 +71,13 @@ final class Notify extends BaseObject 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; @@ -515,7 +515,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 +669,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/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 db3c4d429b..dd49892240 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; @@ -15,6 +14,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; @@ -28,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 @@ -202,7 +202,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; @@ -679,8 +679,7 @@ class Photo extends BaseObject */ 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 extends BaseObject */ 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/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/Profile.php b/src/Model/Profile.php index 8659506cb1..a08cdade12 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; @@ -143,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; } @@ -164,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; } @@ -336,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; @@ -570,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; } @@ -667,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; } @@ -1046,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. @@ -1076,16 +1077,16 @@ 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($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 @@ -1163,7 +1164,7 @@ class Profile $arr = [ 'visitor' => $visitor, - 'url' => $a->query_string + 'url' => DI::args()->getQueryString() ]; /** * @hooks magic_auth_success @@ -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/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/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/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/Admin/Addons/Details.php b/src/Module/Admin/Addons/Details.php index a196e7834f..bc1925717e 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 @@ -28,18 +29,18 @@ 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 = []) { parent::content($parameters); - $a = self::getApp(); + $a = DI::app(); $addons_admin = Addon::getAdminList(); @@ -50,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') { @@ -67,7 +68,7 @@ class Details extends BaseAdminModule Addon::saveEnabledList(); - $a->internalRedirect('admin/addons/' . $addon); + DI::baseUrl()->redirect('admin/addons/' . $addon); } // display addon details @@ -100,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, @@ -118,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 f327f0dc92..511cb44755 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,8 +14,6 @@ class Index extends BaseAdminModule { parent::content($parameters); - $a = self::getApp(); - // reload active themes if (!empty($_GET['action'])) { parent::checkFormSecurityTokenRedirectOnError('/admin/addons', 'admin_addons', 't'); @@ -40,7 +39,7 @@ class Index extends BaseAdminModule } - $a->internalRedirect('admin/addons'); + DI::baseUrl()->redirect('admin/addons'); } $addons = Addon::getAvailableList(); @@ -51,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 38ae233715..7bcdef4687 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,20 +39,18 @@ class Contact extends BaseAdminModule notice(L10n::tt('%s contact unblocked', '%s contacts unblocked', count($contacts))); } - self::getApp()->internalRedirect('admin/blocklist/contact'); + DI::baseUrl()->redirect('admin/blocklist/contact'); } public static function content(array $parameters = []) { parent::content($parameters); - $a = self::getApp(); - $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()]]); @@ -75,7 +74,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 53647e64ef..43c6543e46 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,15 +48,13 @@ class Server extends BaseAdminModule info(L10n::t('Site blocklist updated.') . EOL); } - self::getApp()->internalRedirect('admin/blocklist/server'); + DI::baseUrl()->redirect('admin/blocklist/server'); } public static function content(array $parameters = []) { parent::content($parameters); - $a = self::getApp(); - $blocklist = Config::get('system', 'blocklist'); $blocklistform = []; if (is_array($blocklist)) { @@ -90,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 0d68a56481..a0e70737e5 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 = ''; @@ -31,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) { @@ -87,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/Features.php b/src/Module/Admin/Features.php index 85683d238f..7cc7932af8 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::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 f5f4687cec..744a57f073 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::baseUrl()->redirect('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..21380af4a5 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,15 +35,13 @@ class Settings extends BaseAdminModule } info(L10n::t("Log settings updated.")); - self::getApp()->internalRedirect('admin/logs'); + DI::baseUrl()->redirect('admin/logs'); } public static function content(array $parameters = []) { parent::content($parameters); - $a = self::getApp(); - $log_choices = [ LogLevel::ERROR => 'Error', LogLevel::WARNING => 'Warning', @@ -64,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/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..ed16a65b77 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'); @@ -47,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: @@ -55,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)); @@ -76,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'); } } @@ -94,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]); @@ -104,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 @@ -228,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.')); @@ -241,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'))) { @@ -409,15 +410,13 @@ 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 = []) { parent::content($parameters); - $a = self::getApp(); - /* Installed langs */ $lang_choices = L10n::getAvailableLanguages(); @@ -522,7 +521,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); @@ -577,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'), ''], @@ -660,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 e10533ee94..6f304082af 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 = []; @@ -62,26 +63,25 @@ 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 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); @@ -111,14 +111,14 @@ 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'); - $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.', [ + 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, ]); @@ -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(self::getApp()->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 912adc4297..2b573eec3b 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 @@ -31,11 +32,11 @@ class Details extends BaseAdminModule info(L10n::t('Theme settings updated.')); - if ($a->isAjax()) { + if (DI::mode()->isAjax()) { return; } - $a->internalRedirect('admin/themes/' . $theme); + DI::baseUrl()->redirect('admin/themes/' . $theme); } } @@ -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 @@ -75,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; @@ -105,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, @@ -121,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 70a12dadd2..fc0d3301bf 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 @@ -45,11 +46,11 @@ class Embed extends BaseAdminModule info(L10n::t('Theme settings updated.')); - if ($a->isAjax()) { + if (DI::mode()->isAjax()) { return; } - $a->internalRedirect('admin/themes/' . $theme . '/embed?mode=minimal'); + DI::baseUrl()->redirect('admin/themes/' . $theme . '/embed?mode=minimal'); } } @@ -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..dc848f93f8 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,13 +16,11 @@ class Index extends BaseAdminModule { parent::content($parameters); - $a = self::getApp(); - $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': @@ -58,7 +57,7 @@ class Index extends BaseAdminModule } - $a->internalRedirect('admin/themes'); + DI::baseUrl()->redirect('admin/themes'); } $themes = []; @@ -96,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/Tos.php b/src/Module/Admin/Tos.php index 6fbdc21e8f..5e434bc0d0 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::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 84332c979f..b71f3f7513 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,8 +20,6 @@ class Users extends BaseAdminModule { parent::post($parameters); - $a = self::getApp(); - $pending = $_POST['pending'] ?? []; $users = $_POST['user'] ?? []; $nu_name = $_POST['new_user_name'] ?? ''; @@ -77,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, @@ -128,14 +127,14 @@ class Users extends BaseAdminModule } } - $a->internalRedirect('admin/users'); + DI::baseUrl()->redirect('admin/users'); } public static function content(array $parameters = []) { parent::content($parameters); - $a = self::getApp(); + $a = DI::app(); if ($a->argc > 3) { // @TODO: Replace with parameter from router @@ -144,7 +143,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 } @@ -174,13 +173,13 @@ class Users extends BaseAdminModule break; } - $a->internalRedirect('admin/users'); + DI::baseUrl()->redirect('admin/users'); } /* 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 = [ @@ -305,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 0d9bf59858..47d8c3e264 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(); @@ -48,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)) { @@ -69,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/Api/Mastodon/FollowRequests.php b/src/Module/Api/Mastodon/FollowRequests.php index 739400eb77..6cafb44a66 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; @@ -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'}; @@ -104,8 +102,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/Apps.php b/src/Module/Apps.php index bc099ce8bb..d7cd0fc72e 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::baseUrl()->redirect(); } } 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..b4cb39e15f 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'; @@ -22,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'; } } @@ -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..f985b4a495 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,12 +51,12 @@ 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.')); - Session::set('return_path', $a->query_string); - $a->internalRedirect('login'); + Session::set('return_path', DI::args()->getQueryString()); + DI::baseUrl()->redirect('login'); } if (!empty($_SESSION['submanage'])) { diff --git a/src/Module/BaseSearchModule.php b/src/Module/BaseSearchModule.php index 96692b0b2d..cf0159cc27 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,8 +34,8 @@ class BaseSearchModule extends BaseModule */ public static function performContactSearch($search, $prefix = '') { - $a = self::getApp(); - $config = $a->getConfig(); + $a = DI::app(); + $config = DI::config(); $type = Search::TYPE_ALL; @@ -64,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)) { @@ -97,8 +97,6 @@ class BaseSearchModule extends BaseModule return ''; } - $a = self::getApp(); - $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/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..f5627e4354 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,17 +20,17 @@ class Bookmarklet extends BaseModule { $_GET['mode'] = 'minimal'; - $app = self::getApp(); - $config = $app->getConfig(); + $app = DI::app(); + $config = DI::config(); 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; } $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 82b7e4b992..d307652b63 100644 --- a/src/Module/Contact.php +++ b/src/Module/Contact.php @@ -17,11 +17,11 @@ 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; use Friendica\Network\HTTPException\NotFoundException; -use Friendica\Network\Probe; use Friendica\Util\DateTimeFormat; use Friendica\Util\Proxy as ProxyUtils; use Friendica\Util\Strings; @@ -33,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; @@ -73,12 +73,12 @@ 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 = []) { - $a = self::getApp(); + $a = DI::app(); if (!local_user()) { return; @@ -86,7 +86,7 @@ class Contact extends BaseModule // @TODO: Replace with parameter from router if ($a->argv[1] === 'batch') { - self::batchActions($a); + self::batchActions(); return; } @@ -98,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 } @@ -247,7 +247,7 @@ class Contact extends BaseModule return Login::form($_SERVER['REQUEST_URI']); } - $a = self::getApp(); + $a = DI::app(); $nets = $_GET['nets'] ?? ''; $rel = $_GET['rel'] ?? ''; @@ -279,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'); } } @@ -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; @@ -379,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 } @@ -395,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 } @@ -405,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 } @@ -416,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 } @@ -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) { @@ -450,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') { @@ -467,13 +467,13 @@ 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']; $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()); @@ -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 = []; @@ -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/Module/Debug/Feed.php b/src/Module/Debug/Feed.php index c764c90003..9a48d743c8 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::baseUrl()->redirect(); } } diff --git a/src/Module/Debug/ItemBody.php b/src/Module/Debug/ItemBody.php index f166fb0a27..d32e1f6c2d 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); @@ -30,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/Debug/Localtime.php b/src/Module/Debug/Localtime.php index 0d78f08d79..d9e2489790 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'; @@ -39,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/Delegation.php b/src/Module/Delegation.php index 7d2e686725..cb2f24ce1e 100644 --- a/src/Module/Delegation.php +++ b/src/Module/Delegation.php @@ -3,12 +3,12 @@ namespace Friendica\Module; use Friendica\BaseModule; -use Friendica\App\Authentication; use Friendica\Core\Hook; 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 +25,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')); @@ -80,9 +80,7 @@ class Delegation extends BaseModule Session::clear(); - /** @var Authentication $authentication */ - $authentication = self::getClass(Authentication::class); - $authentication->setForUser(self::getApp(), $user, true, true); + DI::auth()->setForUser(DI::app(), $user, true, true); if ($limited_id) { Session::set('submanage', $original_id); @@ -91,7 +89,7 @@ class Delegation extends BaseModule $ret = []; Hook::callAll('home_init', $ret); - self::getApp()->internalRedirect('profile/' . self::getApp()->user['nickname']); + DI::baseUrl()->redirect('profile/' . DI::app()->user['nickname']); // NOTREACHED } @@ -101,7 +99,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 +110,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..c19857fde3 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"]))) { @@ -46,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/Diaspora/Receive.php b/src/Module/Diaspora/Receive.php index 72b060a848..dbfb7f549f 100644 --- a/src/Module/Diaspora/Receive.php +++ b/src/Module/Diaspora/Receive.php @@ -2,10 +2,8 @@ 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; use Friendica\Protocol\Diaspora; @@ -23,24 +21,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/Directory.php b/src/Module/Directory.php index f24c066507..fc4c1be4f8 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,8 +24,8 @@ class Directory extends BaseModule { public static function content(array $parameters = []) { - $app = self::getApp(); - $config = $app->getConfig(); + $app = DI::app(); + $config = DI::config(); if (($config->get('system', 'block_public') && !Session::isAuthenticated()) || ($config->get('system', 'block_local_dir') && !Session::isAuthenticated())) { @@ -51,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/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..dfe548d817 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,8 +19,8 @@ class RemoveTag extends BaseModule throw new HTTPException\ForbiddenException(); } - $app = self::getApp(); - $logger = $app->getLogger(); + $app = DI::app(); + $logger = DI::logger(); $item_id = (($app->argc > 1) ? intval($app->argv[1]) : 0); @@ -46,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 7f0da83bce..93f683744e 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,14 +19,14 @@ class SaveTag extends BaseModule { if (!local_user()) { info(L10n::t('You must be logged in to use this module')); - self::getApp()->internalRedirect(); + DI::baseUrl()->redirect(); } } public static function rawContent(array $parameters = []) { - $a = self::getApp(); - $logger = $a->getLogger(); + $a = DI::app(); + $logger = DI::logger(); $term = XML::unescape(trim($_GET['term'] ?? '')); // @TODO: Replace with parameter from router diff --git a/src/Module/FollowConfirm.php b/src/Module/FollowConfirm.php index 5e9ab0481c..e54032c850 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,8 +13,6 @@ class FollowConfirm extends BaseModule { public static function post(array $parameters = []) { - $a = self::getApp(); - $uid = local_user(); if (!$uid) { notice(L10n::t('Permission denied.') . EOL); @@ -24,14 +23,12 @@ 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'}; $Intro->confirm($duplex, $hidden); - $a->internalRedirect('contact/' . intval($cid)); + DI::baseUrl()->redirect('contact/' . intval($cid)); } } 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..11773a06d2 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,8 +18,7 @@ class Friendica extends BaseModule { public static function content(array $parameters = []) { - $app = self::getApp(); - $config = $app->getConfig(); + $config = DI::config(); $visibleAddonList = Addon::getVisibleList(); if (!empty($visibleAddonList)) { @@ -47,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'); @@ -74,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.'), @@ -90,14 +90,14 @@ 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')) { return; } - $config = $app->getConfig(); + $config = DI::config(); $register_policies = [ Register::CLOSED => 'REGISTER_CLOSED', @@ -124,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'], ]; } } @@ -146,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)), @@ -156,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/Group.php b/src/Module/Group.php index 5699d2d30b..8de4c5033b 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,15 +22,15 @@ class Group extends BaseModule { public static function post(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); - if ($a->isAjax()) { + if (DI::mode()->isAjax()) { self::ajaxPost(); } if (!local_user()) { notice(L10n::t('Permission denied.')); - $a->internalRedirect(); + DI::baseUrl()->redirect(); } // @TODO: Replace with parameter from router @@ -42,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 @@ -57,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'])) { @@ -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,14 +135,14 @@ 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')); // 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 @@ -199,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])) { @@ -208,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 @@ -225,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/Help.php b/src/Module/Help.php index 58cc95affd..d9362712fd 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,8 +22,8 @@ class Help extends BaseModule $text = ''; $filename = ''; - $a = self::getApp(); - $config = $a->getConfig(); + $a = DI::app(); + $config = DI::config(); $lang = $config->get('system', 'language'); // @TODO: Replace with parameter from router @@ -35,7 +36,7 @@ class Help extends BaseModule $path .= '/'; } - $path .= $a->getArgumentValue($x); + $path .= DI::args()->get($x); } $title = basename($path); $filename = $path; @@ -86,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 8fdb613f9b..3d04849cf4 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,8 +16,8 @@ class Home extends BaseModule { public static function content(array $parameters = []) { - $app = self::getApp(); - $config = $app->getConfig(); + $app = DI::app(); + $config = DI::config(); // currently no returned data is used $ret = []; @@ -24,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 = ''; @@ -41,11 +42,11 @@ class Home extends BaseModule $customHome = $homeFilePath; if (file_exists($cssFilePath)) { - $app->page['htmlhead'] .= ''; + $app->page['htmlhead'] .= ''; } } - $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/HoverCard.php b/src/Module/HoverCard.php index 2106809220..e8570d73d2 100644 --- a/src/Module/HoverCard.php +++ b/src/Module/HoverCard.php @@ -2,13 +2,9 @@ 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; use Friendica\Model\User; use Friendica\Network\HTTPException\NotFoundException; @@ -31,15 +27,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 +45,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 +54,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/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..537338da15 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,16 +49,15 @@ class Install extends BaseModule public static function init(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); - if (!$a->getMode()->isInstall()) { + if (!DI::mode()->isInstall()) { throw new HTTPException\ForbiddenException(); } // 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(); } @@ -71,14 +71,14 @@ 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; } public static function post(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); $configCache = $a->getConfigCache(); switch (self::$currentWizardStep) { @@ -110,7 +110,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; } @@ -134,7 +134,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; } @@ -151,7 +151,7 @@ class Install extends BaseModule public static function content(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); $configCache = $a->getConfigCache(); $output = ''; @@ -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 cd616001be..67d26f6fa7 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,8 +25,8 @@ class Invite extends BaseModule self::checkFormSecurityTokenRedirectOnError('/', 'send_invite'); - $app = self::getApp(); - $config = $app->getConfig(); + $app = DI::app(); + $config = DI::config(); $max_invites = intval($config->get('system', 'max_invites')); if (!$max_invites) { @@ -110,8 +111,8 @@ class Invite extends BaseModule throw new HTTPException\ForbiddenException(L10n::t('Permission denied.')); } - $app = self::getApp(); - $config = $app->getConfig(); + $app = DI::app(); + $config = DI::config(); $inviteOnly = false; @@ -128,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.')); } } @@ -151,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/Item/Compose.php b/src/Module/Item/Compose.php index ded41fe392..5d4a3c18ed 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.')); @@ -62,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']); @@ -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/Module/Item/Ignore.php b/src/Module/Item/Ignore.php index e67f2113cd..b200741665 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; @@ -18,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)); @@ -69,7 +67,7 @@ class Ignore extends BaseModule $rand = "?$rand"; } - self::getApp()->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 1c98cbc38c..2c5f02b1f6 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); @@ -46,7 +47,7 @@ class Like extends BaseModule $rand = "?$rand"; } - $app->internalRedirect($returnPath . $rand); + DI::baseUrl()->redirect($returnPath . $rand); } } } diff --git a/src/Module/Magic.php b/src/Module/Magic.php index 0f610d123c..0ac05ccdf8 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::baseUrl()->get())) !== false) { if ($test) { $ret['success'] = true; $ret['message'] .= 'Local site - you are already authenticated.' . EOL; @@ -79,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'] . '@' . DI::baseUrl()->getHostname()() . (DI::baseUrl()->getUrlPath() ? '/' . DI::baseUrl()->getUrlPath() : '') ); // Try to get an authentication token from the other instance. diff --git a/src/Module/Maintenance.php b/src/Module/Maintenance.php index 056bde7325..bee9ab53f5 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,9 +17,7 @@ class Maintenance extends BaseModule { public static function content(array $parameters = []) { - $config = self::getApp()->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 9e09740594..a7ef344e4d 100644 --- a/src/Module/Manifest.php +++ b/src/Module/Manifest.php @@ -4,13 +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(); - $config = $app->getConfig(); + $config = DI::config(); $tpl = Renderer::getMarkupTemplate('manifest.tpl'); diff --git a/src/Module/NodeInfo.php b/src/Module/NodeInfo.php index 8e3692e3d3..a62687de1b 100644 --- a/src/Module/NodeInfo.php +++ b/src/Module/NodeInfo.php @@ -2,10 +2,9 @@ namespace Friendica\Module; -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,12 +14,10 @@ class NodeInfo extends BaseModule { public static function rawContent(array $parameters = []) { - $app = self::getApp(); - 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(); } @@ -29,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 = []; @@ -55,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' => [], @@ -116,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', @@ -155,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'; @@ -179,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')); @@ -211,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/Notifications/Notify.php b/src/Module/Notifications/Notify.php index 721a89a694..bb52ce8124 100644 --- a/src/Module/Notifications/Notify.php +++ b/src/Module/Notifications/Notify.php @@ -3,10 +3,9 @@ namespace Friendica\Module\Notifications; use Friendica\BaseModule; -use Friendica\BaseObject; use Friendica\Core\L10n; use Friendica\Core\System; -use Friendica\Model\Notify as ModelNotify; +use Friendica\DI; use Friendica\Network\HTTPException; /** @@ -23,13 +22,11 @@ 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') { - /** @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([ @@ -47,12 +44,11 @@ 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])) { - /** @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)) { @@ -62,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 df57636926..e2f21af1a5 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,14 +18,14 @@ 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(); } if (!ActivityPub::isRequest()) { - $a->internalRedirect(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/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..e1da674184 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::baseUrl()->getHostname()(); + $baseUrl = DI::baseUrl()->get(); /** @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..b28777516e 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::baseUrl()->redirect($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..8232282dfd 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); @@ -119,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'] . '@' . 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); @@ -132,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 { @@ -260,7 +258,7 @@ class Profile extends BaseModule return ''; } - $pager = new Pager($a->query_string); + $pager = new Pager(DI::args()->getQueryString()); } else { $sql_post_table = ""; @@ -292,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); @@ -304,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 9a96590ac3..f848945bcb 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]; @@ -68,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/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..c14e9f6cac 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(); @@ -22,6 +23,6 @@ class RandomProfile extends BaseModule $a->redirect($link); } - $a->internalRedirect('profile'); + DI::baseUrl()->redirect('profile'); } } diff --git a/src/Module/ReallySimpleDiscovery.php b/src/Module/ReallySimpleDiscovery.php index 7cf0db6c7b..382fe12d4f 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,6 @@ class ReallySimpleDiscovery extends BaseModule { header('Content-Type: text/xml'); - $app = self::getApp(); $xml = null; echo XML::fromArray([ 'rsd' => [ @@ -31,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/Register.php b/src/Module/Register.php index 3b43970197..613b3da7b5 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::baseUrl()->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::baseUrl()->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); @@ -197,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); @@ -208,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']; @@ -237,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.', @@ -247,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 @@ -260,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']); @@ -311,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/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..87f0193c32 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; @@ -39,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 @@ -68,7 +66,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'); @@ -96,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']) { @@ -125,9 +123,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]); @@ -190,7 +186,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)); @@ -208,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); @@ -247,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; @@ -279,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']); } } } diff --git a/src/Module/Search/Saved.php b/src/Module/Search/Saved.php index 88668272de..47925b0ae1 100644 --- a/src/Module/Search/Saved.php +++ b/src/Module/Search/Saved.php @@ -2,20 +2,17 @@ namespace Friendica\Module\Search; -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 { 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); @@ -39,6 +36,6 @@ class Saved extends BaseModule } } - self::getApp()->internalRedirect($return_url); + DI::baseUrl()->redirect($return_url); } } diff --git a/src/Module/Security/Login.php b/src/Module/Security/Login.php index 311cbdd9bb..053e17b1b4 100644 --- a/src/Module/Security/Login.php +++ b/src/Module/Security/Login.php @@ -7,12 +7,12 @@ namespace Friendica\Module\Security; use Friendica\BaseModule; -use Friendica\App\Authentication; use Friendica\Core\Config; 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,10 +25,8 @@ class Login extends BaseModule { public static function content(array $parameters = []) { - $a = self::getApp(); - 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); @@ -48,16 +46,12 @@ 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( - self::getApp(), + DI::auth()->withPassword( + DI::app(), trim($_POST['username']), trim($_POST['password']), !empty($_POST['remember']) @@ -81,7 +75,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'); @@ -92,7 +86,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'), @@ -101,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()) { @@ -110,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) ] ); @@ -133,7 +127,7 @@ class Login extends BaseModule $o .= Renderer::replaceMacros( $tpl, [ - '$dest_url' => self::getApp()->getBaseURL(true) . '/login', + '$dest_url' => DI::baseUrl()->get(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..abe409ca1d 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::baseUrl()->redirect(); } } } diff --git a/src/Module/Security/OpenID.php b/src/Module/Security/OpenID.php index b11afa1b98..0baa8bb543 100644 --- a/src/Module/Security/OpenID.php +++ b/src/Module/Security/OpenID.php @@ -2,16 +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 @@ -20,37 +14,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 +44,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 +52,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 +65,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'); } } } diff --git a/src/Module/Security/TwoFactor/Recovery.php b/src/Module/Security/TwoFactor/Recovery.php index 90e1488ed9..bbbb2d4451 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'] ?? ''; @@ -41,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.')); } @@ -54,12 +52,12 @@ class Recovery extends BaseModule public static function content(array $parameters = []) { if (!local_user()) { - self::getApp()->internalRedirect(); + DI::baseUrl()->redirect(); } // Already authenticated with 2FA token if (Session::get('2fa')) { - self::getApp()->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 10327aea59..8fc647472d 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'] ?? ''; @@ -39,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.'); } @@ -51,12 +50,12 @@ class Verify extends BaseModule public static function content(array $parameters = []) { if (!local_user()) { - self::getApp()->internalRedirect(); + DI::baseUrl()->redirect(); } // Already authenticated with 2FA token if (Session::get('2fa')) { - self::getApp()->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 e3c2b8d34c..9884876566 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.')); } @@ -54,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); @@ -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.')); - self::getApp()->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.')); } - self::getApp()->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.')); - self::getApp()->internalRedirect('settings/delegation'); + DI::baseUrl()->redirect('settings/delegation'); } DBA::delete('manage', ['uid' => $user_id, 'mid' => local_user()]); - self::getApp()->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 fe7423c5d2..a303862712 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::baseUrl()->redirect('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::baseUrl()->redirect('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::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.')); - self::getApp()->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.')); @@ -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::baseUrl()->redirect('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::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 03c866ce89..06e0e66d51 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::baseUrl()->redirect('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::baseUrl()->redirect('settings/2fa'); } break; case 'recovery': if ($has_secret) { - self::getApp()->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) { - self::getApp()->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) { - self::getApp()->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 8bd40bec98..492b96635b 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::baseUrl()->redirect('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::baseUrl()->redirect('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::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 28ee999d14..96feab825a 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::baseUrl()->redirect('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::baseUrl()->redirect('settings/2fa'); } } @@ -62,7 +63,7 @@ class Verify extends BaseSettingsModule notice(L10n::t('Two-factor authentication successfully activated.')); - self::getApp()->internalRedirect('settings/2fa'); + DI::baseUrl()->redirect('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..6c06f1133c 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; /** @@ -61,22 +62,22 @@ 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); - $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..0f111b21e0 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::baseUrl()->redirect($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..ce15426b8a 100644 --- a/src/Module/Statistics.php +++ b/src/Module/Statistics.php @@ -4,23 +4,22 @@ 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 = self::getApp()->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 = self::getApp()->getConfig(); - $logger = self::getApp()->getLogger(); + $config = DI::config(); + $logger = DI::logger(); $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..b28c98de7b 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::baseUrl()->redirect('profile/' . Config::get('system','singleuser')); } } diff --git a/src/Module/Welcome.php b/src/Module/Welcome.php index f69991e496..6182146337 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::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 cb344b695e..2bae006a70 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,8 +16,7 @@ class HostMeta extends BaseModule { public static function rawContent(array $parameters = []) { - $app = self::getApp(); - $config = $app->getConfig(); + $config = DI::config(); header('Content-type: text/xml'); @@ -29,9 +29,9 @@ class HostMeta extends BaseModule $tpl = Renderer::getMarkupTemplate('xrd_host.tpl'); echo Renderer::replaceMacros($tpl, [ - '$zhost' => $app->getHostName(), - '$zroot' => $app->getBaseURL(), - '$domain' => $app->getBaseURL(), + '$zhost' => DI::baseUrl()->getHostname()(), + '$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 7d87252edd..d0d2ea7a02 100644 --- a/src/Module/WellKnown/NodeInfo.php +++ b/src/Module/WellKnown/NodeInfo.php @@ -2,8 +2,8 @@ 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,26 +13,22 @@ class NodeInfo extends BaseModule { public static function rawContent(array $parameters = []) { - $app = self::getApp(); - - 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 5d8f4e817c..f9a806f03c 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,8 +14,7 @@ class XSocialRelay extends BaseModule { public static function rawContent(array $parameters = []) { - $app = self::getApp(); - $config = $app->getConfig(); + $config = DI::config(); $subscribe = $config->get('system', 'relay_subscribe', false); @@ -49,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 79e0883a87..0048350be8 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') { @@ -74,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/Network/FKOAuth1.php b/src/Network/FKOAuth1.php index a3dde38d26..26b5637a62 100644 --- a/src/Network/FKOAuth1.php +++ b/src/Network/FKOAuth1.php @@ -4,11 +4,9 @@ */ 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; use OAuthSignatureMethod_HMAC_SHA1; use OAuthSignatureMethod_PLAINTEXT; @@ -37,7 +35,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)) { @@ -46,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/Network/Probe.php b/src/Network/Probe.php index fac76e0dac..735c6a7434 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/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/Object/Post.php b/src/Object/Post.php index 259de94c0f..fd99a206de 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; @@ -18,6 +16,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; @@ -32,7 +31,7 @@ use Friendica\Util\Temporal; /** * An item */ -class Post extends BaseObject +class Post { private $data = []; private $template = null; @@ -121,7 +120,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; @@ -343,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); @@ -413,7 +409,7 @@ class Post extends BaseObject '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, @@ -427,7 +423,7 @@ class Post extends BaseObject '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, @@ -457,7 +453,7 @@ class Post extends BaseObject '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 @@ -550,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 @@ -815,7 +810,7 @@ class Post extends BaseObject */ private function getDefaultText() { - $a = self::getApp(); + $a = DI::app(); if (!local_user()) { return ''; @@ -862,7 +857,7 @@ class Post extends BaseObject */ private function getCommentBox($indent) { - $a = self::getApp(); + $a = DI::app(); $comment_box = ''; $conv = $this->getThread(); @@ -895,7 +890,7 @@ class Post extends BaseObject $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'), @@ -904,9 +899,9 @@ class Post extends BaseObject '$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'), @@ -945,7 +940,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..f88dee2c41 100644 --- a/src/Object/Thread.php +++ b/src/Object/Thread.php @@ -4,9 +4,9 @@ */ 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; @@ -15,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; @@ -52,7 +52,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..d345340f85 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; @@ -14,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\APContact; use Friendica\Model\Contact; use Friendica\Model\Conversation; @@ -204,7 +204,7 @@ class Transmitter { return ['type' => 'Service', 'name' => FRIENDICA_PLATFORM . " '" . FRIENDICA_CODENAME . "' " . FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION, - 'url' => BaseObject::getApp()->getBaseURL()]; + 'url' => DI::baseUrl()->get()]; } /** diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index f7a8f69390..e058854c94 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. @@ -2375,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']); 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/Util/Images.php b/src/Util/Images.php index c69c944c0e..e19304bba1 100644 --- a/src/Util/Images.php +++ b/src/Util/Images.php @@ -2,10 +2,10 @@ namespace Friendica\Util; -use Friendica\BaseObject; use Friendica\Core\Cache; use Friendica\Core\Logger; use Friendica\Core\System; +use Friendica\DI; use Imagick; /** @@ -165,7 +165,7 @@ class Images $stamp1 = microtime(true); file_put_contents($tempfile, $img_str); - BaseObject::getApp()->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; 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/src/Util/Proxy.php b/src/Util/Proxy.php index 9309887409..dab08b18bb 100644 --- a/src/Util/Proxy.php +++ b/src/Util/Proxy.php @@ -2,9 +2,9 @@ namespace Friendica\Util; -use Friendica\BaseObject; use Friendica\Core\Config; use Friendica\Core\System; +use Friendica\DI; /** * @brief Proxy utilities class @@ -63,7 +63,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/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 6928cb8d79..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; @@ -12,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\Contact; use Friendica\Util\DateTimeFormat; @@ -19,7 +19,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..6267bf6f33 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; @@ -14,6 +13,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 +29,7 @@ class CronJobs { public static function execute($command = '') { - $a = BaseObject::getApp(); + $a = DI::app(); // No parameter set? So return if ($command == '') { @@ -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/DBUpdate.php b/src/Worker/DBUpdate.php index 001df25a81..5f7dfcb796 100644 --- a/src/Worker/DBUpdate.php +++ b/src/Worker/DBUpdate.php @@ -5,17 +5,17 @@ */ 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() { // 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..ed2ff2979d 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -4,13 +4,13 @@ */ namespace Friendica\Worker; -use Friendica\BaseObject; use Friendica\Core\Config; use Friendica\Core\L10n; 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; @@ -20,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'; @@ -140,7 +140,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::baseUrl()->getHostname(); if (strpos($localhost, ':')) { $localhost = substr($localhost, 0, strpos($localhost, ':')); } @@ -548,7 +548,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..4abb6a2267 100644 --- a/src/Worker/Expire.php +++ b/src/Worker/Expire.php @@ -6,19 +6,19 @@ namespace Friendica\Worker; -use Friendica\BaseObject; use Friendica\Core\Config; 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..fea2da7e32 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -4,13 +4,13 @@ */ namespace Friendica\Worker; -use Friendica\BaseObject; use Friendica\Core\Config; use Friendica\Core\Hook; 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 +41,7 @@ class Notifier { public static function execute($cmd, $target_id) { - $a = BaseObject::getApp(); + $a = DI::app(); Logger::info('Invoked', ['cmd' => $cmd, 'target' => $target_id]); @@ -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,':')); } @@ -278,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 808d47299f..8bc45ee33a 100644 --- a/src/Worker/ProfileUpdate.php +++ b/src/Worker/ProfileUpdate.php @@ -6,9 +6,9 @@ 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 +18,7 @@ class ProfileUpdate { return; } - $a = BaseObject::getApp(); + $a = DI::app(); $inboxes = ActivityPub\Transmitter::fetchTargetInboxesforUser($uid); 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 f9b026979c..7948f09f60 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; @@ -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 @@ -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/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 c54135faee..8fce36955d 100644 --- a/tests/include/ApiTest.php +++ b/tests/include/ApiTest.php @@ -7,14 +7,14 @@ 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\Config\IConfiguration; +use Friendica\Core\Config\IPConfiguration; use Friendica\Core\Protocol; 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; @@ -47,7 +47,7 @@ class ApiTest extends DatabaseTest /** @var App */ protected $app; - /** @var Configuration */ + /** @var IConfiguration */ protected $config; /** @var Dice */ @@ -64,13 +64,13 @@ 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); - /** @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'); @@ -87,7 +87,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']; @@ -115,9 +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->start(); + DI::session()->start(); // Most API require login so we force the session $_SESSION = [ @@ -434,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) ); } @@ -458,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 = [ @@ -469,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) ); } @@ -492,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) ); } @@ -530,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) ); } @@ -554,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) ); } @@ -578,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) ); } @@ -603,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) ); } @@ -623,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) ); } @@ -643,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) ); } @@ -663,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()) ); } @@ -684,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()) ); } @@ -705,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()) ); } @@ -726,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()) ); } @@ -808,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); @@ -824,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'); @@ -843,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/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 @@ -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/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 3b41e4739c..dd7790e739 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; @@ -35,10 +34,10 @@ 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); - BaseObject::setDependencyInjection($dice); + DI::init($dice); } private function mockL10nT(string $text, $times = null) @@ -74,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)); } /** @@ -363,7 +364,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, @@ -386,7 +387,7 @@ 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, false, 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 a2291b2c24..51d3866fe7 100644 --- a/tests/src/Core/Lock/SemaphoreLockTest.php +++ b/tests/src/Core/Lock/SemaphoreLockTest.php @@ -4,29 +4,32 @@ namespace Friendica\Test\src\Core\Lock; use Dice\Dice; use Friendica\App; -use Friendica\BaseObject; -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(Configuration::class); + $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 - BaseObject::setDependencyInjection($dice); + DI::init($dice); parent::setUp(); } diff --git a/tests/src/Core/SystemTest.php b/tests/src/Core/SystemTest.php index a385d1b352..2f01df3446 100644 --- a/tests/src/Core/SystemTest.php +++ b/tests/src/Core/SystemTest.php @@ -2,11 +2,24 @@ 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 { + private function useBaseUrl() + { + $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); @@ -15,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'); } 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/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 03e415a99b..294be6b0b2 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; @@ -16,17 +16,16 @@ 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); - BaseObject::setDependencyInjection($dice); + 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) diff --git a/view/theme/frio/php/default.php b/view/theme/frio/php/default.php index 6b39e68acb..5579680a33 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,9 +20,9 @@ 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'; +$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"; ?> @@ -65,7 +66,7 @@ $is_singleuser_class = $is_singleuser ? "is-singleuser" : "is-not-singleuser"; ?> - "> + "> Skip to main content 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