[![build status](https://git.buckhill.com.hr/buckhill/config/badges/master/build.svg)](https://git.buckhill.com.hr/buckhill/config/commits/master)

# Configuration loader / getter for PHP projects

Works similar to Laravel or Lumen's `config()` function.

Add an array to the configuration and then retrieve its values by specifying keys delimited by `.` character.

If your MySQL configuration looks like this: 

```php
<?php

$mysql_cfg = [
	'host' => '127.0.0.1',
	'username' => 'test',
	'password' => 'test',
	'port' => 3306
];

```


then you can add it to configuration utility and retrieve specific values from the array. Nesting is supported.

# Adding and retrieving configuration values


To add configuration:

```php
<?php

use function Buckhill\config;

config()->set('mysql', [
	'host' => '127.0.0.1',
	'username' => 'test',
	'password' => 'test',
	'port' => 3306
]);
```


To retrieve specific values:

```php
<?php

use function Buckhill\config;

echo config('mysql.host'); // Echoes '127.0.0.1'
```


## Saving configuration to database

You might want to save configuration to the database. Why? Because multiple servers running `PHP-FPM` can access a single source of configuration.

Configuration is saved in `blob` field, encoded as `JSON`.

## Storing configuration to database

First, you need to create the database table. Check out `sql/` directory for an example file or `Laravel` migration file.

Next, you need to save configuration to the database.

```php
<?php

use function Buckhill\configCreate

$mysql_cfg = [
	'host' => '127.0.0.1',
	'username' => 'test',
	'password' => 'test',
	'port' => 3306
];

$result = configCreate('mysql', $mysql_cfg);
```

## Retrieving configuration from database

Once saved, you need to retrieve the configuration. 

```php
<?php

use function Buckhill\configRetrieve;
use function Buckhill\config;

$config = configRetrieve('mysql');

echo config('mysql.host'); // 127.0.0.1

```
