scabbiafw / scabbia2-config
v0.1.1
2015-09-16 07:45 UTC
Requires
- php: >=5.6.0
Requires (Dev)
This package is not auto-updated.
Last update: 2022-02-01 12:51:20 UTC
README
此组件 是一个配置编译器,支持绑定多个配置文件。
用法
合并多个配置
use Scabbia\Config\ConfigCollection; $confs = new ConfigCollection(); // add a yaml-parsed configuration $yaml = new \Scabbia\Yaml\Parser(); $confs->add($yaml->parse(file_get_contents('common.yml'))); // ...and/or add a json file $confs->add(json_decode(file_get_contents('production.json'))); // ...and/or add a configuration value manually $confs->add([ 'env' => 'development' ]); // output the result $config = $confs->save(); print_r($config);
覆盖现有配置项
use Scabbia\Config\ConfigCollection; $confs = new ConfigCollection(); $confs->add([ 'env' => 'production' ]); // in second config you can override a value with 'important' flag $confs->add([ 'env|important' => 'development' ]); // output the result $config = $confs->save(); echo $config['env'];
在单独的配置中构建列表
use Scabbia\Config\ConfigCollection; $confs = new ConfigCollection(); $confs->add([ 'items|list' => [ 'first', 'second' ] ]); // in second config you can override a value with 'important' flag $confs->add([ 'items|list' => [ 'third' ] ]); // output the result $config = $confs->save(); print_r($config['items']);
扁平化配置值键
use Scabbia\Config\ConfigCollection; $confs = new ConfigCollection(); $confs->add([ 'database|flat' => [ 'mongo' => [ 'username' => 'scabbia2', 'password' => 'testing' ] ] ]); // output the result $config = $confs->save(); echo $config['database/mongo/username']; echo $config['database/mongo/password'];
链接
贡献
对任何贡献都公开开放。欢迎修复错误、新功能和额外模块。所有贡献都应提交到 eserozvataf/scabbia2-config 仓库。