davigs/silex-yaml-config-service-provider

Silex ServiceProvider for using YAML configuration files

This package's canonical repository appears to be gone and the package has been frozen as a result.

1.0.5 2017-09-28 18:40 UTC

This package is not auto-updated.

Last update: 2019-01-30 01:10:20 UTC


README

Service provider for Silex for using YAML configuration files.

Installation

To use it add following line to your composer.json:

"require": {
    ...
    "davigs/silex-yaml-config-service-provider": "1.*"
    ...
}

Usage

Include following line of code somewhere in your initial Silex file (index.php or whatever):

$app->register(new Davigs\Silex\YamlConfigServiceProvider(PATH_TO_CONFIG));

Now you have access to all of your configuration variables through $app['config'].

Example

config.yml:

database:
    host: localhost
    user: myuser
    password: mypassword

index.php:

<?php
    require_once __DIR__.'/../vendor/autoload.php';

    $app = new Silex\Application();

    // Considering the config.yml files is in the same directory as index.php
    $app->register(new Davigs\Silex\YamlConfigServiceProvider('config.yml'));

    echo $app['config']['database']['host'];
    ...