From c3073d56d8094102625ed3979d5121042b815ed3 Mon Sep 17 00:00:00 2001 From: Bugo Date: Sat, 27 Apr 2024 10:52:42 +0500 Subject: [PATCH] Extend Config --- README.md | 1 + README.ru.md | 1 + src/Compat/Config.php | 8 ++++++++ tests/Unit/ConfigTest.php | 6 ++++++ tests/files/Subs-Admin.php | 7 +++++++ 5 files changed, 23 insertions(+) diff --git a/README.md b/README.md index 5924da2..bf077b6 100644 --- a/README.md +++ b/README.md @@ -151,6 +151,7 @@ Or you can leave it as it is. In this case, your modification will support both | `getCalendarList` | `Calendar::getCalendarList` | | `getCalendarGrid` | `Calendar::getCalendarGrid` | | `updateSettings` | `Config::updateModSettings` | +| `updateSettingsFile` | `Config::updateSettingsFile` | | `db_extend` | `Db::extend` | | `create_control_richedit` | `new Editor` | | `fatal_error` | `ErrorHandler::fatal` | diff --git a/README.ru.md b/README.ru.md index 1f8c7f8..42f51e8 100644 --- a/README.ru.md +++ b/README.ru.md @@ -151,6 +151,7 @@ class Example | `getCalendarList` | `Calendar::getCalendarList` | | `getCalendarGrid` | `Calendar::getCalendarGrid` | | `updateSettings` | `Config::updateModSettings` | +| `updateSettingsFile` | `Config::updateSettingsFile` | | `db_extend` | `Db::extend` | | `create_control_richedit` | `new Editor` | | `fatal_error` | `ErrorHandler::fatal` | diff --git a/src/Compat/Config.php b/src/Compat/Config.php index e982672..56c2c0d 100644 --- a/src/Compat/Config.php +++ b/src/Compat/Config.php @@ -15,6 +15,7 @@ namespace Bugo\Compat; use function updateSettings; +use function updateSettingsFile; class Config { @@ -84,4 +85,11 @@ public static function updateModSettings(array $settings): void { updateSettings($settings); } + + public static function updateSettingsFile(array $config_vars, ?bool $keep_quotes = null, bool $rebuild = false): bool + { + require_once self::$sourcedir . DIRECTORY_SEPARATOR . 'Subs-Admin.php'; + + return updateSettingsFile($config_vars, $keep_quotes, $rebuild); + } } diff --git a/tests/Unit/ConfigTest.php b/tests/Unit/ConfigTest.php index 9981d47..c6543d4 100644 --- a/tests/Unit/ConfigTest.php +++ b/tests/Unit/ConfigTest.php @@ -27,3 +27,9 @@ expect(Config::$modSettings['foo'])->toBe('bar'); }); + +test('updateSettingsFile method', function () { + $this->config::$sourcedir = dirname(__DIR__) . '/files'; + + expect($this->config::updateSettingsFile(['foo' => 'bar']))->toBeBool(); +}); diff --git a/tests/files/Subs-Admin.php b/tests/files/Subs-Admin.php index 853b22b..c7b41c6 100644 --- a/tests/files/Subs-Admin.php +++ b/tests/files/Subs-Admin.php @@ -6,3 +6,10 @@ function sm_temp_dir(): string return ''; } } + +if (! function_exists('updateSettingsFile')) { + function updateSettingsFile(...$args): bool + { + return true; + } +}