Refactor dynamic App::getConfig() to static DI::config()

This commit is contained in:
Philipp Holzer 2019-12-15 23:44:33 +01:00
parent 2bb9e46be3
commit fceb4f3823
No known key found for this signature in database
GPG key ID: D8365C3D36B77D90
21 changed files with 38 additions and 66 deletions

View file

@ -144,16 +144,6 @@ class App
return $this->config->getCache();
}
/**
* Returns the current config of this node
*
* @return Configuration
*/
public function getConfig()
{
return $this->config;
}
/**
* The basepath of this app
*

View file

@ -92,8 +92,7 @@ class Search
*/
public static function getContactsFromGlobalDirectory($search, $type = self::TYPE_ALL, $page = 1)
{
$config = DI::app()->getConfig();
$server = $config->get('system', 'directory', self::DEFAULT_DIRECTORY);
$server = DI::config()->get('system', 'directory', self::DEFAULT_DIRECTORY);
$searchUrl = $server . '/search';
@ -158,7 +157,7 @@ class Search
*/
public static function getContactsFromLocalDirectory($search, $type = self::TYPE_ALL, $start = 0, $itemPage = 80)
{
$config = DI::app()->getConfig();
$config = DI::config();
$diaspora = $config->get('system', 'diaspora_enabled') ? Protocol::DIASPORA : Protocol::DFRN;
$ostatus = !$config->get('system', 'ostatus_disabled') ? Protocol::OSTATUS : Protocol::DFRN;

View file

@ -1086,7 +1086,7 @@ class Worker
$args = ['no_cron' => !$do_cron];
$a = get_app();
$process = new Core\Process($a->getLogger(), $a->getMode(), $a->getConfig(), $a->getBasePath());
$process = new Core\Process($a->getLogger(), $a->getMode(), DI::config(), $a->getBasePath());
$process->run($command, $args);
// after spawning we have to remove the flag.

View file

@ -19,7 +19,7 @@ class Nodeinfo
public static function update()
{
$app = DI::app();
$config = $app->getConfig();
$config = DI::config();
$logger = $app->getLogger();
// If the addon 'statistics_json' is enabled then disable it and activate nodeinfo.

View file

@ -115,7 +115,7 @@ class Summary extends BaseAdminModule
$configCache = new Config\Cache\ConfigCache();
$configLoader->setupCache($configCache);
$confBasepath = $configCache->get('system', 'basepath');
$currBasepath = $a->getConfig()->get('system', 'basepath');
$currBasepath = DI::config()->get('system', 'basepath');
if ($confBasepath !== $currBasepath || !is_dir($currBasepath)) {
if (is_dir($confBasepath) && Config::set('system', 'basepath', $confBasepath)) {
$a->getLogger()->info('Friendica\'s system.basepath was updated successfully.', [

View file

@ -35,7 +35,7 @@ class BaseSearchModule extends BaseModule
public static function performContactSearch($search, $prefix = '')
{
$a = DI::app();
$config = $a->getConfig();
$config = DI::config();
$type = Search::TYPE_ALL;

View file

@ -21,7 +21,7 @@ class Bookmarklet extends BaseModule
$_GET['mode'] = 'minimal';
$app = DI::app();
$config = $app->getConfig();
$config = DI::config();
if (!local_user()) {
$output = '<h2>' . L10n::t('Login') . '</h2>';

View file

@ -25,7 +25,7 @@ class Directory extends BaseModule
public static function content(array $parameters = [])
{
$app = DI::app();
$config = $app->getConfig();
$config = DI::config();
if (($config->get('system', 'block_public') && !Session::isAuthenticated()) ||
($config->get('system', 'block_local_dir') && !Session::isAuthenticated())) {

View file

@ -19,7 +19,7 @@ class Friendica extends BaseModule
public static function content(array $parameters = [])
{
$app = DI::app();
$config = $app->getConfig();
$config = DI::config();
$visibleAddonList = Addon::getVisibleList();
if (!empty($visibleAddonList)) {
@ -98,7 +98,7 @@ class Friendica extends BaseModule
return;
}
$config = $app->getConfig();
$config = DI::config();
$register_policies = [
Register::CLOSED => 'REGISTER_CLOSED',

View file

@ -23,7 +23,7 @@ class Help extends BaseModule
$filename = '';
$a = DI::app();
$config = $a->getConfig();
$config = DI::config();
$lang = $config->get('system', 'language');
// @TODO: Replace with parameter from router

View file

@ -17,7 +17,7 @@ class Home extends BaseModule
public static function content(array $parameters = [])
{
$app = DI::app();
$config = $app->getConfig();
$config = DI::config();
// currently no returned data is used
$ret = [];

View file

@ -26,7 +26,7 @@ class Invite extends BaseModule
self::checkFormSecurityTokenRedirectOnError('/', 'send_invite');
$app = DI::app();
$config = $app->getConfig();
$config = DI::config();
$max_invites = intval($config->get('system', 'max_invites'));
if (!$max_invites) {
@ -112,7 +112,7 @@ class Invite extends BaseModule
}
$app = DI::app();
$config = $app->getConfig();
$config = DI::config();
$inviteOnly = false;

View file

@ -17,9 +17,7 @@ class Maintenance extends BaseModule
{
public static function content(array $parameters = [])
{
$config = DI::app()->getConfig();
$reason = $config->get('system', 'maintenance_reason');
$reason = DI::config()->get('system', 'maintenance_reason');
if ((substr(Strings::normaliseLink($reason), 0, 7) === 'http://') ||
(substr(Strings::normaliseLink($reason), 0, 8) === 'https://')) {

View file

@ -10,8 +10,7 @@ class Manifest extends BaseModule
{
public static function rawContent(array $parameters = [])
{
$app = DI::app();
$config = $app->getConfig();
$config = DI::config();
$tpl = Renderer::getMarkupTemplate('manifest.tpl');

View file

@ -2,10 +2,8 @@
namespace Friendica\Module;
use Friendica\App;
use Friendica\BaseModule;
use Friendica\Core\Addon;
use Friendica\Core\System;
use Friendica\DI;
/**
@ -16,12 +14,10 @@ class NodeInfo extends BaseModule
{
public static function rawContent(array $parameters = [])
{
$app = DI::app();
if ($parameters['version'] == '1.0') {
self::printNodeInfo1($app);
self::printNodeInfo1();
} elseif ($parameters['version'] == '2.0') {
self::printNodeInfo2($app);
self::printNodeInfo2();
} else {
throw new \Friendica\Network\HTTPException\NotFoundException();
}
@ -30,13 +26,11 @@ class NodeInfo extends BaseModule
/**
* Return the supported services
*
* @param App $app
*
* @return array with supported services
*/
private static function getUsage(App $app)
private static function getUsage()
{
$config = $app->getConfig();
$config = DI::config();
$usage = [];
@ -56,11 +50,9 @@ class NodeInfo extends BaseModule
/**
* Return the supported services
*
* @param App $app
*
* @return array with supported services
*/
private static function getServices(App $app)
private static function getServices()
{
$services = [
'inbound' => [],
@ -117,12 +109,10 @@ class NodeInfo extends BaseModule
/**
* Print the nodeinfo version 1
*
* @param App $app
*/
private static function printNodeInfo1(App $app)
private static function printNodeInfo1()
{
$config = $app->getConfig();
$config = DI::config();
$nodeinfo = [
'version' => '1.0',
@ -156,9 +146,9 @@ class NodeInfo extends BaseModule
$nodeinfo['protocols']['outbound'][] = 'gnusocial';
}
$nodeinfo['usage'] = self::getUsage($app);
$nodeinfo['usage'] = self::getUsage();
$nodeinfo['services'] = self::getServices($app);
$nodeinfo['services'] = self::getServices();
$nodeinfo['metadata']['protocols'] = $nodeinfo['protocols'];
$nodeinfo['metadata']['protocols']['outbound'][] = 'atom1.0';
@ -180,12 +170,10 @@ class NodeInfo extends BaseModule
/**
* Print the nodeinfo version 2
*
* @param App $app
*/
private static function printNodeInfo2(App $app)
private static function printNodeInfo2()
{
$config = $app->getConfig();
$config = DI::config();
$imap = (function_exists('imap_open') && !$config->get('system', 'imap_disabled') && !$config->get('system', 'dfrn_only'));
@ -212,9 +200,9 @@ class NodeInfo extends BaseModule
$nodeinfo['protocols'][] = 'ostatus';
}
$nodeinfo['usage'] = self::getUsage($app);
$nodeinfo['usage'] = self::getUsage();
$nodeinfo['services'] = self::getServices($app);
$nodeinfo['services'] = self::getServices();
if (Addon::isEnabled('twitter')) {
$nodeinfo['services']['inbound'][] = 'twitter';

View file

@ -198,7 +198,7 @@ class Register extends BaseModule
$arr['blocked'] = $blocked;
$arr['verified'] = $verified;
$arr['language'] = L10nClass::detectLanguage($_SERVER, $_GET, $a->getConfig()->get('system', 'language'));
$arr['language'] = L10nClass::detectLanguage($_SERVER, $_GET, DI::config()->get('system', 'language'));
try {
$result = Model\User::create($arr);

View file

@ -88,7 +88,7 @@ class Login extends BaseModule
}
$reg = false;
if ($register && intval($a->getConfig()->get('config', 'register_policy')) !== Register::CLOSED) {
if ($register && intval(DI::config()->get('config', 'register_policy')) !== Register::CLOSED) {
$reg = [
'title' => L10n::t('Create a New Account'),
'desc' => L10n::t('Register'),

View file

@ -4,23 +4,21 @@ namespace Friendica\Module;
use Friendica\BaseModule;
use Friendica\Core\Addon;
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Network\HTTPException\NotFoundException;
class Statistics extends BaseModule
{
public static function init(array $parameters = [])
{
$config = DI::app()->getConfig();
if (!$config->get("system", "nodeinfo")) {
throw new \Friendica\Network\HTTPException\NotFoundException();
if (!DI::config()->get("system", "nodeinfo")) {
throw new NotFoundException();
}
}
public static function rawContent(array $parameters = [])
{
$config = DI::app()->getConfig();
$config = DI::config();
$logger = DI::app()->getLogger();
$registration_open =

View file

@ -14,7 +14,7 @@ class Welcome extends BaseModule
{
public static function content(array $parameters = [])
{
$config = DI::app()->getConfig();
$config = DI::config();
$mail_disabled = ((function_exists('imap_open') &&
(!$config->get('system', 'imap_disabled'))));

View file

@ -17,7 +17,7 @@ class HostMeta extends BaseModule
public static function rawContent(array $parameters = [])
{
$app = DI::app();
$config = $app->getConfig();
$config = DI::config();
header('Content-type: text/xml');

View file

@ -15,7 +15,7 @@ class XSocialRelay extends BaseModule
public static function rawContent(array $parameters = [])
{
$app = DI::app();
$config = $app->getConfig();
$config = DI::config();
$subscribe = $config->get('system', 'relay_subscribe', false);