Refactor dynamic App::getMode() to static DI::mode()

This commit is contained in:
nupplaPhil 2019-12-15 23:52:15 +01:00
parent 181529f3df
commit 9cec293ccc
No known key found for this signature in database
GPG Key ID: D8365C3D36B77D90
6 changed files with 13 additions and 21 deletions

View File

@ -12,6 +12,7 @@ use Friendica\Core\Config;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Core\Worker; use Friendica\Core\Worker;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
// Get options // Get options
@ -36,10 +37,10 @@ require dirname(__DIR__) . '/vendor/autoload.php';
$dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php'); $dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php');
$dice = $dice->addRule(LoggerInterface::class,['constructParams' => ['daemon']]); $dice = $dice->addRule(LoggerInterface::class,['constructParams' => ['daemon']]);
\Friendica\DI::init($dice); DI::init($dice);
$a = \Friendica\DI::app(); $a = DI::app();
if ($a->getMode()->isInstall()) { if (DI::mode()->isInstall()) {
die("Friendica isn't properly installed yet.\n"); die("Friendica isn't properly installed yet.\n");
} }

View File

@ -10,6 +10,7 @@ use Friendica\App;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Core\Update; use Friendica\Core\Update;
use Friendica\Core\Worker; use Friendica\Core\Worker;
use Friendica\DI;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
// Get options // Get options
@ -34,14 +35,14 @@ require dirname(__DIR__) . '/vendor/autoload.php';
$dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php'); $dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php');
$dice = $dice->addRule(LoggerInterface::class,['constructParams' => ['worker']]); $dice = $dice->addRule(LoggerInterface::class,['constructParams' => ['worker']]);
\Friendica\DI::init($dice); DI::init($dice);
$a = Friendica\DI::app(); $a = DI::app();
// Check the database structure and possibly fixes it // 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 // Quit when in maintenance
if (!$a->getMode()->has(App\Mode::MAINTENANCEDISABLED)) { if (!DI::mode()->has(App\Mode::MAINTENANCEDISABLED)) {
return; return;
} }

View File

@ -155,16 +155,6 @@ class App
return $this->config->getCache()->get('system', 'basepath'); return $this->config->getCache()->get('system', 'basepath');
} }
/**
* Returns the Mode of the Application
*
* @return App\Mode The Application Mode
*/
public function getMode()
{
return $this->mode;
}
/** /**
* Returns the Database of the Application * Returns the Database of the Application
* *

View File

@ -1086,7 +1086,7 @@ class Worker
$args = ['no_cron' => !$do_cron]; $args = ['no_cron' => !$do_cron];
$a = get_app(); $a = get_app();
$process = new Core\Process(DI::logger(), $a->getMode(), DI::config(), $a->getBasePath()); $process = new Core\Process(DI::logger(), DI::mode(), DI::config(), $a->getBasePath());
$process->run($command, $args); $process->run($command, $args);
// after spawning we have to remove the flag. // after spawning we have to remove the flag.
@ -1129,7 +1129,7 @@ class Worker
$priority = PRIORITY_MEDIUM; $priority = PRIORITY_MEDIUM;
// Don't fork from frontend tasks by default // 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(); $created = DateTimeFormat::utcNow();
$force_priority = false; $force_priority = false;

View File

@ -111,7 +111,7 @@ class Summary extends BaseAdminModule
} }
// check legacy basepath settings // check legacy basepath settings
$configLoader = new ConfigFileLoader($a->getBasePath(), $a->getMode()); $configLoader = new ConfigFileLoader($a->getBasePath());
$configCache = new Config\Cache\ConfigCache(); $configCache = new Config\Cache\ConfigCache();
$configLoader->setupCache($configCache); $configLoader->setupCache($configCache);
$confBasepath = $configCache->get('system', 'basepath'); $confBasepath = $configCache->get('system', 'basepath');

View File

@ -51,7 +51,7 @@ class Install extends BaseModule
{ {
$a = DI::app(); $a = DI::app();
if (!$a->getMode()->isInstall()) { if (!DI::mode()->isInstall()) {
throw new HTTPException\ForbiddenException(); throw new HTTPException\ForbiddenException();
} }