From 9cec293cccf730a02ef2bc5d57b87a6cba44ea5e Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Sun, 15 Dec 2019 23:52:15 +0100 Subject: [PATCH] Refactor dynamic App::getMode() to static DI::mode() --- bin/daemon.php | 7 ++++--- bin/worker.php | 9 +++++---- src/App.php | 10 ---------- src/Core/Worker.php | 4 ++-- src/Module/Admin/Summary.php | 2 +- src/Module/Install.php | 2 +- 6 files changed, 13 insertions(+), 21 deletions(-) diff --git a/bin/daemon.php b/bin/daemon.php index 039a40cf06..f0154e74e8 100755 --- a/bin/daemon.php +++ b/bin/daemon.php @@ -12,6 +12,7 @@ use Friendica\Core\Config; use Friendica\Core\Logger; use Friendica\Core\Worker; use Friendica\Database\DBA; +use Friendica\DI; use Psr\Log\LoggerInterface; // Get options @@ -36,10 +37,10 @@ require dirname(__DIR__) . '/vendor/autoload.php'; $dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php'); $dice = $dice->addRule(LoggerInterface::class,['constructParams' => ['daemon']]); -\Friendica\DI::init($dice); -$a = \Friendica\DI::app(); +DI::init($dice); +$a = DI::app(); -if ($a->getMode()->isInstall()) { +if (DI::mode()->isInstall()) { die("Friendica isn't properly installed yet.\n"); } diff --git a/bin/worker.php b/bin/worker.php index e156170490..a478159195 100755 --- a/bin/worker.php +++ b/bin/worker.php @@ -10,6 +10,7 @@ use Friendica\App; use Friendica\Core\Config; use Friendica\Core\Update; use Friendica\Core\Worker; +use Friendica\DI; use Psr\Log\LoggerInterface; // Get options @@ -34,14 +35,14 @@ require dirname(__DIR__) . '/vendor/autoload.php'; $dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php'); $dice = $dice->addRule(LoggerInterface::class,['constructParams' => ['worker']]); -\Friendica\DI::init($dice); -$a = Friendica\DI::app(); +DI::init($dice); +$a = DI::app(); // Check the database structure and possibly fixes it -Update::check($a->getBasePath(), true, $a->getMode()); +Update::check($a->getBasePath(), true, DI::mode()); // Quit when in maintenance -if (!$a->getMode()->has(App\Mode::MAINTENANCEDISABLED)) { +if (!DI::mode()->has(App\Mode::MAINTENANCEDISABLED)) { return; } diff --git a/src/App.php b/src/App.php index 6c88c6c947..c0787a460e 100644 --- a/src/App.php +++ b/src/App.php @@ -155,16 +155,6 @@ class App return $this->config->getCache()->get('system', 'basepath'); } - /** - * Returns the Mode of the Application - * - * @return App\Mode The Application Mode - */ - public function getMode() - { - return $this->mode; - } - /** * Returns the Database of the Application * diff --git a/src/Core/Worker.php b/src/Core/Worker.php index fc30ce12d5..9a1570d72f 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -1086,7 +1086,7 @@ class Worker $args = ['no_cron' => !$do_cron]; $a = get_app(); - $process = new Core\Process(DI::logger(), $a->getMode(), DI::config(), $a->getBasePath()); + $process = new Core\Process(DI::logger(), DI::mode(), DI::config(), $a->getBasePath()); $process->run($command, $args); // after spawning we have to remove the flag. @@ -1129,7 +1129,7 @@ class Worker $priority = PRIORITY_MEDIUM; // Don't fork from frontend tasks by default - $dont_fork = Config::get("system", "worker_dont_fork", false) || !\get_app()->getMode()->isBackend(); + $dont_fork = Config::get("system", "worker_dont_fork", false) || !DI::mode()->isBackend(); $created = DateTimeFormat::utcNow(); $force_priority = false; diff --git a/src/Module/Admin/Summary.php b/src/Module/Admin/Summary.php index d634b89fbf..9853ce951b 100644 --- a/src/Module/Admin/Summary.php +++ b/src/Module/Admin/Summary.php @@ -111,7 +111,7 @@ class Summary extends BaseAdminModule } // check legacy basepath settings - $configLoader = new ConfigFileLoader($a->getBasePath(), $a->getMode()); + $configLoader = new ConfigFileLoader($a->getBasePath()); $configCache = new Config\Cache\ConfigCache(); $configLoader->setupCache($configCache); $confBasepath = $configCache->get('system', 'basepath'); diff --git a/src/Module/Install.php b/src/Module/Install.php index 107f83e77d..29fbdacbc0 100644 --- a/src/Module/Install.php +++ b/src/Module/Install.php @@ -51,7 +51,7 @@ class Install extends BaseModule { $a = DI::app(); - if (!$a->getMode()->isInstall()) { + if (!DI::mode()->isInstall()) { throw new HTTPException\ForbiddenException(); }