From 0512a5d1a6e0c35e6c81c77ddc7992661ac0eff9 Mon Sep 17 00:00:00 2001 From: maxpozdeev Date: Fri, 23 Sep 2022 12:02:50 +0300 Subject: [PATCH] remove MTTExtension::name --- src/includes/api/ExtSettingsController.php | 6 +++++- src/includes/classes.php | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/includes/api/ExtSettingsController.php b/src/includes/api/ExtSettingsController.php index ef3eb21..1e780f0 100644 --- a/src/includes/api/ExtSettingsController.php +++ b/src/includes/api/ExtSettingsController.php @@ -16,6 +16,10 @@ class ExtSettingsController extends ApiController { if (!$instance) { return; } + $meta = MTTExtension::extMetaInfo($ext); + if (!$meta || !isset($meta['name'])) { + return; + } $data = $instance->settingsPage(); @@ -25,7 +29,7 @@ class ExtSettingsController extends ApiController { $name = htmlspecialchars($lang->get($nameKey)); } else { - $name = htmlspecialchars($instance::name); + $name = htmlspecialchars($meta['name']); } $escapedExt = htmlspecialchars($ext); $e = function($s) use($lang) { return htmlspecialchars($lang->get($s)); }; diff --git a/src/includes/classes.php b/src/includes/classes.php index ce6be4c..f7332b1 100644 --- a/src/includes/classes.php +++ b/src/includes/classes.php @@ -74,7 +74,7 @@ abstract class ApiController abstract class MTTExtension { const bundleId = ''; - const name = ''; + abstract function init(); public static function extMetaInfo(string $ext): ?array @@ -142,11 +142,11 @@ class MTTExtensionLoader } $className = get_class($instance); - if (!defined("$className::bundleId") || !defined("$className::name")) { - throw new Exception("Failed to register extension '$ext': require class constants (bundleId, name)"); + if (!defined("$className::bundleId")) { + throw new Exception("Failed to load extension '$ext': missing required class constants (bundleId)"); } if ($instance::bundleId != $ext) { - throw new Exception("Extension '$ext' bundleId does not conforms to extension dir"); + throw new Exception("Failed to load extension '$ext': bundleId does not conforms to extension dir"); } Lang::instance()->loadExtensionLang($ext);