petersuhm / configure
A configuration repository for PHP.
Requires
- symfony/yaml: 2.4.*@dev
Requires (Dev)
- phpspec/phpspec: 2.0.*@dev
This package is not auto-updated.
Last update: 2024-11-09 16:01:01 UTC
README
A configuration repository for PHP projects.
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.
Install
You can install Configure via Composer:
{ "require": { "petersuhm/configure": "dev-master" } }
Basic usage
Using Configure is as simple as instantiating the ConfigurationRepository
class and start adding settings to it:
$di->settings = new \Petersuhm\Configure\ConfigurationRepository(); $di->settings->set('template_path', '../templates');
Now you can start querying the repository:
$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:
$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.
# 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:
$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.
$ vendor/bin/phpspec run
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.