czproject / configuration
Helper for processing of configurations.
v1.0.1
2017-01-16 18:17 UTC
Requires
- php: >=5.4.0
- czproject/arrays: ^1.0
- nette/utils: ^2.3
Requires (Dev)
- nette/neon: ^2.3
- nette/tester: ^1.7
Suggests
- nette/neon: Required by NeonAdapter
This package is auto-updated.
Last update: 2024-10-28 05:18:04 UTC
README
Helper for processing of configurations.
Installation
Download a latest package or use Composer:
composer require czproject/configuration
CzProject\Configuration
requires PHP 5.4.0 or later.
Usage
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', ] ] */
Config files
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();
Parameters & placeholders
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/