2017 © Pedro Peláez
 

library silex-config-service-provider

Silex config service provider based on Illuminate Config package for Silex.

image

nunopress/silex-config-service-provider

Silex config service provider based on Illuminate Config package for Silex.

  • Friday, November 4, 2016
  • by namaless
  • Repository
  • 1 Watchers
  • 1 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Config Service Provider

Config Service Provider based on Illuminate Config package for Silex Microframework., (*1)

The Service Provider is installable with Composer:, (*2)

composer require nunopress/silex-config-service-provider

Parameters

config.path

Path defined to find every php files inside for loading., (*3)

config.environment (optional)

Search before in the defined path and then in the environment path (config.path/config.environment format). The service use config.merge_factory for help the developers to change only what you need in the different environment instead to write again all the configuration set., (*4)

Here a simple example:, (*5)

// config/view.php
return [
    'twig' => [
        'path' => realpath(__DIR__ . '/../views'),
        'options' => [
            'debug' => false,
            'cache' => realpath(__DIR__ . '/../../storage/cache/twig')
        ]
    ]
];

// config/development/view.php
return [
    'twig' => [
        'options' => [
            'debug' => true,
            'cache' => false
        ]
    ]
];

// RESULT
[
    'twig' => [
        'path' => realpath(__DIR__ . '/../views'),
        'options' => [
            'debug' => true,
            'cache' => false
        ]
    ]
]

config.merge_factory (optional)

You can configure your merge method instead to use the default merge factory array_replace_recursive:, (*6)

$app['config.merge_factory'] = $app->share($app->protect('config.merge_factory', function (array $old, array $new) {
    return array_merge($old, $new);
}));

Services

For access to config keys you need to use the filename (without extension) before every config keys, example:, (*7)

// config/view.php
return [
    'test' => 'yep'
];

// Access to test key
$app['config']->get('view.test'); // Result: yep

config

The Illuminate\Config\Repository instance. The main way to interact with Config., (*8)

Registering

$app->register(new NunoPress\Silex\Config\Provider\ConfigServiceProvider(), [
    'config.path' => __DIR__ . '/config',
    'config.environment' => ($app['debug']) ? 'dev' : 'prod'
]);

Usage

The Config provider provides a config service:, (*9)

$app->get('/hello', function () use ($app) {
    $name = $app['config']->get('app.name', 'NunoPress');

    return 'Hello ' . $name . '!!';
});

Note

Read the Config reference for the Illuminate Config document to learn more about the various Config functions., (*10)

Traits

NunoPress\Silex\Config\Application\ConfigTrait adds the following shortcuts:, (*11)

config

Access to Config object for retrieve the key requested, for the second param you can define a default value., (*12)

$name = $app->config('app.name', 'NunoPress');

You can use that for set your configuration at runtime:, (*13)

$app->config([
    'newvar' => 'newvalue'
]);

echo $app->config('newvar'); // print newvalue

Define this trait in your Application class:, (*14)

class App extends \Silex\Application
{
    use \NunoPress\Silex\Config\Application\ConfigTrait;
}

$app = new App();

$name = $app->config('app.name', 'NunoPress');

Customization

You can configure the Config object before using it by extending the config service:, (*15)

$app['config'] = $app->share($app->extend('config', function ($config, $app) {
    // Instead to have separate the config items you can share it in the current container
    $items = $config->all();

    foreach ($items as $name => $item) {
        $app[$name] = $item;
    }

    return $config;
}));

The Versions

04/11 2016

dev-master

9999999-dev http://nunopress.com

Silex config service provider based on Illuminate Config package for Silex.

  Sources   Download

MIT

The Requires

 

config silex illuminate service provider

04/11 2016

v1.4.1

1.4.1.0 http://nunopress.com

Silex config service provider based on Illuminate Config package for Silex.

  Sources   Download

MIT

The Requires

 

config silex illuminate service provider

04/11 2016

v1.4.0

1.4.0.0 http://nunopress.com

Silex config service provider based on Illuminate Config package for Silex.

  Sources   Download

MIT

The Requires

 

config silex illuminate service provider

07/09 2016

1.3

1.3.0.0 http://nunopress.com

Pimple Config Service Provider based on Illuminate Config package for Silex Microframework or any Pimple Container project's.

  Sources   Download

MIT

The Requires

 

06/09 2016

v1.2

1.2.0.0 http://nunopress.com

Pimple Config Service Provider based on Illuminate Config package for Silex Microframework or any Pimple Container project's.

  Sources   Download

MIT

The Requires

 

05/09 2016

v1.1

1.1.0.0 http://nunopress.com

Config Service Provider based on Illuminate Config package for Silex Microframework or any Pimple Container project's.

  Sources   Download

MIT

The Requires

 

03/09 2016

1.0

1.0.0.0 http://nunopress.com

The Config Service Provider with Illuminate Config package for Silex Microframework or every Pimple Container project's.

  Sources   Download

MIT

The Requires