abdullahpazarbasi/silex-config-service-provider

A Config Service Provider for Silex. Supported json, ini, php, yaml files.

v1.1.0 2016-03-26 23:34 UTC

README

A Config Service Provider for Silex. Supported json, ini, php (array based), yaml files.

About

The config service provider provides a framework for managing application configuration within a Silex application. If you do not know what Silex is, it is a PHP micro-framework created by the makers of Symfony. You can find out more about Silex here.

Supported config file types:

  • JSON *.json files
  • INI *.ini files
  • PHP *.php files returning array or array structure
  • YAML *.yaml and *.yml files

The service provider uses symfony json decoder to parse json files. And uses symfony yaml parser to parse yaml files.

Also the service provider can scan directories if given as directory paths.

Install

If you haven't got composer:

% wget http://getcomposer.org/composer.phar

Add abdullahpazarbasi/silex-config-service-provider to your composer.json:

    "require": {
        .
        .
        "abdullahpazarbasi/silex-config-service-provider": "~1.0"
    }

or:

% php composer.phar require abdullahpazarbasi/silex-config-service-provider:~1.0

or:

% php composer require abdullahpazarbasi/silex-config-service-provider:~1.0

Usage

use abdullahpazarbasi\Silex\ServiceProvider\SilexConfigServiceProvider;

$oApp = new Silex\Application();

$oApp->register(new SilexConfigServiceProvider(__DIR__ . '/../app/config/config.yml'));

echo $oApp['config']['a_config_parameter_in_configyml'];
use abdullahpazarbasi\Silex\ServiceProvider\SilexConfigServiceProvider;

$oApp = new Silex\Application();

$oApp->register(new SilexConfigServiceProvider(array(
    __DIR__ . '/../app/config1/config.php',
    __DIR__ . '/../app/config2/config.yml'
)));

echo $oApp['config']['a_config_parameter_in_configyml'];
echo $oApp['config']['a_config_parameter_in_configphp'];
use abdullahpazarbasi\Silex\ServiceProvider\SilexConfigServiceProvider;

$oApp = new Silex\Application();

$oApp->register(new SilexConfigServiceProvider(array(
    __DIR__ . '/../app/config1/config.json',
    __DIR__ . '/../app/config2/config3'
)));

echo $oApp['config']['a_config_parameter_in_configjson'];
echo $oApp['config']['a_config_parameter_in_blablayml_in_config3_folder'];
use abdullahpazarbasi\Silex\ServiceProvider\SilexConfigServiceProvider;

$oApp = new Silex\Application();

$oApp->register(new SilexConfigServiceProvider(array(
    __DIR__ . '/../app/config/resolve.php',
    __DIR__ . '/../app/config/config.yml'
)));
$sAppTypeSuffix = $oApp['config']['aAppType2SuffixPairs'][APP_TYPE];
$sEnvironmentSuffix = $oApp['config']['aEnvironment2SuffixPairs'][APP_ENV];
$oApp->register(new SilexConfigServiceProvider(__DIR__ . $oApp['config']['parameters_path' . $sAppTypeSuffix . $sEnvironmentSuffix]));

echo $oApp['config']['testparameter'];

Author

Abdullah Pazarbaşı - Software Architect and Developer www.abdullahpazarbasi.com

License

GPL v3, see license file named LICENSE