2017 © Pedro Peláez
 

library config-serviceprovider

A configuration ServiceProvider for Silex based on Symfony Config component with support for YAML, TOML and JSON

image

yosymfony/config-serviceprovider

A configuration ServiceProvider for Silex based on Symfony Config component with support for YAML, TOML and JSON

  • Sunday, June 8, 2014
  • by yosymfony
  • Repository
  • 1 Watchers
  • 7 Stars
  • 1,061 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Config ServiceProvider for Silex

A configuration ServiceProvider for Silex based on Symfony Config component with support for YAML, TOML (0.2.0) and JSON., (*1)

Build Status Latest Stable Version Scrutinizer Quality Score Total Downloads, (*2)

Installation

Use Composer to install Yosyfmony ConfigServiceProvider package:, (*3)

Add the following to your composer.json and run composer update., (*4)

"require": {
    "yosymfony/config-serviceprovider": "1.2-dev"
}

More informations about the package on Packagist., (*5)

Usage

Register the ServiceProvider:, (*6)

$app->register(new ConfigServiceProvider());

You can set a collection of locations where it should look for files and reference it only with the file's name, (*7)

$app->register(new ConfigServiceProvider(array(
    __dir__.'/config',
    '/var/www/general-config'
)));

Load a configuration file:

$repository = $app['configuration']->load('user.yml');

// or load with absolute path:
$repository = $app['configuration']->load('/var/config/user1.yml');

.dist files

This library have support to .dist files. The location of a file follow the next hierachy:, (*8)

  • filename.ext
  • filename.ext.dist (if filename.ext not exists)

Load inline configuration:

use Yosymfony\Silex\ConfigServiceProvider\Config;

$repository = $app['configuration']->load('server: "mail.yourname.com"', Config::TYPE_YAML);
// or
$repository = $app['configuration']->load('server = "mail.yourname.com"', Config::TYPE_TOML);

Repository

The configuration file is loaded to a repository. A repository is a wrapper with array access interface that supply methods for validating configurations values and merge with other repositories., (*9)

$repository->get('name', 'noname'); // If 'name' not exists return 'noname'
$repository['name']; // Get the element in 'name' key

Validating configurations

The values and the structure can be validated using a definition class from Symfony Config component. For example, for this configuratión file:, (*10)

# Yaml file
port: 25
server: "mail.yourname.com"

you can create the below definition:, (*11)

use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;

class MyConfigDefinitions implements ConfigurationInterface
{
    public function getConfigTreeBuilder()
    {
        $treeBuilder = new TreeBuilder();
        $rootNode = $treeBuilder->root(0);

        $rootNode->children()
            ->integerNode('port')
                ->end()
            ->scalarNode('server')
                ->end()
        ->end();

        return $treeBuilder;
    }
}

and check your repository: $repository->validateWith(new MyConfigDefinitions()); An exception will be thrown if any definition constraints are violated., (*12)

Operations

The operation mergeWith was deprecated since version 1.2.0 and replaced by union method., (*13)

Unions

You can get the union of repository A with other B with C as result: $resultC = $repositoryA->union($repositoryB);. The values of $repositoryB have less priority than $repositoryA., (*14)

Intersections

You can get the intersection of repository A with other B with C as result: $resultC = $repositoryA->intersection($repositoryB);. The values of $repositoryB have less priority than $repositoryA., (*15)

Create a blank repository

Create a blank repository is too easy. You only need create a instance of ConfigRepository and use the array interface or set method to insert new values:, (*16)

use Yosymfony\Silex\ConfigServiceProvider\ConfigRepository;

//...

$repository = new ConfigRepository();
$repository->set('key1', 'value1');
// or
$repository['key1'] = 'value1';

and the next, you merge with others or validate it., (*17)

Unit tests

You can run the unit tests with the following command:, (*18)

$ cd your-path/vendor/yosymfony/config-serviceprovider
$ composer.phar install --dev
$ phpunit

The Versions

08/06 2014

dev-master

9999999-dev

A configuration ServiceProvider for Silex based on Symfony Config component with support for YAML, TOML and JSON

  Sources   Download

MIT

The Requires

 

json configuration config silex toml yaml

08/06 2014

dev-develop

dev-develop

A configuration ServiceProvider for Silex based on Symfony Config component with support for YAML, TOML and JSON

  Sources   Download

MIT

The Requires

 

json configuration config silex toml yaml

07/06 2014

v1.2.2

1.2.2.0

A configuration ServiceProvider for Silex based on Symfony Config component with support for YAML, TOML and JSON

  Sources   Download

MIT

The Requires

 

json configuration config silex toml yaml

07/06 2014

v1.2.1

1.2.1.0

A configuration ServiceProvider for Silex based on Symfony Config component with support for YAML, TOML and JSON

  Sources   Download

MIT

The Requires

 

json configuration config silex toml yaml

18/05 2014

v1.2.0

1.2.0.0

A configuration ServiceProvider for Silex based on Symfony Config component with support for YAML, TOML and JSON

  Sources   Download

MIT

The Requires

 

json configuration config silex toml yaml

16/09 2013

v1.1.0

1.1.0.0

A configuration ServiceProvider for Silex based on Symfony Config component with support for yaml and toml

  Sources   Download

MIT

The Requires

 

configuration config silex toml yaml

16/09 2013

v1.0.0

1.0.0.0

A configuration ServiceProvider for Silex based on Symfony Config component with support for yaml and toml

  Sources   Download

MIT

The Requires

 

configuration config silex toml yaml