2017 © Pedro Peláez
 

library pimple-env-provider

A super simple, Silex compatible, lightweight service provider to override Pimple container parameters with the value of environment variables.

image

e-artspace/pimple-env-provider

A super simple, Silex compatible, lightweight service provider to override Pimple container parameters with the value of environment variables.

  • Thursday, October 20, 2016
  • by botk
  • Repository
  • 1 Watchers
  • 1 Stars
  • 55 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

pimple-env-provider

Build Status Code Coverage Scrutinizer Code Quality, (*1)

pimple-env-provider is a super simple, Silex compatible, lightweight service provider to allow overriding of Pimple container parameters with the value of environment variables., (*2)

Install

> composer require e-artspace/pimple-env-provider

Usage

The container's parameters allowed to be overridden must be declared in env.prefix array. Foreach parameter a cast service name must be supplied (custom or predefined)., (*3)

Call 'env.overload' before using the container., (*4)

putenv('DEBUG_APP=false');

$container = new \Pimple\Container([
    'debug.app'=> true
]);

$container->register(new \EnvProvider\EnvProvider([
    'env.vars'=>[
        'debug.app'=>'env.cast.boolean'
    ]
]);

assert($container['debug.app'] === true);

$container['env.overload']; // this do the magic

assert($container['debug.app'] === false);

Predefined services:

  • env.cast.strval: cast to a string
  • env.cast.intval: cast to a integer
  • env.cast.json_decode: to an array from a json string
  • env.cast.boolean: cast to boolean 'true','TRUE' oe '1' => true otherwhise false
  • env.name.builder: function to generate environment variable name, by default: environment var name = strtoupper((str_replace('.', '_', *container var name*)));
  • env.prefix: a prefix for generated environment variable name (default is empty)

Create a new cast service:

$container['env.cast.onoff'] = $app->protect(function($str) {
    return (0===strcasecmp('on',$str));
};

Customize env.name.builder service

$container['env.name.builder'] = app->protect(function($name) {
    return strtolower((str_replace('.', '-', $name)));;
})

Developing and Testing with docker

$ docker run --rm -ti -v $PWD/.:/app composer install
$ docker run --rm -ti -v $PWD/.:/app composer vendor/bin/phpunit

License

(c) Enrico Fagnoni MIT License (see file), (*5)

The Versions

20/10 2016

dev-master

9999999-dev

A super simple, Silex compatible, lightweight service provider to override Pimple container parameters with the value of environment variables.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Enrico fagnoni

silex environment service provider pimple 12factor twelve-factor app

20/10 2016

1.0.0

1.0.0.0

A super simple, Silex compatible, lightweight service provider to override Pimple container parameters with the value of environment variables.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Enrico fagnoni

silex environment service provider pimple 12factor twelve-factor app