borobudur / config
Borobudur Config Component
Installs: 568
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Type:borobudur-component
Requires
- php: >=5.4.0
- symfony/yaml: 2.7.*
Requires (Dev)
- codeclimate/php-test-reporter: dev-master
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2017-10-06 09:44:13 UTC
README
Borobudur\Config
provides configuration manager and infrastructure for php 5.4+. This project inspired from Symfony framework.
- Configuration manager
- Config definition infrastructure
- Multiple configuration with prepend or append behavior
- File loader (load or write configuration file)
Installation
- Get Composer
- Install Borobudur\Config with
composer require borobudur/config
- Add composer autoload on your main PHP file:
require __DIR__.'/vendor/autoload.php';
Example
Example 1 - Config Definition
use Borobudur\Config\ConfigDefinitionInterface; use Borobudur\Config\Configuration; use Borobudur\Config\Definition\Builder\TreeConfigBuilder; class ConfigDefinition implements ConfigDefinitionInterface { public function getConfigTreeBuilder() { $tree = new TreeConfigBuilder(); $root = $tree->root('framework'); $root ->children() ->scalarNode('host') ->defaultValue('localhost') ->end() ->integerNode('port')->end() ->booleanNode('secure') ->defaultFalse() ->end() ->end() ; return $tree; } } $config->prepend(new ConfigDefinition(), array( array( 'port' => 80 ) )); $config->get('framework'); /* Output: array( 'port' => 80, 'host' => 'localhost', 'secure' => false ) */
Example 2 - File Loader
use Borobudur\Config\FileLoader; use Borobudur\Config\FileLoader\FileLocator; $loader = new FileLoader(); $configs = $loader->import(new FileLocator('config.yml')); // parse yaml file configuration to array $loader->write($configs, 'config.ini'); // write array configuration to ini file.