mr-luke/settings-manager
Composer 安装命令:
composer require mr-luke/settings-manager
包简介
Laravel 5 Package that provides settings manager with type casting.
README 文档
README
This package provides settings manamgement to your Laravel app with support of multiple setting bags with typed value.
Getting Started
Setting Manager supported versions:
- Laravel 10
- Laravel 9
- Laravel 8
Installation
To install through composer, simply put the following in your composer.json file and run composer update
{
"require": {
"mr-luke/settings-manager": "~2.0"
}
}
Or use the following command
composer require "mr-luke/settings-manager"
Next, add the service provider to app/config/app.php
Mrluke\Settings\SettingsServiceProvider::class,
Note: Package is auto-discoverable!
Configuration
To use SettingsManager you need to setup your Bags first. Add your own one to the config file bags:
'bags' => [ 'general' => [ // Given key is used as a Bag name 'driver' => 'database', // One of available drivers 'cache' => true, // Should be Cached 'lifetime' => 60 // Cache lifetime in minutes ], ],
You can setup different database connections or tables by new driver or different json files in:
'drivers' => [ 'database' => [ 'class' => \Mrluke\Settings\Drivers\Database::class, 'connection' => 'mysql', 'table' => 'settings', ], 'json' => [ 'class' => \Mrluke\Settings\Drivers\Json::class, 'path' => base_path('storage/app/settings/'), 'file' => 'settings.json', ] ],
You can also publish config file via command:
php artisan vendor:publish
Usage
Facade
You can access to Manager and your Bags using Mrluke\Settings\Facades\Settings.
Type
SettingsManager is a type casted tool that care about it during the whole process.
Example: You can pass string 5.567 to set method for ratio setting (float) and SettingsManager will cast the value to float 5.567 behind the scean.
Whereever you ask for certain key, it will always be correct type. But all begins at the point of registering...
Registering new index
To register new value use:
$value = Settings::register(string $key, $value, string $type);
This method returns given $value casted to given $type.
Accessing index
To get value use:
$value = Settings::get(string $key, $default = null);
This method returns $default in case given $key is not present in the Bag. Otherwise $value is casted to registered type.
Setting new value of index
To set new value use:
$value = Settings::set(string $key, $value);
This method returns $value casted to registered type. If given $key is not present, it will automaticaly call register method with auto-detected type.
This method shoud not be use to register settings in general! Use Eventing to detect all needed settings during development.
Forgeting an index
To forget an index use:
Settings::forget(string $key);
Default Bag vs specified
To access specific Bag use bag accessor method:
$value = Settings::bag(string $name)->get(string $key, $default = null);
Helper
You can access to SettingsManager via helper function:
// Get index settings(string $key); // Set value settings([string $key => $value]); // Get instance and perform action settings()->forget(string $key);
Events
SettingsManager provides you a list of pre and post action events to help you handle different situations.
Example: You can use Mrluke\Settings\Events\Registered event to prepare full list of production settings.
Namespace Mrluke\Settings\Events:
ForgetingForgotLoadingLoadedRegisteringRegisteredUpdatingUpdated
JSON Structure
SettingsManager provides JSON Driver for configurations that can be share with front-end apps. The structure looks like this:
{
"key": {
"type": "<type>",
"value": "<value>"
},
"another": {
"type": "<type>",
"value": "<value>"
}
}
Plans
- Artisan Commands
- Blade helpers for
boolkeys - Additional option to store
defaultvalue fromget()method
mr-luke/settings-manager 适用场景与选型建议
mr-luke/settings-manager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 33.34k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2018 年 10 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「manager」 「laravel」 「Settings」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mr-luke/settings-manager 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mr-luke/settings-manager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mr-luke/settings-manager 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Persistent settings package for Laravel framework.
The file manager intended for using Laravel with CKEditor / TinyMCE / Colorbox
A Zend Framework module to quickly and easily set PHP settings.
Settings Card for Laravel Nova.
Extends basic Wordpress features.
KCFinder web file manager
统计信息
- 总下载量: 33.34k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-10-26