Helper for processing of configurations.
Download a latest package or use Composer:
composer require czproject/configuration
CzProject\Configuration
requires PHP 5.4.0 or later.
use CzProject\Configuration\Configurator;
$configurator = new Configurator;
$configurator->addConfig(array(
'database' => array(
'host' => 'localhost',
),
));
$configurator->addConfig(array(
'database' => array(
'user' => 'user123',
'password' => 'password123',
),
));
$config = $configurator->getConfig();
/* Returns:
[
database => [
host => 'localhost',
user => 'user123',
password => 'password123',
]
]
*/
use CzProject\Configuration\Configurator;
use CzProject\Configuration\ConfigLoader;
use CzProject\Configuration\Adapters;
$loader = new ConfigLoader;
$loader->addAdapter('json', new Adapters\JsonAdapter);
$loader->addAdapter('php', new Adapters\PhpAdapter);
$loader->addAdapter('neon', new Adapters\NeonAdapter);
$configurator = new Configurator($loader);
$configurator->addConfig('config.json');
$configurator->addConfig('config.local.php');
$config = $configurator->getConfig();
use CzProject\Configuration\Configurator;
$configurator = new Configurator;
$configurator->addConfig(array(
'parameters' => array(
'database' => array(
'host' => 'localhost',
'driver' => 'mysql',
),
),
'messages' => array(
'user' => '%database.user%',
),
));
$configurator->addConfig(array(
'parameters' => array(
'database' => array(
'user' => '%database.host%_user123',
'password' => 'password123',
),
),
));
$config = $configurator->getConfigExpandedBy('parameters');
/* Returns:
[
parameters => [
database => [
host => 'localhost',
driver => 'mysql',
user => 'localhost_user123',
password => 'password123',
]
],
messages => [
user => 'localhost_user123',
]
]
*/
License: New BSD License
Author: Jan Pecha, https://www.janpecha.cz/