devture / silex-provider-config
Silex (Pimple) 配置管理提供者
2.0
2017-03-17 16:58 UTC
Requires
- pimple/pimple: ^3.0
This package is not auto-updated.
Last update: 2024-09-14 16:18:48 UTC
README
为 Silex 微框架提供配置提供者。
用法
配置加载器使用 配置 文件(包含配置骨架)和 参数 文件(自定义配置的变量)的概念。
将一些配置值移动到配置骨架之外,允许配置文件提交到版本控制并保持一致,同时留下某些“参数”以供自定义。
参数文件 可以作为文件路径或作为值的 PHP 数组提供给库。后者在您想要获取一些环境变量时非常有用。
示例配置
//config.json
{
"key": "value",
"something": "%something%",
"websites": {
"first": "%main_website%",
"second": "%another_website%"
}
}
//parameters.json
{
"something": "value for something",
"main_website": "http://devture.com/",
"another_website": "http://github.com/spantaleev"
}
用法
<?php
$app->register(new \Devture\SilexProvider\Config\ServicesProvider());
$configFiles = array('/path/to/config.json');
//Each is either a path to a parameter file (JSON) or an array of parameters (key => value dictionary).
$parameterFiles = array(
'/path/to/parameters.json',
array('something' => 'overriden value for something'),
);
$app['config'] = $app['devture_config.loader']->load($configFiles, $parameterFiles);
结果
$app['config'] = array(
'key' => 'value',
'something' => 'overriden value for something',
'websites' => array(
'first' => 'http://devture.com/',
'second' => 'http://github.com/spantaleev',
)
);
限制
- 仅支持 JSON 配置文件和内联数组(故意为之)
- 不支持部分参数替换("storage_path": "%base_path%/storage")- 可能稍后实现