kenarkose/settlement
最新稳定版本:2.0.0
Composer 安装命令:
composer require kenarkose/settlement
包简介
Framework Agnostic Persistent Typed and Group-able Settings with JSON Driver
README 文档
README
Framework Agnostic Persistent Typed and Group-able Settings with JSON Driver.
Settlement provides a simple solution for persistent settings with support for types and groups.
Features
- Flexible API for persistent settings
- Configurable JSON driver
- Grouped and typed settings
- Group and type validation
- Service provider for Laravel 5
- A phpunit test suite for easy development
Installation
Installing Settlement is simple. Just pull the package in through Composer.
{
"require": {
"kenarkose/settlement": "~2.0"
}
}
Usage
Instantiate a new JSON repository with path and filename and you are good to go.
use Kenarkose\Settlement\Repository\JSONRepository; $settings = new JSONRepository('path/to', 'settings.json');
Here is a list of methods that are defined by the repository interface.
$settings->set('foo', 'bar'); $settings->set('foo', 42, null, 'number'); $settings->set('foo', 'bar', 'Label', 'text', 'baz_group'); $settings->get('foo'); // 'bar' $settings->getComplete('foo'); // ['value' => 'bar', 'label' =>'Label', 'type' => 'text', 'group' => 'baz_group'] $setting->has('foo'); // true $setting->delete('foo'); $setting->getGroup('baz_group'); // Name of the Baz Group $setting->setGroup('foo_group', 'Name of the Foo Group'); $setting->hasGroup('foo_group'); // true $setting->getGroupSettings('baz_group'); // ['foo' => ['value' => 'bar', 'label' => 'Label', 'type' => 'string', 'group' => 'baz_group']] $setting->deleteGroup('foo_group'); $setting->flush();
Additionally, you may use other methods that is provided by the JSONRepository.
$setting->path(); // Returns current path $setting->path('new/path'); // Sets a new path $setting->filename(); // Returns current filename $setting->filename('config.json'); // Sets a new filename $setting->settings(); // Returns all stored settings $setting->settings( ['foo' => ['value' => 'bar', 'type' => 'string', 'group' => null] ); // Replaces stored settings $setting->groups(); // Returns all stored groups $setting->groups( ['dummy' => 'Dummy Group'] ); // Replaces stored groups $setting->stored(); // Returns all stored information $setting->stored([ 'settings' => [...], 'groups' => [...] ]); // Replaces all stored information $setting->load(); // Loads from current path and filename $setting->load('new/path', 'config.json'); // Loads from new path and filename $setting->save(); // Saves to current path and filename $setting->save('new/path', 'config.json'); // Saves to new path and filename
For more options you may refer to source code and tests as Settlement is well tested and documented.
For Laravel Users
The Settlement Service Provider for Laravel 5 registers the default LaravelJSONRepository, the Facade, and the settings() helper.
Laravel Installation
-
In order to register Settlement Service Provider add
'Kenarkose\Settlement\Provider\Laravel\SettlementServiceProvider'to the end ofprovidersarray in yourconfig/app.phpfile.'providers' => array( 'Illuminate\Foundation\Providers\ArtisanServiceProvider', 'Illuminate\Auth\AuthServiceProvider', ... 'Kenarkose\Settlement\Provider\Laravel\SettlementServiceProvider', ),
-
You may access the services provided by Settlement by using the supplied Facade.
Settings::get('foo'); Settings::set('bar', 'baz');
In order to register the Facade add
'Settings' => 'Kenarkose\Settlement\Provider\Laravel\Settings'to the end ofaliasesarray in yourconfig/app.phpfile.'aliases' => array( 'App' => 'Illuminate\Support\Facades\App', 'Artisan' => 'Illuminate\Support\Facades\Artisan', ... 'Settings' => 'Kenarkose\Settlement\Provider\Laravel\Settings', ),
-
A helper function is also provided if the Facade is not preferred.
settings(); // Returns the repository // Getting a value settings('foo'); // is the same as settings()->get('foo'); // Setting a value settings('foo', 'bar'); // is the same as settings()->set('foo', 'bar'); // Other possible derivations of setting settings('foo', 'bar', 'string'); settings('foo', 'bar', 'string', 'group');
-
Finally, you may customize Settlement's behavior by publishing the configuration file. To do so, use the following command.
php artisan vendor:publish
Than, you will find the configuration file on the
config/settlement.phppath.
License
Settlement is released under MIT License.
kenarkose/settlement 适用场景与选型建议
kenarkose/settlement 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 770 次下载、GitHub Stars 达 2, 最近一次更新时间为 2015 年 08 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「json」 「group」 「laravel」 「Settings」 「typed」 「laravel5」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kenarkose/settlement 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kenarkose/settlement 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kenarkose/settlement 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kinikit - PHP Application development framework MVC component
Provides a PHP interface for The AAM Group's RESTful API.
ext-json wrapper with sane defaults
Provides a PHP interface for The AAM Group's payment processor.
A package to cast json fields, each sub-keys is castable
Flexible Content & Repeater Fields for Laravel Nova.
统计信息
- 总下载量: 770
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-08-20