From e33ef74af9ff2f8ba1c6909b78ee07633cff240a Mon Sep 17 00:00:00 2001 From: Inverle Date: Wed, 30 Jul 2025 08:03:04 +0200 Subject: `before_login_btn` hook + system conf attributes (#7761) * `before_login_btn` hook + system conf attributes * phpstan fix * Refactoring --------- Co-authored-by: Alexandre Alapetite --- lib/Minz/Configuration.php | 43 +++++++++++++++++++++++++++++++++++++++++++ lib/Minz/ExtensionManager.php | 9 ++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/Minz/Configuration.php b/lib/Minz/Configuration.php index b56268b4a..a79c364d3 100644 --- a/lib/Minz/Configuration.php +++ b/lib/Minz/Configuration.php @@ -155,6 +155,8 @@ class Minz_Configuration { * @param string $key the name of the param. * @param mixed $default default value to return if key does not exist. * @return array|mixed value corresponding to the key. + * @access private + * @deprecated Use `attribute*()` methods instead. */ public function param(string $key, mixed $default = null): mixed { if (isset($this->data[$key])) { @@ -170,6 +172,8 @@ class Minz_Configuration { /** * A wrapper for param(). * @return array|mixed + * @access private + * @deprecated */ public function __get(string $key): mixed { return $this->param($key); @@ -180,6 +184,8 @@ class Minz_Configuration { * * @param string $key the param name to set. * @param mixed $value the value to set. If null, the key is removed from the configuration. + * @access private + * @deprecated Use `_attribute()` instead. */ public function _param(string $key, mixed $value = null): void { if ($this->configuration_setter !== null && $this->configuration_setter->support($key)) { @@ -193,6 +199,8 @@ class Minz_Configuration { /** * A wrapper for _param(). + * @access private + * @deprecated */ public function __set(string $key, mixed $value): void { $this->_param($key, $value); @@ -217,4 +225,39 @@ class Minz_Configuration { return true; } + + /** + * @param non-empty-string $key + * @return array|null + */ + public function attributeArray(string $key): ?array { + $a = self::param($key, null); + return is_array($a) ? $a : null; + } + + /** @param non-empty-string $key */ + public function attributeBool(string $key): ?bool { + $a = self::param($key, null); + return is_bool($a) ? $a : null; + } + + /** @param non-empty-string $key */ + public function attributeInt(string $key): ?int { + $a = self::param($key, null); + return is_numeric($a) ? (int)$a : null; + } + + /** @param non-empty-string $key */ + public function attributeString(string $key): ?string { + $a = self::param($key, null); + return is_string($a) ? $a : null; + } + + /** + * @param non-empty-string $key + * @param array|mixed|null $value Value, not HTML-encoded + */ + public function _attribute(string $key, $value = null): void { + self::_param($key, $value); + } } diff --git a/lib/Minz/ExtensionManager.php b/lib/Minz/ExtensionManager.php index fc6a7f08a..936af82a1 100644 --- a/lib/Minz/ExtensionManager.php +++ b/lib/Minz/ExtensionManager.php @@ -26,6 +26,10 @@ final class Minz_ExtensionManager { 'list' => [], 'signature' => 'NoneToNone', ], + 'before_login_btn' => [ // function(): string + 'list' => [], + 'signature' => 'NoneToString', + ], 'check_url_before_add' => [ // function($url) -> Url | null 'list' => [], 'signature' => 'OneToOne', @@ -155,7 +159,10 @@ final class Minz_ExtensionManager { $list_potential_extensions = array_merge($list_core_extensions, $list_thirdparty_extensions); $system_conf = Minz_Configuration::get('system'); - self::$ext_auto_enabled = $system_conf->extensions_enabled; + self::$ext_auto_enabled = array_filter( + $system_conf->attributeArray('extensions_enabled') ?? [], + fn($value, $key): bool => is_string($key) && is_bool($value), + ARRAY_FILTER_USE_BOTH); foreach ($list_potential_extensions as $ext_pathname) { if (!is_dir($ext_pathname)) { -- cgit v1.2.3