2017 © Pedro Peláez
 

library dotenv-service-provider

A dotenv ServiceProvider for Silex.

image

ivoba/dotenv-service-provider

A dotenv ServiceProvider for Silex.

  • Wednesday, May 25, 2016
  • by ivoba
  • Repository
  • 1 Watchers
  • 2 Stars
  • 1,985 Installations
  • PHP
  • 0 Dependents
  • 1 Suggesters
  • 1 Forks
  • 2 Open issues
  • 5 Versions
  • 3 % Grown

The README.md

DotenvServiceProvider

A dotenv ServiceProvider for Silex, (*1)

Build Status, (*2)

Caution: this is highly overengineered!

This will set all Env vars that have a given prefix, default is SILEX_, to $app as parameters.
You can pass a function to detect if you want to run dotenv load as well to load vars from an .env file., (*3)

The functionality replaces mainly something like this:, (*4)

$app['env'] = getenv('SILEX_ENV') ? getenv('SILEX_ENV') : 'dev';
if($app['env'] === 'dev'){
    \Dotenv::load();
}
$app['debug'] = getenv('SILEX_DEBUG') ? getenv('SILEX_DEBUG') : false;
$app['this'] = getenv('this') ? getenv('this') : 'that';
//...
\Dotenv::required();

About 10 LOC vs ca. 110 LOC + autoload, yiah
So its actually a bit overdressed for the party, but anyway ;)
Some goodies might be legit as getenv, $_ENV & $_SERVER support., (*5)

Usage

Register the Service:, (*6)

$app->register(new \Ivoba\Silex\EnvProvider(), ['env.options' => ['prefix' => 'MYPREFIX',
    'use_dotenv' => function () use ($app) {
        return $app['env'] === 'dev';
    },
    'dotenv_dir' => __DIR__ . '/../../../..',
    'var_config' => []]
]);
$app['env.load'];

Yo can add default, required, allowed and typecast config options for each var., (*7)

$envOptions = ['env.options' => ['var_config' => [
    'hoo' => [EnvProvider::CONFIG_KEY_ALLOWED => 'this'],
    'zack' => [EnvProvider::CONFIG_KEY_REQUIRED => true],
    'dong' => [EnvProvider::CONFIG_KEY_CAST => EnvProvider::CAST_TYPE_BOOLEAN],
    'zip' => [EnvProvider::CONFIG_KEY_DEFAULT => 'zippi']]
]];
$app->register(new \Ivoba\Silex\EnvProvider(), $envOptions);
$app['env.load'];

The Versions

25/05 2016

dev-master

9999999-dev

A dotenv ServiceProvider for Silex.

  Sources   Download

MIT

The Requires

 

The Development Requires

silex dotenv

25/05 2016

2.0.0

2.0.0.0

A dotenv ServiceProvider for Silex.

  Sources   Download

MIT

The Requires

 

The Development Requires

silex dotenv

03/03 2015

1.1.1

1.1.1.0

A dotenv ServiceProvider for Silex.

  Sources   Download

MIT

The Requires

 

silex dotenv

03/03 2015

1.1.0

1.1.0.0

A dotenv ServiceProvider for Silex.

  Sources   Download

MIT

The Requires

 

silex dotenv

30/01 2015

1.0.0

1.0.0.0

A dotenv ServiceProvider for Silex.

  Sources   Download

MIT

The Requires

 

silex dotenv