wdalmut/simplini

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

0.0.2 2014-03-24 20:56 UTC

This package is not auto-updated.

Last update: 2024-11-09 14:55:33 UTC


README

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