cornford/setter
Composer 安装命令:
composer require cornford/setter
包简介
An easy way to integrate Database Settings with Laravel.
README 文档
README
For Laravel 5.x, check version 2.4.0
For Laravel 4.x, check version 1.7.2
Think of Setter as an easy way to integrate Settings with Laravel, providing a variety of helpers to speed up the utilisation of application wide settings. These include:
Setting::setSetting::getSetting::forgetSetting::hasSetting::allSetting::clearSetting::expires
Installation
Begin by installing this package through Composer. Edit your project's composer.json file to require cornford/setter.
"require": {
"cornford/setter": "3.*"
}
Next, update Composer from the Terminal:
composer update
We now have to publish the packages assets with the following command:
php artisan vendor:publish --provider="Cornford\Setter\Providers\SettingServiceProvider" --tag=setting
We now have to migrate the package database table with the following command:
php artisan migrate
Once this operation completes, the next step is to add the service provider. Open config/app.php, and add a new item to the providers array.
Cornford\Setter\Providers\SettingServiceProvider::class,
The final step is to introduce the facade. Open config/app.php, and add a new item to the aliases array.
'Setting' => Cornford\Setter\Facades\SettingFacade::class,
That's it! You're all set to go.
Configuration
You can now configure Setter in a few simple steps. Open config/packages/cornford/setter/config.php and update the options as needed.
cache- Enable caching to improve performance by reducing database calls.tag- A tag prefixed to all cache items, e.g. tag::.expiry- The default expiry for cache items, e.g. 60.
Usage
It's really as simple as using the Setter class in any Controller / Model / File you see fit with:
Setting::
This will give you access to
- Set
- Get
- Forget
- Has
- All
- Clear
- expires
- Uncached
- cacheEnabled
- enableCache
- disableCache
- setCacheTag
- getCacheTag
- cacheHas
- cacheForget
- cacheClear
- CacheExpires
Set
The set method sets a setting via both a key and a value parameter in the database.
Setting::set('app.url', 'http://localhost');
Get
The get method gets a setting via a key parameter from the database, and a default value can be optionally passed if the setting doesn't exist.
If no default parameter is supplied, and an application configuration variable is present, this will be returned.
Setting::get('app.url', 'http://localhost');
Setting::get('app.url');
Forget
The forget method removes a setting via a key parameter from the database.
Setting::forget('app.setting');
Has
The has method returns a true / false based on if a setting is present in the database via a key parameter.
This doesn't fall back to checking application configuration variables.
Setting::has('app.setting');
All
The all method returns an array of key value pairs of settings from the database.
This doesn't fall back to return application configuration variables.
Setting::all();
Clear
The clear method removes all settings from the database.
This doesn't fall back to removing application configuration variables.
Setting::clear();
Expires
The expires method sets the cache expiry setting.
Can be false to not cache, true / 0 to cache indefinitely, an integer for minutes, or a datetime of when to expire.
Setting::expires(false);
Uncached
The uncached method ensures the next get request is requested from the database rather than the cache. It will also re-cache the item if one is found.
Setting::uncached();
Setting::uncached()->get('app.setting');
Cache Enabled
The cacheEnabled method gets the current caching state returning a true / false based on the cache status, retuning the current Setter instance.
Setting::cacheEnabled();
Enable Cache
The enableCache method sets caching state to cache items, retuning the current Setter instance.
Setting::enableCache();
Setting::enableCache()->set('app.url', 'http://localhost');
Disable Cache
The disableCache method sets caching state to not cache items.
Setting::disableCache();
Setting::disableCache()->set('app.url', 'http://localhost');
Set Cache Tag
The setCacheTag method sets the currently caching prefix tag.
Setting::setCacheTag('tag:');
Get Cache Tag
The getCacheTag method gets the currently set caching prefix tag.
Setting::getCacheTag();
Cache Has
The cacheHas method returns a true / false based on if a setting is present in the cache via a key parameter.
This doesn't fall back to checking application configuration variables.
Setting::cacheHas('app.setting');
Cache Forget
The cacheForget method removes a setting via a key parameter from the cache.
Setting::cacheForget('app.setting');
Cache Expires
The cacheExpires method sets the cache expiry setting.
Can be false to not cache, true / 0 to cache indefinitely, an integer for minutes, or a datetime of when to expire.
Setting::cacheExpires(false);
Cache Clear
The cacheClear method removes all settings from the cache.
This doesn't fall back to removing application configuration variables.
Setting::cacheClear();
License
Setter is open-sourced software licensed under the MIT license
cornford/setter 适用场景与选型建议
cornford/setter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.05k 次下载、GitHub Stars 达 13, 最近一次更新时间为 2014 年 05 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「configuration」 「config」 「laravel」 「setting」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 cornford/setter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cornford/setter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 cornford/setter 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Configuration component
Store your language lines in the database, yaml or other sources
A Zend Framework module to quickly and easily set PHP settings.
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
A PSR-7 compatible library for making CRUD API endpoints
统计信息
- 总下载量: 1.05k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-05-28