fantismic/dynamic-settings
Composer 安装命令:
composer require fantismic/dynamic-settings
包简介
This package creates custom dynamic settings controlled by the user.
关键字:
README 文档
README
Dynamic Settings is a Laravel / Livewire package that allows you to manage custom settings of your application dynamically.
Let's say you have several notifications to different mailing lists, but you would like to be able to change whether they are sent or not, or which email they are sent to without having to modify the code or the env file.
This is where Dynamic Settings comes in.
You can make any number of configurations, grouped and associated with each other, and then use their values in the code. This way when sending an email, for example, $to will be DynSettings::get('admin.mail') and not "admin@mysite.com".
Requirements
- Laravel 10/11
Optionals requirements
- Livewire 3 (*)
- Wire UI 2 (**)
(*) Livewire 3 is required only for the component to manage the settings. You can always ignore that and make your own.
(**) As said before, WireUI is a great package for those components, we included a normal view and a WireUI view, they set up automatically base on your app.
Installation
composer require fantismic/dynamic-settings
After you install you need to publish the migration file...
php artisan vendor:publish --provider="Fantismic\\DynSettings\\Providers\\DynSettingsProvider" --tag="migrations"
...and run the migration.
php artisan migrate
That's it. You are ready to go!
Optionals
You can publish the configuration file to customize behavior, such as full page component mode or preferred blade.
php artisan vendor:publish --provider="Fantismic\\DynSettings\\Providers\\DynSettingsProvider" --tag="config"
Using the built in component
Component mode
We provide a livewire component for manage the settings. You just need to include it like any other componenet wherever you want it.
<livewire:DynamicSettings />
Fullpage mode
You can set the component to render in fullpage in the config file. If you do, you should add the route in your routes/web.php
<?php
use Fantismic\DynSettings\Livewire\DynamicSettingsComponent;
Route::get('/fullpageSettings',DynamicSettingsComponent::class);
Usage
We provide one or two methods in the facade.
use Fantismic\DynSettings\Facades\DynSettings;
Lets say you have these keys:
notifications.send
notifications.alwayscc.send
notificactions.alwayscc.emails
Getting data
- Get all settings
- Get all settings as array
- Get all settings as object
- Get all settings as dotted array
- Get setting value
- Get setting data
- Get setting model
- Get all groups
- Get associations by group
- Get settings by group
Setting / Updating data
- Set a value
- Get settings by group
- Update groupname
- Update description
- Update association
- Delete setting
- Delete setting by key
- Update groupname
Using the settings
Get all settings
DynSettings::all(): (array)
> DynSettings::all()
= [
[
"id" => 1,
"key" => "notifications.send",
"value" => "true",
"type" => "bool",
"name" => "Send email notifications",
"description" => "Check this item in order to active all notifications.",
"group" => "Notifications",
"associate_with" => "General",
],
[
"id" => 2,
"key" => "notifications.alwayscc.send",
"value" => "true",
"type" => "bool",
"name" => "Send always CC",
"description" => "Add to all emails a carbon copy",
"group" => "Notifications",
"associate_with" => "Always CC",
],
[
"id" => 3,
"key" => "notifications.alwayscc.emails",
"value" => "["test@mail.com","admin@app.com"]",
"type" => "array",
"name" => "CC email list",
"description" => "List of emails that should recibe a copy for every send mail",
"group" => "Notifications",
"associate_with" => "Always CC",
],
]
>
Get all settings as array
DynSettings::getArray(): (array)
> DynSettings::getArray()
= [
"notifications" => [
"send" => true,
"alwayscc" => [
"send" => true,
"emails" => [
"test@mail.com",
"admin@app.com",
],
],
],
]
Get all settings as object
DynSettings::getObject(): (object)
> DynSettings::getObject()
= {#1
+"notifications": {#2
+"send": true,
+"alwayscc": {#3
+"send": true,
+"emails": [
"test@mail.com",
"admin@app.com",
],
},
},
}
Get all settings as dotted array
DynSettings::getDot(): (array)
> DynSettings::getDot()
= [
"notifications.send" => true,
"notifications.alwayscc.send" => true,
"notifications.alwayscc.emails" => [
"test@mail.com",
"admin@app.com",
],
]
Get setting value
DynSettings::get( (string) $key): (mixed)
> DynSettings::get('notifications.alwayscc.send')
= true
------------------------------------------------------------
> DynSettings::get('notifications.alwayscc.emails')
= [
"test@mail.com",
"admin@app.com",
]
Get setting data
DynSettings::getKeyData( (string) $key): (array)
> DynSettings::getKeyData('notifications.alwayscc.send')
= {#5459
+"id": 2,
+"key": "notifications.alwayscc.send",
+"value": "true",
+"type": "bool",
+"name": "Send always CC",
+"description": "Add to all emails a carbon copy",
+"group": "Notifications",
+"associate_with": "Always CC",
}
Get setting model
DynSettings::getModel( (string) $key): (Eloquent Model)
> DynSettings::getModel('notifications.alwayscc.send')
= Fantismic\DynSettings\Models\DynamicSettings {#
id: 2,
key: "notifications.alwayscc.send",
value: "true",
type: "bool",
name: "Send always CC",
description: "Add to all emails a carbon copy",
group: "Notifications",
associate_with: "Always CC",
}
>
Get all groups
DynSettings::getGroups(): (array)
> DynSettings::getGroups()
= [
"Notifications",
]
Get associations by group
DynSettings::getAssocs( (string) $group): (array)
> DynSettings::getAssocs("Notifications")
= [
"General",
"Always CC",
]
Get settings by group
DynSettings::getByGroup( (string) $group): (array)
> DynSettings::getByGroup("Notifications")
= [
[
"id" => 1,
"key" => "notifications.send",
"value" => "true",
"type" => "bool",
"name" => "Send email notifications",
"description" => "Check this item in order to active all notifications.",
"group" => "Notifications",
"associate_with" => "General",
],
[
"id" => 2,
"key" => "notifications.alwayscc.send",
"value" => "false",
"type" => "bool",
"name" => "Send always CC",
"description" => "Add to all emails a carbon copy",
"group" => "Notifications",
"associate_with" => "Always CC",
],
[
"id" => 3,
"key" => "notifications.alwayscc.emails",
"value" => "["test@mail.com","admin@app.com"]",
"type" => "array",
"name" => "CC email list",
"description" => "List of emails that should recibe a copy for every send mail",
"group" => "Notifications",
"associate_with" => "Always CC",
],
]
------------------------------------------------------------
Setting / Updating data
Set a value
DynSettings::set( (string) $group, (mixed) $value): (bool)
> DynSettings::set('notifications.alwayscc.send',false)
= true
Update groupname
DynSettings::updateName( (string) $key, (string) $newName): (bool)
> DynSettings::updateName('notifications.alwayscc.send','Always send carbon copy')
= true
Update description
DynSettings::updateDescription( (string) $key, (string) $newDescription): (bool)
> DynSettings::updateDescription('notifications.alwayscc.send','Set CC on every outgoing mail')
= true
Update association
DynSettings::updateAssoc( (string) $key, (string) $newAssoc): (bool)
> DynSettings::updateAssoc('notifications.alwayscc.send','CC')
= true
Delete setting
DynSettings::delete( (int) $id)**: (bool)
> DynSettings::delete(3)
= true
Delete setting by key
DynSettings::deleteByKey( (string) $key)**: (bool)
> DynSettings::deleteByKey('notifications.alwayscc.send')
= true
Update groupname
DynSettings::updateGroupName( (string) $oldName, (string) $newName): (bool)
> DynSettings::updateGroupName("Notifications", "Mailing")
= true
Using the settings
Comparing setting
DynSettings::is( (string) $key, (mixed) $value): (bool)
> DynSettings::is('notifications.alwayscc.send', false)
= true
Boolean comparition
DynSettings::should( (string) $key): (bool)
> DynSettings::should('notifications.alwayscc.send')
= false
Array search
DynSettings::has( (string) $key, (array) $value, [(bool) strict = false]): (bool)
> DynSettings::has('notifications.alwayscc.email', 'admin@app.com')
= true
> DynSettings::has('notifications.alwayscc.email', 'admin@APP.com')
= false
> DynSettings::has('notifications.alwayscc.email', 'admin@APP.com', false)
= true
> DynSettings::has('notifications.alwayscc.email', 'not-in-list-mail@app.com')
= false
fantismic/dynamic-settings 适用场景与选型建议
fantismic/dynamic-settings 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.77k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 07 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「dynamic」 「Settings」 「blade components」 「livewire components」 「laravel components」 「dynamic-settings」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fantismic/dynamic-settings 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fantismic/dynamic-settings 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fantismic/dynamic-settings 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Persistent settings package for Laravel framework.
Flexslider slideshow content block for Silverstripe Elemental
A Zend Framework module to quickly and easily set PHP settings.
EAV modeling package for Eloquent and Laravel.
Settings Card for Laravel Nova.
Write down your routing mapping at one place
统计信息
- 总下载量: 1.77k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-07-17