Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
This class helps you load your application configs
PHP
Branch: master

README.md

Config4all

Downloads with Composer SensioLabs Insight ReiDuKuduro @gittip

This class helps you load your application configs, it supports php, xml, ini, yml and json files.

It's easy to use, and you can load multiple files with diferent formats at once

How to install via Composer

The recommended way to install is through Composer.

# Install Composer
$ curl -sS https://getcomposer.org/installer | php

# Add Config4all as a dependency
$ php composer.phar require masnathan/config4all:dev-master

Once it's installed, you need to require Composer's autoloader:

require 'vendor/autoload.php';

How it works

You can check a few config examples here

Loading and unloading content

$config = MASNathan\Config\Config();

//You can load as many files as you want, one by one
$config->load('configs/config.php', 'configs/database.php');
//or all the files with a certain extension at the same time
$config->load('configs/*.json');
//you can even load multiple format files at the same time
$config->load('configs/*.json', 'configs/*.yml');
//or can also load multiple files, regardless of the extension
$config->load('configs/*.*');

//This is how you clear all the configurations
$config->clear();

Fetching the information

//To get a value, you just need to know the path to get there
//if you want to know my name, just use the get method and pass the configuration file name
//and the keys to get my name, like this
echo $config->get('config', 'me', 'name');

//here are some other examples
echo $config->get('config', 'github');
echo $config->get('database', 'host');

//if the value that you are trying to get doesn't exist, you'll get a null
//you can also get the entire structure by calling the method get with no arguments
var_dump($config->get());

Setting my own configs

//You can also set new configs on the fly, or change existing ones
$config
    ->set('a', 'b', 'c', 'value')
    ->set('config', 'me', 'name', 'Not Andre Filipe')
    ->set('database', 'host', 'first', 'localhost')
    ->set('database', 'host', 'second', 'somehost')
    ->set('this is a null field');

//This will return 'value'
echo $config->set('a', 'b', 'c');

License

This library is under the MIT License, see the complete license here

Is your project using Config4all? Let me know!

Something went wrong with that request. Please try again.