hambrook/config
Composer 安装命令:
composer require hambrook/config
包简介
Easy-to-work-with config object that saves to a JSON file.
README 文档
README
#Config
A simple Config object that loads a JSON file and lets you access values without having to check if they're set first. Then automatically saves back to the JSON file when your script finishes. It inherits all the getting/setting abilities from Nest.
##Example
$Config = new \Hambrook\Config\Config("settings.json");
JSON File (settings.json)
{
"foo": "bar",
"one": {
"two": "three"
}
};
####Use a string as the path parameter
$value = $Config->get("foo"); // "bar"
####We're going two levels in this time, so use an array for the path
$value = $Config->get(["one", "two"]); // "three"
####What if we try to get something that isn't there? Does it error?
$value = $Config->get(["nope", "two"]); // returns `null`, not an error
####Or we can specify our own default in case of error
$value = $Config->get(["nope", "two"], "safe"); // returns "safe", not an error
##Saving
By default, Config will auto-save at the end of the script. If you instanciate Config with false as the second parameter, then it will no longer auto-save.
You can save at any time by using the save() function.
// Save the JSON encoded data to the file and returns `$this` $Config->save();
##Shortcuts
You can use __ (by default) as a separator instead of using an array, then you can do things like...
// Get a nested value $value = Config->one__two // "three" // Get a nested value that isn't there $value = Config->one__bad // null // Get a nested value, with a default if the value isn't there $value = Config->one__bad("default") // "default" // Get a nested value, with a default if the value isn't there $value = Config->one__two = "newthree" // sets the value to "newthree" then returns `$this`
##Who is it for? Config was built for small CLI scripts and tools. But it can be used anywhere.
##Feedback Tell me if you loved it. Tell me if you hated it. Tell me if you used it and thought "meh". I'm keen to hear your feedback.
##Roadmap
- Add any other standard documentation that should be included
- Add proper unit tests
- If you have an idea, let me know.
##License Copyright © 2015 Rick Hambrook
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
hambrook/config 适用场景与选型建议
hambrook/config 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 34 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 10 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「json」 「array」 「object」 「saving」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hambrook/config 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hambrook/config 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hambrook/config 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A set of useful PHP classes.
Kinikit - PHP Application development framework MVC component
ext-json wrapper with sane defaults
A package to cast json fields, each sub-keys is castable
Trait providing methods to set class properties with an array.
Traits to build collections of specific objects
统计信息
- 总下载量: 34
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0
- 更新时间: 2015-10-20