thewunder / conphigure
Framework Agnostic Configuration Library
Installs: 13 531
Dependents: 0
Suggesters: 0
Security: 0
Stars: 30
Watchers: 2
Forks: 0
Open Issues: 0
pkg:composer/thewunder/conphigure
Requires
- php: >=8.1
 
Requires (Dev)
- php-coveralls/php-coveralls: ^2.0
 - phpunit/phpunit: ^10.0
 - squizlabs/php_codesniffer: ^2.3
 - symfony/yaml: ^5.0 || ^6.0
 - vlucas/phpdotenv: ^4.2 || ^5.0
 
Suggests
- ext-json: *
 - ext-libxml: *
 - ext-simplexml: *
 - symfony/yaml: ^5.0 || ^6.0
 - vlucas/phpdotenv: ^4.2 || ^5.0
 
README
Conphigure is a framework agnostic library for reading and retrieving configuration. If your application has outgrown a single configuration file this library will be a good choice.
It can read configuration files in the following formats:
- php
 - yaml
 - json
 - xml
 - ini
 - dotenv
 
Conphigure can also read entire directories containing configuration files.
Install
Via Composer
$ composer require thewunder/conphigure
Usage
If you have configuration in myfile.yml
smtp: host: smtp.mycompany.com port: 25
Read it in your php application like the following
$config = Conphigure::create(); //load configuration from a single file $config->read('/directory/myfile.yml'); //get a value $port = $config->get('smtp/port'); //add configuration from somewhere else (cache / database / etc) $arrayFromSomewhere = [ 'database' => [ 'host' => 'localhost' ] ]; $config->addConfiguration($arrayFromSomewhere); //you can also use it like an array $host = $config['database']['host']; $host = $config['database/host']; //throws an exception if a value is missing $value = $config->get('missing/key');
When reading a config directory Conphigure will (by default) organize the configuration in each file into a common root based on the file path.
For example, a directory /directory/config/ with:
- system.yml
 - email.yml
 - logging.yml
 - subdirectory/something.yml
 
//read the directory $config->read('/directory/config/'); //get all configuration as an array $all = $config->all(); var_export($all); /* The result will be: [ 'system' => ['...'], //contents of system.yml 'email' => ['...'], //contents of email.yml 'logging' => ['...'], //contents of logging.yml 'subdirectory' => [ 'something' => ['...'], //contents of subdirectory/something.yml ] ]; */
This allows you to keep things organized, and keep each file very flat.
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.