121

GitHub - thewunder/conphigure: Simple Configuration Reader Component for PHP

 6 years ago
source link: https://github.com/thewunder/conphigure
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.md

Conphigure

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:

  • 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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK