From ae75ffc31ab7a486332c68fff165c88b8d741d1c Mon Sep 17 00:00:00 2001 From: Art4 Date: Sun, 10 Nov 2024 10:57:13 +0000 Subject: [PATCH] replace calls for App::getBasePath() with AppHelper --- src/Console/DocBloxErrorChecker.php | 12 ++++++------ src/Console/PostUpdate.php | 16 ++++++++++------ src/Core/Hook.php | 6 +++--- src/Module/Admin/Summary.php | 4 ++-- src/Module/Home.php | 6 +++--- src/Worker/Cron.php | 3 +-- src/Worker/DBUpdate.php | 2 +- 7 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/Console/DocBloxErrorChecker.php b/src/Console/DocBloxErrorChecker.php index 2b16b6694b..694940c95e 100644 --- a/src/Console/DocBloxErrorChecker.php +++ b/src/Console/DocBloxErrorChecker.php @@ -7,7 +7,7 @@ namespace Friendica\Console; -use Friendica\App; +use Friendica\AppHelper; /** * When I installed docblox, I had the experience that it does not generate any output at all. @@ -33,14 +33,14 @@ class DocBloxErrorChecker extends \Asika\SimpleConsole\Console protected $helpOptions = ['h', 'help', '?']; - /** @var App */ - private $app; + /** @var string */ + private $basePath; - public function __construct(App $app, array $argv = null) + public function __construct(AppHelper $appHelper, array $argv = null) { parent::__construct($argv); - $this->app = $app; + $this->basePath = $appHelper->getBasePath(); } protected function getHelp() @@ -73,7 +73,7 @@ HELP; throw new \RuntimeException('DocBlox isn\'t available.'); } - $dir = $this->app->getBasePath(); + $dir = $this->basePath; //stack for dirs to search $dirstack = []; diff --git a/src/Console/PostUpdate.php b/src/Console/PostUpdate.php index 90c75bb343..2d0357a460 100644 --- a/src/Console/PostUpdate.php +++ b/src/Console/PostUpdate.php @@ -7,10 +7,11 @@ namespace Friendica\Console; -use Friendica\App; +use Friendica\App\Mode; use Friendica\Core\KeyValueStorage\Capability\IManageKeyValuePairs; use Friendica\Core\L10n; use Friendica\Core\Update; +use Friendica\DI; /** * Performs database post updates @@ -20,7 +21,7 @@ class PostUpdate extends \Asika\SimpleConsole\Console protected $helpOptions = ['h', 'help', '?']; /** - * @var App\Mode + * @var Mode */ private $appMode; /** @@ -31,6 +32,10 @@ class PostUpdate extends \Asika\SimpleConsole\Console * @var L10n */ private $l10n; + /** + * @var string + */ + private $basePath; protected function getHelp() { @@ -46,19 +51,18 @@ HELP; return $help; } - public function __construct(App\Mode $appMode, IManageKeyValuePairs $keyValue, L10n $l10n, array $argv = null) + public function __construct(Mode $appMode, IManageKeyValuePairs $keyValue, L10n $l10n, array $argv = null) { parent::__construct($argv); $this->appMode = $appMode; $this->keyValue = $keyValue; $this->l10n = $l10n; + $this->basePath = DI::apphelper()->getBasePath(); } protected function doExecute(): int { - $a = \Friendica\DI::app(); - if ($this->getOption($this->helpOptions)) { $this->out($this->getHelp()); return 0; @@ -79,7 +83,7 @@ HELP; } echo $this->l10n->t('Check for pending update actions.') . "\n"; - Update::run($a->getBasePath(), true, false, true, false); + Update::run($this->basePath, true, false, true, false); echo $this->l10n->t('Done.') . "\n"; echo $this->l10n->t('Execute pending post updates.') . "\n"; diff --git a/src/Core/Hook.php b/src/Core/Hook.php index 74256b11ec..c3c994a314 100644 --- a/src/Core/Hook.php +++ b/src/Core/Hook.php @@ -81,7 +81,7 @@ class Hook */ public static function register(string $hook, string $file, string $function, int $priority = 0) { - $file = str_replace(DI::app()->getBasePath() . DIRECTORY_SEPARATOR, '', $file); + $file = str_replace(DI::apphelper()->getBasePath() . DIRECTORY_SEPARATOR, '', $file); $condition = ['hook' => $hook, 'file' => $file, 'function' => $function]; if (DBA::exists('hook', $condition)) { @@ -102,7 +102,7 @@ class Hook */ public static function unregister(string $hook, string $file, string $function): bool { - $relative_file = str_replace(DI::app()->getBasePath() . DIRECTORY_SEPARATOR, '', $file); + $relative_file = str_replace(DI::apphelper()->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]; @@ -198,7 +198,7 @@ class Hook public static function callSingle(string $name, array $hook, &$data = null) { // Don't run a theme's hook if the user isn't using the theme - if (strpos($hook[0], 'view/theme/') !== false && strpos($hook[0], 'view/theme/' . DI::app()->getCurrentTheme()) === false) { + if (strpos($hook[0], 'view/theme/') !== false && strpos($hook[0], 'view/theme/' . DI::apphelper()->getCurrentTheme()) === false) { return; } diff --git a/src/Module/Admin/Summary.php b/src/Module/Admin/Summary.php index 16e376faf1..04980f55bf 100644 --- a/src/Module/Admin/Summary.php +++ b/src/Module/Admin/Summary.php @@ -29,7 +29,7 @@ class Summary extends BaseAdmin { parent::content(); - $a = DI::app(); + $basePath = DI::apphelper()->getBasePath(); // are there MyISAM tables in the DB? If so, trigger a warning message $warningtext = []; @@ -120,7 +120,7 @@ class Summary extends BaseAdmin } // check legacy basepath settings - $configLoader = (new Config())->createConfigFileManager($a->getBasePath(), $_SERVER); + $configLoader = (new Config())->createConfigFileManager($basePath, $_SERVER); $configCache = new Cache(); $configLoader->setupCache($configCache); $confBasepath = $configCache->get('system', 'basepath'); diff --git a/src/Module/Home.php b/src/Module/Home.php index 2d79148c58..94cb08773e 100644 --- a/src/Module/Home.php +++ b/src/Module/Home.php @@ -32,7 +32,7 @@ class Home extends BaseModule protected function content(array $request = []): string { - $app = DI::app(); + $basePath = DI::apphelper()->getBasePath(); $config = DI::config(); // currently no returned data is used @@ -51,8 +51,8 @@ class Home extends BaseModule $customHome = ''; $defaultHeader = ($config->get('config', 'sitename') ? DI::l10n()->t('Welcome to %s', $config->get('config', 'sitename')) : ''); - $homeFilePath = $app->getBasePath() . '/home.html'; - $cssFilePath = $app->getBasePath() . '/home.css'; + $homeFilePath = $basePath . '/home.html'; + $cssFilePath = $basePath . '/home.css'; if (file_exists($homeFilePath)) { $customHome = $homeFilePath; diff --git a/src/Worker/Cron.php b/src/Worker/Cron.php index 1c21bf5065..e6d11db370 100644 --- a/src/Worker/Cron.php +++ b/src/Worker/Cron.php @@ -21,7 +21,7 @@ class Cron { public static function execute() { - $a = DI::app(); + $basepath = DI::apphelper()->getBasePath(); $last = DI::keyValue()->get('last_cron'); @@ -39,7 +39,6 @@ class Cron // Ensure to have a .htaccess file. // this is a precaution for systems that update automatically - $basepath = $a->getBasePath(); if (!file_exists($basepath . '/.htaccess') && is_writable($basepath)) { copy($basepath . '/.htaccess-dist', $basepath . '/.htaccess'); } diff --git a/src/Worker/DBUpdate.php b/src/Worker/DBUpdate.php index cea9df49c0..87a3fae27f 100644 --- a/src/Worker/DBUpdate.php +++ b/src/Worker/DBUpdate.php @@ -19,7 +19,7 @@ class DBUpdate { // Just in case the last update wasn't failed if (DI::config()->get('system', 'update', Update::SUCCESS) != Update::FAILED) { - Update::run(DI::app()->getBasePath()); + Update::run(DI::apphelper()->getBasePath()); } } }