定制 hambrook/config 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hambrook/config

最新稳定版本:v1.0.5

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/.

统计信息

  • 总下载量: 34
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2015-10-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固