yaconf
1.0.0
PHP持续配置容器
YACONF是一个配置容器,它解析INI文件,将结果存储在PHP时将结果存储在PHP中,配置生存在整个PHP生命周期中,这使其非常快。
Yaconf是PECL扩展名,因此您可以通过以下方式安装它。
$pecl install yaconf
或者您可以通过自己的自我编译:
$ /path/to/php7/bin/phpize
$ ./configure --with-php-config=/path/to/php7/bin/php-config
$ make && make install
Path to directory which all ini configuration files are placed in
In which interval Yaconf will detect ini file's change(by directory's mtime),
if it is set to zero, you have to restart php to reloading configurations.
mixed Yaconf:: get (string $ name , mixed $ default = NULL )
bool Yaconf:: has (string $ name )假设我们将所有配置文件放在/tmp/yaconf/中,因此我们将其添加到php.ini中
yaconf.directory=/tmp/yaconf
假设 /tmp /yaconf中有两个文件
foo.ini
name = " yaconf " ; string
year =2015 ; number
features[]= " fast " ; map
features.1 = " light "
features.plus = " zero-copy "
features.constant =PHP_VERSION ; PHP constants
features.env =${HOME} ; Enviorment variables和bar.ini
[base]
parent = " yaconf "
children = " NULL "
[children:base] ; inherit from section "base"
children = " set " 让我们从yaconf检索配置
php7 -r ' var_dump(Yaconf::get("foo")); '
/ *
array ( 3 ) {
[ "name" ] = >
string ( 6 ) "yaconf"
[ "year" ] = >
string ( 4 ) "2015"
[ "features" ] = >
array ( 5 ) {
[ 0 ] = >
string ( 4 ) "fast"
[ 1 ] = >
string ( 5 ) "light"
[ "plus" ] = >
string ( 9 ) "zero-copy"
[ "constant" ] = >
string ( 9 ) "7.0.0-dev"
[ "env" ] = >
string ( 16 ) "/home/huixinchen"
}
}
* /如您所见,Yaconf支持字符串,MAP(数组),INI,ENV变量和PHP常数。
您还可以访问这样的配置:
php7 -r ' var_dump (Yaconf:: get ( " foo.name " )); '
//string(6) "yaconf"
php7 -r ' var_dump (Yaconf:: get ( " foo.features.1 " )); '
//string(5) "light"
php7 -r ' var_dump (Yaconf:: get ( " foo.features " )[ " plus " ]);'
//string(9) "zero-copy"现在让我们看看各节和部分的继承:
php7 -r ' var_dump(Yaconf::get("bar")); '
/ *
array ( 2 ) {
[ "base" ] = >
array ( 2 ) {
[ "parent" ] = >
string ( 6 ) "yaconf"
[ "children" ] = >
string ( 4 ) "NULL"
}
[ "children" ] = >
array ( 2 ) {
[ "parent" ] = >
string ( 6 ) "yaconf"
[ "children" ] = >
string ( 3 ) "set"
}
}
* /儿童部分在基本部分中具有继承的价值,并且儿童能够覆盖所需的价值。