borobudur/config

This package is abandoned and no longer maintained. No replacement package was suggested.

Borobudur Config Component

Installs: 568

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 3

Forks: 0

Open Issues: 0

Type:borobudur-component

dev-master / 0.1.x-dev 2016-08-23 06:30 UTC

This package is not auto-updated.

Last update: 2017-10-06 09:44:13 UTC


README

Build Status License Code Climate Test Coverage Scrutinizer Code Quality SensioLabsInsight

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

  1. Get Composer
  2. Install Borobudur\Config with composer require borobudur/config
  3. 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.

License

MIT Licensed