From d54e07fc16584743de34ac53dfae773a047814aa Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Fri, 20 Jan 2023 21:54:14 +0100 Subject: [PATCH] testing NsClass --- _admin.php | 20 -------------------- _config.php | 19 ------------------- _install.php | 20 -------------------- _prepend.php | 22 ---------------------- _uninstall.php | 24 ------------------------ inc/Action.php | 2 +- inc/Admin.php | 17 +++++++++-------- inc/Config.php | 15 ++++++++------- inc/Core.php | 2 +- inc/Install.php | 8 +++----- inc/Manage.php | 9 ++++++--- inc/Utils.php | 33 ++------------------------------- index.php | 19 ------------------- 13 files changed, 30 insertions(+), 180 deletions(-) delete mode 100644 _admin.php delete mode 100644 _config.php delete mode 100644 _install.php delete mode 100644 _prepend.php delete mode 100644 _uninstall.php delete mode 100644 index.php diff --git a/_admin.php b/_admin.php deleted file mode 100644 index 817be6d..0000000 --- a/_admin.php +++ /dev/null @@ -1,20 +0,0 @@ -class_name = str_replace(Prepend::getActionsNS(), '', get_called_class()); + $this->class_name = str_replace(Utils::getActionsNS(), '', get_called_class()); $settings = dcCore::app()->blog->settings->get(Core::id())->get('settings_' . $this->class_name); if (null != $settings) { diff --git a/inc/Admin.php b/inc/Admin.php index d04aaad..434899b 100644 --- a/inc/Admin.php +++ b/inc/Admin.php @@ -19,6 +19,7 @@ use dcAdmin; use dcCore; use dcPage; use dcFavorites; +use dcNsProcess; /* clearbricks */ use Clearbricks; @@ -29,10 +30,8 @@ use files; * * Add menu and dashboard icons, load Improve action modules. */ -class Admin +class Admin extends dcNsProcess { - protected static $init = false; - public static function init(): bool { if (defined('DC_CONTEXT_ADMIN')) { @@ -42,7 +41,7 @@ class Admin return self::$init; } - public static function process() + public static function process(): bool { if (!self::$init) { return false; @@ -69,11 +68,13 @@ class Admin dcCore::app()->auth->isSuperAdmin() ); - foreach (files::scandir(Prepend::getActionsDir()) as $file) { - if (is_file(Prepend::getActionsDir() . $file) && '.php' == substr($file, -4)) { - Clearbricks::lib()->autoload([Prepend::getActionsNS() . substr($file, 0, -4) => Prepend::getActionsDir() . $file]); - dcCore::app()->addBehavior('improveAddAction', [Prepend::getActionsNS() . substr($file, 0, -4), 'create']); /* @phpstan-ignore-line */ + foreach (files::scandir(Utils::getActionsDir()) as $file) { + if (is_file(Utils::getActionsDir() . $file) && '.php' == substr($file, -4)) { + Clearbricks::lib()->autoload([Utils::getActionsNS() . substr($file, 0, -4) => Utils::getActionsDir() . $file]); + dcCore::app()->addBehavior('improveAddAction', [Utils::getActionsNS() . substr($file, 0, -4), 'create']); /* @phpstan-ignore-line */ } } + + return true; } } diff --git a/inc/Config.php b/inc/Config.php index 13be04a..e70af82 100644 --- a/inc/Config.php +++ b/inc/Config.php @@ -17,6 +17,7 @@ namespace Dotclear\Plugin\improve; /* dotclear */ use dcCore; use dcPage; +use dcNsProcess; /* clearbricks */ use form; @@ -29,10 +30,8 @@ use Exception; * * Set preference for this plugin. */ -class Config +class Config extends dcNsProcess { - protected static $init = false; - public static function init(): bool { if (defined('DC_CONTEXT_ADMIN')) { @@ -43,14 +42,14 @@ class Config return self::$init; } - public static function process(): void + public static function process(): bool { if (!self::$init) { - return; + return false; } if (empty($_POST['save'])) { - return; + return true; } try { @@ -70,9 +69,11 @@ class Config } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } + + return true; } - public static function render() + public static function render(): void { if (!self::$init) { return; diff --git a/inc/Core.php b/inc/Core.php index 63d8193..cff7d60 100644 --- a/inc/Core.php +++ b/inc/Core.php @@ -76,7 +76,7 @@ class Core public static function id() { - return basename(dirname(dirname(__DIR__))); + return basename(dirname(__DIR__)); } public function getLogs(): array diff --git a/inc/Install.php b/inc/Install.php index da88bb0..9da1345 100644 --- a/inc/Install.php +++ b/inc/Install.php @@ -16,6 +16,7 @@ namespace Dotclear\Plugin\improve; /* dotclear */ use dcCore; +use dcNsProcess; /* php */ use Exception; @@ -26,7 +27,7 @@ use Exception; * Set default settings and version * and manage changes on updates. */ -class Install +class Install extends dcNsProcess { /** @var array Improve default settings */ private static $default_settings = [[ @@ -36,9 +37,6 @@ class Install 'string', ]]; - // Nothing to change below - protected static $init = false; - public static function init(): bool { self::$init = defined('DC_CONTEXT_ADMIN') && dcCore::app()->newVersion(Core::id(), dcCore::app()->plugins->moduleInfo(Core::id(), 'version')); @@ -46,7 +44,7 @@ class Install return self::$init; } - public static function process(): ?bool + public static function process(): bool { if (!self::$init) { return false; diff --git a/inc/Manage.php b/inc/Manage.php index 816a867..ed9c868 100644 --- a/inc/Manage.php +++ b/inc/Manage.php @@ -20,6 +20,7 @@ use dcPage; use dcAdminNotices; use dcThemes; use dcUtils; +use dcNsProcess; /* clearbricks */ use html; @@ -34,7 +35,7 @@ use Exception; * Display page and configure modules * and launch action. */ -class Manage +class Manage extends dcNsProcess { /** @var Core $improve improve core instance */ private static $improve = null; @@ -162,10 +163,10 @@ class Manage return null; } - public static function process(): void + public static function process(): bool { if (!self::$init) { - return; + return false; } $log_id = ''; @@ -209,6 +210,8 @@ class Manage if ($done) { dcCore::app()->adminurl->redirect('admin.plugin.' . Core::id(), ['type' => self::$type, 'module' => self::$module, 'upd' => $log_id]); } + + return true; } public static function render(): void diff --git a/inc/Utils.php b/inc/Utils.php index 93c3956..99c34a7 100644 --- a/inc/Utils.php +++ b/inc/Utils.php @@ -14,40 +14,11 @@ declare(strict_types=1); namespace Dotclear\Plugin\improve; -use Clearbricks; - /** - * Improve prepend class - * - * Manage autoload and some action module helpers. + * Improve utils class */ -class Prepend +class Utils { - protected static $init = false; - - public static function init(): bool - { - self::$init = defined('DC_RC_PATH') && defined('DC_CONTEXT_ADMIN'); - - return self::$init; - } - - public static function process() - { - if (!self::$init) { - return false; - } - - // Core plugin class - foreach (['Core', 'Action', 'Module'] as $class) { - Clearbricks::lib()->autoload([__NAMESPACE__ . '\\' . $class => implode(DIRECTORY_SEPARATOR, [__DIR__, 'core', $class . '.php'])]); - } - - // Dotclear plugin class - foreach (['Admin', 'Config', 'Install', 'Manage', 'Prepend', 'Uninstall'] as $class) { - Clearbricks::lib()->autoload([__NAMESPACE__ . '\\' . $class => implode(DIRECTORY_SEPARATOR, [__DIR__, $class . '.php'])]); - } - } public static function getActionsDir(): string { diff --git a/index.php b/index.php deleted file mode 100644 index f250cd9..0000000 --- a/index.php +++ /dev/null @@ -1,19 +0,0 @@ -