minphp/configure
最新稳定版本:2.1.0
Composer 安装命令:
composer require minphp/configure
包简介
Generic Configuration Library
README 文档
README
A generic configuration library for getting and setting values for keys.
Installation
Install via composer:
composer require minphp/configure:~2.0
Basic Usage
<?php use Minphp\Configure\Configure; $config = new Configure(); $config->set('key', 'value'); $config->get('key');
Supported Actions
$config->set($key, $value)- Add or update a value in the config$config->get($key)- Get a value from the config$config->exists($key)- Find if a key is set in the config$config->remove($key)- Remove a key from the config
Using Config Files
Configure currently supports the following formats:
- PHP (a file that returns an array or object supported by \ArrayIterator)
- JSON
config.php
<?php return array( 'key1' => 'value', 'key2' => array('key' => 'value') );
config.json
{
"key1": "value",
"key2": {"property": "value"}
}
usage.php
<?php use Minphp\Configure\Configure; $config = new Configure(); $config->load(new Reader\PhpReader(new \SplFileObject('config.php'))); echo $config->get('key1'); // prints "value" echo $config->get('key2')['key']; // prints "value"; $config->load(new Reader\JsonReader(new \SplFileObject('config.json'))); echo $config->get('key1'); // prints "value" echo $config->get('key2')->property; // prints "value";
Note: Configure won't mess with your data. JSON objects are returned as actual objects, not hashes.
A literal translation of the above config.json file would be:
return array( 'key' => 'value', 'key2' => (object)array('key' => 'value') );
统计信息
- 总下载量: 908
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-02-04