Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multi-level directory && fix sections coredump bug #29

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Yaconf is a configurations container, it parses ini files, and store the result
- Zero-copy while accesses configurations
- Support sections, sections inheritance
- Configurations reload automatically after changed
- Support multi-level directory

### Install

Expand Down Expand Up @@ -42,6 +43,11 @@ $ make && make install
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.
```
- yaconf.check_type
```
if it is set to zero (default) will detect ini file's change by directory's mtime ,
otherwise will detect each file's mtime.
```

### APIs

Expand Down Expand Up @@ -80,6 +86,18 @@ children="NULL"
[children:base]
children="set"
````

and test/foo.ini( fullpath is : /tmp/yaconf/test/foo.ini)
````ini
name="test/yaconf"
year=2015
features[]="fast"
features.1="light"
features.plus="zero-copy"
features.constant=PHP_VERSION
features.env=${HOME}
````

#### Run
lets access the configurations

Expand Down Expand Up @@ -145,5 +163,29 @@ array(2) {
}
*/
````

Children section has inherited values in base sections, and children were able to override the values they want.


##### test/foo.ini
Now let's see the ini in the directories :
````php
php7 -r 'var_dump(Yaconf::get("test/foo"));'
/*
array(2) {
["base"]=>
array(2) {
["parent"]=>
string(6) "test/yaconf"
["children"]=>
string(4) "NULL"
}
["children"]=>
array(2) {
["parent"]=>
string(6) "yaconf"
["children"]=>
string(3) "set"
}
}
*/
````
4 changes: 4 additions & 0 deletions php_yaconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ extern zend_module_entry yaconf_module_entry;
#define YACONF_DEBUG(m)
#endif


#define MAX_SEARCH_DIR_SIZE 10240

ZEND_BEGIN_MODULE_GLOBALS(yaconf)
char *directory;
int parse_err;
#ifndef ZTS
long check_type;
long check_delay;
time_t last_check;
time_t directory_mtime;
Expand Down
2 changes: 2 additions & 0 deletions tests/001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Check for Yaconf presence
--SKIPIF--
<?php if (!extension_loaded("yaconf")) print "skip"; ?>
--INI--
yaconf.directory={PWD}/inis/data
--FILE--
<?php
echo "yaconf extension is available";
Expand Down
24 changes: 23 additions & 1 deletion tests/002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ Check for Yaconf
--SKIPIF--
<?php if (!extension_loaded("yaconf")) print "skip"; ?>
--INI--
yaconf.directory={PWD}/inis/
yaconf.directory={PWD}/inis/data
--FILE--
<?php
print_r(Yaconf::get("a"));
print_r(Yaconf::get("b"));
var_dump(Yaconf::get("c"));
var_dump(Yaconf::get("c", 1));
print_r(Yaconf::get("d"));
print_r(Yaconf::get("common/a"));
?>
--EXPECTF--
Array
Expand Down Expand Up @@ -92,3 +93,24 @@ Array
)

)
Array
(
[common] => Array
(
[domain] => Array
(
[allow] => Array
(
[0] => 127.0.0.1
)

[deny] => Array
(
[0] => 192.168.1.0
)

)

)

)
2 changes: 1 addition & 1 deletion tests/003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Check for Yaconf
--SKIPIF--
<?php if (!extension_loaded("yaconf")) print "skip"; ?>
--INI--
yaconf.directory={PWD}/inis/
yaconf.directory={PWD}/inis/data
--FILE--
<?php
var_dump(Yaconf::get("d.bar.application.test"));
Expand Down
2 changes: 1 addition & 1 deletion tests/004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Check for Yaconf info
--SKIPIF--
<?php if (!extension_loaded("yaconf")) print "skip"; ?>
--INI--
yaconf.directory={PWD}/inis/
yaconf.directory={PWD}/inis/data
--FILE--
<?php
phpinfo(INFO_MODULES);
Expand Down
10 changes: 10 additions & 0 deletions tests/006.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,19 @@ yaconf.directory={PWD}/inis/err/section
--FILE--
<?php
var_dump(Yaconf::has("a"));
var_dump(Yaconf::has("b"));
?>
--EXPECTF--
PHP Warning: Nesting too deep? Only less than 16 level inheritance is allowed in Unknown on line 0

Warning: Nesting too deep? Only less than 16 level inheritance is allowed in Unknown on line 0
bool(false)
array(2) {
["name"]=>
string(1) "1"
["student"]=>
array(1) {
["test"]=>
string(1) "2"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions tests/inis/data/common/a.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[common]
domain = 'com'
domain.allow[] = '127.0.0.1'
domain.deny[] = '192.168.1.0'
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions tests/inis/err/section/b.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name=1
[student:name]
test=2
2 changes: 1 addition & 1 deletion tests/issue19.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ISSUE #19 Memory leak on foreach and reference
--SKIPIF--
<?php if (!extension_loaded("yaconf")) print "skip"; ?>
--INI--
yaconf.directory={PWD}/inis/
yaconf.directory={PWD}/inis/data
--FILE--
<?php
$i = 0;
Expand Down
Loading