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 รองรับสตริงแผนที่ (อาร์เรย์), 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"
}
}
* /ส่วนเด็กมีค่าที่สืบทอดมาในส่วนฐานและเด็ก ๆ สามารถแทนที่ค่านิยมที่ต้องการ