From afa1adb90b406936e153e4e97fcd9d1dbd426e7f Mon Sep 17 00:00:00 2001 From: slawkens Date: Thu, 13 Jul 2023 16:47:09 +0200 Subject: [PATCH] Add settings.callbacks.get --- system/compat/config.php | 9 +-------- system/libs/Settings.php | 4 ++++ system/settings.php | 10 ++++++++++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/system/compat/config.php b/system/compat/config.php index 256620f7..8deca716 100644 --- a/system/compat/config.php +++ b/system/compat/config.php @@ -4,6 +4,7 @@ $deprecatedConfig = [ 'template', 'template_allow_change', 'vocations_amount', + 'vocations', 'client', 'session_prefix', 'friendly_urls', @@ -44,11 +45,3 @@ foreach ($deprecatedConfig as $key => $value) { //var_dump($settings['core.'.$value]['value']); } -$vocationsParsed = array_map( - function(string $value): string { - return trim($value); - }, - explode(',', setting('core.vocations')) -); - -config(['vocations', $vocationsParsed]); diff --git a/system/libs/Settings.php b/system/libs/Settings.php index 6a4ff933..3244069a 100644 --- a/system/libs/Settings.php +++ b/system/libs/Settings.php @@ -434,6 +434,10 @@ class Settings implements ArrayAccess } } + if (isset($ret['callbacks']['get'])) { + $ret['value'] = $ret['callbacks']['get']($ret['value']); + } + $this->cache[$offset] = $ret; return $ret; } diff --git a/system/settings.php b/system/settings.php index d30e8eb8..e259ec36 100644 --- a/system/settings.php +++ b/system/settings.php @@ -142,6 +142,11 @@ return [ 'type' => 'textarea', 'desc' => 'Separated by comma ,', 'default' => 'None, Sorcerer, Druid, Paladin, Knight, Master Sorcerer, Elder Druid,Royal Paladin, Elite Knight', + 'callbacks' => [ + 'get' => function ($value) { + return array_map('trim', explode(',', $value)); + }, + ], ], 'client' => [ 'name' => 'Client Version', @@ -673,6 +678,11 @@ Sent by MyAAC,
'type' => 'text', 'desc' => 'This looktypes needs to have different margin-top and margin-left because they are wrong positioned', 'default' => '75, 126, 127, 266, 302', + 'callbacks' => [ + 'get' => function ($value) { + return array_map('trim', explode(',', $value)); + }, + ], ], [ 'type' => 'section',