2017 © Pedro Peláez
 

library consul-php-envvar

Define missing environment variables from Consul KV and expose them in Symfony 3.2+ containers

image

dlapps/consul-php-envvar

Define missing environment variables from Consul KV and expose them in Symfony 3.2+ containers

  • Monday, July 2, 2018
  • by petrepatrasc
  • Repository
  • 5 Watchers
  • 0 Stars
  • 71 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 6 Versions
  • 3 % Grown

The README.md

Consul PHP Environment Variables

Latest Version on Packagist ![Software License][ico-license] Build Status ![Coverage Status][ico-scrutinizer] Quality Score SensioLabsInsight ![Total Downloads][ico-downloads], (*1)

The library enables developers to retrieve missing environment variables from a Consul KV store and make them available in a running PHP process, and also in a Symfony 3.2+ container., (*2)

The package supports PSR-4 autoloading, is PSR-2 compliant and has been well tested through automated tests. The library is also actively used within the Dreamlabs ecosystem., (*3)

Install

Via Composer, (*4)

``` bash $ composer require dlapps/consul-php-envvar, (*5)


## Usage In order to be able to interact with the library, an instance of the `ConsulEnvManager` class is required. One can easily be obtained through the dedicated builder, like so: ``` php $manager = (new ConsulEnvManagerBuilder())->build();

The same builder can be customised:, (*6)

  • By setting the overwrite flag to true, even if an environment variable has been previously defined, it will still be updated with the latest from Consul.
  • By setting the URL of the Consul server.

``` php $manager = (new ConsulEnvManagerBuilder()) ->withOverwriteEvenIfDefined(true) ->withConsulServer('https://consul.example.com:9123') ->build();, (*7)


Once a `ConsulEnvManager` instance has been obtained, the `ConsulEnvManager::getEnvVarsFromConsul($mappings)` method can be used to provide an array of environment variable mappings to Consul KV paths. An example can be seen below: ``` php $manager = (new ConsulEnvManagerBuilder())->build(); $manager->getEnvVarsFromConsul([ 'MYSQL_HOST' => 'dreamlabs/mysql/host', 'MYSQL_PORT' => 'dreamlabs/mysql/port', 'MYSQL_DB' => 'dreamlabs/mysql/db', 'MYSQL_USER' => 'dreamlabs/mysql/user', 'MYSQL_PASS' => 'dreamlabs/mysql/pass', ]);

After running the snippet above, the currently running PHP process will have access to the MYSQL_HOST, MYSQL_PORT, MYSQL_DB, MYSQL_USER and MYSQL_PASS environment variables., (*8)

In order to also register the environment variables within a Symfony 3.2+ container as default values, the ConsulEnvManager::exposeEnvironmentIntoContainer($container, $mappings) method can be used., (*9)

An example of parameters.php and parameters.yml can be found below:, (*10)

``` php declare(strict_types = 1);, (*11)

$manager = (new \DL\ConsulPhpEnvVar\Builder\ConsulEnvManagerBuilder())->build();, (*12)

$mappings = [ 'MYSQL_HOST' => 'dreamlabs/mysql/host', 'MYSQL_PORT' => 'dreamlabs/mysql/port', 'MYSQL_DB' => 'dreamlabs/mysql/db', 'MYSQL_USER' => 'dreamlabs/mysql/user', 'MYSQL_PASS' => 'dreamlabs/mysql/pass', ];, (*13)

$manager->getEnvVarsFromConsul($mappings); $manager->exposeEnvironmentIntoContainer($container, $mappings);, (*14)


``` yaml parameters: database_host: '%env(MYSQL_HOST)%' database_port: '%env(MYSQL_PORT)%' database_name: '%env(MYSQL_DB)%' database_user: '%env(MYSQL_USER)%' database_password: '%env(MYSQL_PASS)%'

Testing

``` bash $ composer test, (*15)


## PSR-2 Compatibility ``` bash $ composer check-styles $ composer fix-styles

Contributing

Please see CONTRIBUTING and CONDUCT for details., (*16)

Security

If you discover any security related issues, please email petre [at] dreamlabs.ro instead of using the issue tracker., (*17)

Credits

License

The MIT License (MIT). Please see License File for more information., (*18)

The Versions

02/07 2018

dev-master

9999999-dev https://github.com/dlapps/consul-php-envvar

Define missing environment variables from Consul KV and expose them in Symfony 3.2+ containers

  Sources   Download

MIT

The Requires

 

The Development Requires

php variable environment consul

02/02 2017

1.1.1

1.1.1.0 https://github.com/dlapps/consul-php-envvar

Define missing environment variables from Consul KV and expose them in Symfony 3.2+ containers

  Sources   Download

MIT

The Requires

 

The Development Requires

php variable environment consul

02/02 2017

1.1.0

1.1.0.0 https://github.com/dlapps/consul-php-envvar

Define missing environment variables from Consul KV

  Sources   Download

MIT

The Requires

 

The Development Requires

php variable environment consul

02/02 2017

1.0.2

1.0.2.0 https://github.com/dlapps/consul-php-envvar

Define missing environment variables from Consul KV

  Sources   Download

MIT

The Requires

 

The Development Requires

php variable environment consul

02/02 2017

1.0.1

1.0.1.0 https://github.com/dlapps/consul-php-envvar

Define missing environment variables from Consul KV

  Sources   Download

MIT

The Requires

 

The Development Requires

php variable environment consul

02/02 2017

1.0.0

1.0.0.0 https://github.com/dlapps/consul-php-envvar

Define missing environment variables from Consul KV

  Sources   Download

MIT

The Requires

 

The Development Requires

php variable environment consul