Di migration Settings and ModSettings services#9177
Open
MissAllSunday wants to merge 7 commits intoSimpleMachines:release-3.0from
Open
Di migration Settings and ModSettings services#9177MissAllSunday wants to merge 7 commits intoSimpleMachines:release-3.0from
MissAllSunday wants to merge 7 commits intoSimpleMachines:release-3.0from
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This MR aims to split the configuration management into two separate, independent services fit also adds a few docs to keep track of already refactored services.
Key Features
Fully Independent: Both services can load and manage settings without depending on the
ConfigclassBackward Compatible: Existing code using
Configcontinues to workPerformance Optimized: Smart loading strategy reuses
Configdata when availableTestable: Can be tested in isolation without global state
Future-Proof: Clean migration path to eventually replace
ConfigentirelyArchitecture
Why Split?
SettingsService (Settings.php)
Settings.php)ModSettingsService (Database)
settingstable)Usage Examples
Old Way (Still Works - Backward Compatible)
New Way - SettingsService
New Way - ModSettingsService
Dependency Injection (Best Practice)
API Reference
SettingsServiceInterface
get(string $key, mixed $default = null)set(string $key, mixed $value)updateFile(array $configVars, bool $keepQuotes = false, bool $rebuild = false)getBoardUrl()getScriptUrl()getBoardDir()getSourcesDir()getCacheDir()getLanguagesDir()isMaintenanceMode()getMaintenanceLevel()getForumName()getDatabaseType()getDatabaseServer()getDatabaseName()getDatabasePrefix()ModSettingsServiceInterface
get(string $key, mixed $default = null)getAll()has(string $key)set(string $key, mixed $value)update(array $settings, bool $update = false)delete(string|array $keys)reload()clearCache()getMultiple(array $keys, mixed $default = null)hasAny(array $keys)hasAll(array $keys)increment(string $key, int $amount = 1)decrement(string $key, int $amount = 1)Migration Checklist
When migrating code to use the new services:
SettingsServiceModSettingsServiceConfig::getSettingsService()orConfig::getModSettingsService()Benefits
1. Single Responsibility
Each service has one clear purpose:
SettingsService: Manage Settings.phpModSettingsService: Manage database settings2. Better Dependencies
3. Improved Testing
4. Performance Optimization
SettingsService: No caching needed (file is fast)ModSettingsService: Aggressive caching (DB queries are slow)5. Security Separation
SettingsService: Contains sensitive data (DB passwords)ModSettingsService: User-configurable, less sensitiveService Registration
Both services are registered in
Sources/Infrastructure/ServicesList.php:Files Structure
Backward Compatibility
All existing code continues to work:
Config::$boardurl✓Config::$modSettings['key']✓Config::updateModSettings()✓Config::reloadModSettings()✓Config::updateSettingsFile()✓