, (*1)
A configuration repository for PHP projects., (*2)
Configure is a configuration repository for PHP projects. If your app depends on
some sort of configuration settings, you can use Configure to handle them. It
has a simple API and supports for different kinds of configuration file
formats., (*3)
Install
You can install Configure via Composer:, (*4)
{
"require": {
"petersuhm/configure": "dev-master"
}
}
Basic usage
Using Configure is as simple as instantiating the ConfigurationRepository
class and start adding settings to it:, (*5)
$di->settings = new \Petersuhm\Configure\ConfigurationRepository();
$di->settings->set('template_path', '../templates');
Now you can start querying the repository:, (*6)
$di->settings->get('template_path');
// You can also provide a default value to be returned
$di->settings->get('not_set', 'default_value');
Configure also has supports for arrays:, (*7)
$di->settings->set([
'lang' => 'da',
'country' => 'dk'
]);
// Multi dimensional arrays will be flattened using dot notation
$di->settings->set([
'localization' => [
'lang' => 'da',
'country' => 'dk'
]
]);
$di->settings->get('localization.lang');
$di->settings->get('localization.country');
Using configuration files
As of now, Configure supports YAML and PHP files., (*8)
# config.yml
localization:
lang: da
country: dk
app_name: Configure
# config.php
<?php
return array(
'localization' => array(
'lang' => 'da',
'country' => 'dk'
),
'app_name' => 'Configure'
);
In order to load the files, you need to create an instance of the relevant file
loader class and provide it to the load()
method on the repository:, (*9)
$loader = new \Petersuhm\Configure\Loader\YamlFileLoader('config.yml');
// or
$loader = new \Petersuhm\Configure\Loader\ArrayFileLoader('config.php');
$di->settings->load($loader);
$di->settings->get('localization.lang');
$di->settings->get('app_name');
Testing
Configure is fully covered by unit tests. All code is written using a behavior
driven approach with phpspec., (*10)
$ vendor/bin/phpspec run
Contributing
Please see CONTRIBUTING for details., (*11)
Credits
License
The MIT License (MIT). Please see License File for more information., (*12)