nimblephp/settings
Composer 安装命令:
composer require nimblephp/settings
包简介
Runtime key-value settings for NimblePHP, stored in the database with typed values and per-request caching
README 文档
README
Runtime key-value settings for NimblePHP. Stores typed values in the database
(table module_setting) and caches them per request.
Contents
Module— module registration and migrations (onUpdate)ModuleSettingModel— settings manager (get, set, has, forget, all)SettingType— value type enum (string,integer,float,boolean,json) with encode/decodeSettingsException— module exceptionsrc/Migrations/— migration creating themodule_settingtable
Installation
composer require nimblephp/settings
Migration
Migrations run automatically on application update (Module::onUpdate(),
group module_setting). They can also be run manually:
php vendor/bin/nimble migration:run --dir=vendor/nimblephp/settings/src/Migrations
Usage
use NimblePHP\Settings\ModuleSettingModel; $settings = $this->loadModel(ModuleSettingModel::class); // store (type is derived from the value) $settings->set('site.name', 'My App'); // string $settings->set('mail.enabled', true); // boolean $settings->set('uploads.maxMb', 25); // integer $settings->set('feature.flags', ['beta' => true]); // json // read (typed value back, with default) $name = $settings->get('site.name', 'Default'); $enabled = $settings->get('mail.enabled', false); // check / remove / list $settings->has('site.name'); $settings->forget('site.name'); $all = $settings->all(); // ['key' => value, ...]
Values are loaded once per request and kept in an in-memory cache. set() and
forget() keep the cache in sync; call flushCache() to force a reload.
Service / facade (no loadModel needed)
Module::register() registers a SettingsService in the container under the id
settings, so settings are reachable application-wide:
use NimblePHP\Framework\Kernel; $settings = Kernel::$serviceContainer->get('settings'); // SettingsService $settings->set('site.name', 'My App');
Or via the static facade (self-registers the service on demand):
use NimblePHP\Settings\Settings; Settings::set('mail.enabled', true); $enabled = Settings::get('mail.enabled', false);
The service, the facade and the model all share the same per-request cache.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-30