Simple INI reader (enhance php ini parser)
PHP
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
tests
.gitignore
.travis.yml
README.md
composer.json
phpunit.xml.dist

README.md

Simple INI

A simple INI reader. This project is heavly inspired to Zend_Config_Ini

Unit Testing Status

Build Status

Sections

Simplini allow multiple sections and section (multiple sections) override(s).

[prod]
a="ciao"
b=hello

[dev : prod]
a="ecco"

Force the dev state:

<?php
$conf = new Config();
$conf->load(__DIR__ . '/my.ini', 'dev');

echo $conf->prod()->a; // will echo "ecco"

Arrays

Array support

a[] = one
a[] = two
a[] = three
<?php
$conf = new Config();
$conf->load(__DIR__ . '/my.ini');

var_dump(conf->a); // array(one,two,three)

Nested objects

Nested Objects

[production]
a.b.c = "Hello"
<?php
$conf = new Config();
$conf->load(__DIR__ . '/my.ini');

echo conf->production()->a->b-c; // will echo "hello"

Multiple sections

[mysql]
db.host = "localhost"
db.user = "user"
db.password = "password"

[redis]
nosql.a.host = "localhost"
nosql.b.host = "192.168.2.2"
<?php
$conf = new Config();
$conf->load(__DIR__ . '/my.ini');

echo $conf->mysql()->db->host; // localhost

echo $conf->redis()->nosql->b->host; // 192.168.2.2

Override strategies

You have three types of overrides.

[prod]
a = hello

[dev : prod]
a = ciao

[mysql]
host = localhost

[dm : mysql]
host = 192.168.2.2

[redis]
host = localhost

[rd : redis]
host = 192.168.3.3

Override all

<?php
$conf = new Config();
$conf->load(__DIR__ . '/a.ini', true);

echo $conf->prod()->a; // echo ciao
echo $conf->mysql()->host; // echo 192.168.2.2
echo $conf->redis()->host; // echo 192.168.3.3

Override only one section

<?php
$conf = new Config();
$conf->load(__DIR__ . '/a.ini', 'dev');

echo $conf->prod()->a; // echo ciao
echo $conf->mysql()->host; // echo localhost
echo $conf->redis()->host; // echo localhost

Override a group of sections

<?php
$conf = new Config();
$conf->load(__DIR__ . '/a.ini', array('dev', 'dm'));

echo $conf->prod()->a; // echo ciao
echo $conf->mysql()->host; // echo 192.168.2.2
echo $conf->redis()->host; // echo localhost