slince / config
支持多种文件格式的灵活配置文件加载器
1.1.0
2017-05-07 08:23 UTC
Requires
- php: >=5.5.9
Requires (Dev)
- phpunit/phpunit: ^4.0
Suggests
- openlss/lib-array2xml: requires for parsing xml file
- symfony/yaml: Requires for parsing yaml file
This package is auto-updated.
Last update: 2024-09-08 17:55:47 UTC
README
该库支持多种配置文件格式,如json、ini、xml、yaml和原生PHP数组。它还可以帮助将项目导出到指定的配置文件。
安装
通过composer安装
{ "require": { "slince/config": "^1.0" } }
用法
创建配置实例
$config = new Slince\Config\Config();
加载配置文件
加载配置文件
$config->load('/path/to/config.json');
加载包含多个文件的目录
$config->load('/path/to/config-directory/');
注意:目录不能包含不受支持的文件。
访问数据
$config->get('foo'); //Or access the data like array $config['foo']['bar'];
通过键检查项目是否存在
echo $config->exists('foo'); //or like array echo isset($config['foo']);
向容器添加项目
$config->set('bar', 'baz'); //or like array $config['bar'] = 'baz';
通过键移除项目
$config->delete('bar'); //or like array unset($config['bar']);
移除所有项目
$config->clear();
将所有项目导出到指定的配置文件
$config->dump('/path/to/config-dump.php');
许可证
MIT许可证。查看MIT