From 86da84f2ad6f0001e1500624f63c7527ebfcf454 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sun, 19 Mar 2023 23:40:08 +0100 Subject: [PATCH] fix init check --- src/Backend.php | 10 +++++----- src/Config.php | 16 ++++++---------- src/Install.php | 11 +++++------ src/Manage.php | 12 ++++++------ src/My.php | 14 ++++++++++++++ 5 files changed, 36 insertions(+), 27 deletions(-) diff --git a/src/Backend.php b/src/Backend.php index cb0c6d4..7bd18a9 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -24,16 +24,16 @@ class Backend extends dcNsProcess { public static function init(): bool { - if (defined('DC_CONTEXT_ADMIN')) { - self::$init = dcCore::app()->auth->isSuperAdmin() && version_compare(phpversion(), My::PHP_MIN, '>='); - } + static::$init == defined('DC_CONTEXT_ADMIN') + && dcCore::app()->auth?->isSuperAdmin() + && My::phpCompliant(); - return self::$init; + return static::$init; } public static function process(): bool { - if (!self::$init) { + if (!static::$init) { return false; } diff --git a/src/Config.php b/src/Config.php index 41364e7..8dec66c 100644 --- a/src/Config.php +++ b/src/Config.php @@ -33,20 +33,16 @@ class Config extends dcNsProcess { public static function init(): bool { - if (defined('DC_CONTEXT_ADMIN')) { - if (version_compare(phpversion(), My::PHP_MIN, '>=')) { - self::$init = true; - } else { - dcCore::app()->error->add(sprintf(__('%s required php >= %s'), My::id(), My::PHP_MIN)); - } - } + static::$init == defined('DC_CONTEXT_ADMIN') + && dcCore::app()->auth?->isSuperAdmin() + && My::phpCompliant(); - return self::$init; + return static::$init; } public static function process(): bool { - if (!self::$init) { + if (!static::$init) { return false; } @@ -79,7 +75,7 @@ class Config extends dcNsProcess public static function render(): void { - if (!self::$init) { + if (!static::$init) { return; } diff --git a/src/Install.php b/src/Install.php index 0c94652..21c6081 100644 --- a/src/Install.php +++ b/src/Install.php @@ -22,17 +22,16 @@ class Install extends dcNsProcess { public static function init(): bool { - if (defined('DC_CONTEXT_ADMIN')) { - self::$init = version_compare(phpversion(), My::PHP_MIN, '>=') - && dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version')); - } + static::$init = defined('DC_CONTEXT_ADMIN') + && My::phpCompliant() + && dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version')); - return self::$init; + return static::$init; } public static function process(): bool { - if (!self::$init) { + if (!static::$init) { return false; } diff --git a/src/Manage.php b/src/Manage.php index b64fbe6..802deb9 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -28,16 +28,16 @@ class Manage extends dcNsProcess { public static function init(): bool { - if (defined('DC_CONTEXT_ADMIN')) { - self::$init = dcCore::app()->auth->isSuperAdmin() && version_compare(phpversion(), My::PHP_MIN, '>='); - } + static::$init = defined('DC_CONTEXT_ADMIN') + && dcCore::app()->auth?->isSuperAdmin() + && My::phpCompliant(); - return self::$init; + return static::$init; } public static function process(): bool { - if (!self::$init) { + if (!static::$init) { return false; } @@ -268,7 +268,7 @@ class Manage extends dcNsProcess public static function render(): void { - if (!self::$init) { + if (!static::$init) { return; } diff --git a/src/My.php b/src/My.php index 539cf97..b8b9c89 100644 --- a/src/My.php +++ b/src/My.php @@ -35,13 +35,27 @@ class My '_disabled', ]; + /** + * This module id + */ public static function id(): string { return basename(dirname(__DIR__)); } + /** + * This module name + */ public static function name(): string { return __((string) dcCore::app()->plugins->moduleInfo(self::id(), 'name')); } + + /** + * Check php version + */ + public static function phpCompliant(): bool + { + return version_compare(phpversion(), self::PHP_MIN, '>='); + } }