2017 © Pedro Peláez
 

library php-env-dereference

PHP environment variables dereference library.

image

ndobromirov/php-env-dereference

PHP environment variables dereference library.

  • Friday, March 17, 2017
  • by ndobromirov
  • Repository
  • 1 Watchers
  • 1 Stars
  • 401 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 2 % Grown

The README.md

php-env-dereference

Allow dereferencing of environment variables in PHP., (*1)

Overview

This is generally useful, in cloud environments, where different backing services are injected into PHP with some strange names. At that point the developer is either using that strange names in his code or starting to do workarounds., (*2)

This particular library solves this based on the idea from variable dereference feature that is already in PHP engine., (*3)

<?php
$a = 'hello';
$$a = 'world';
// Same output.
echo "$a ${$a}\n", "hello world\n";

This is very similar to the phpdotenv nested variables functionality, but exposing only it with a simpler syntax and allowing recursive dereferencing., (*4)

Library examples

// We have this environment variables.
putenv('MY_VAR_1=1');
putenv('MY_VAR_2=#MY_VAR_1');
putenv('MY_VAR_3=#MY_VAR_2');
putenv('MY_VAR_4=#MY_VAR_2 #MY_VAR_3');

// Simple dereferencing
echo EnvDereference\Variable::get('MY_VAR_3'); // Should output '#MY_VAR_1'.
echo EnvDereference\Variable::getRecursive('MY_VAR_3'); // Should output '1'.

// Multiple dereferencing
echo EnvDereference\Variable::getEmbedded('MY_VAR_4'); // Should output '#MY_VAR_1 #MY_VAR_2'.
echo EnvDereference\Variable::getEmbeddedRecursive('MY_VAR_4'); // Should output '1 1'.

// Provide defaultds for missing variables
echo EnvDereference\Variable::get('MY_MISSING_VAR', 'default'); // Should output 'default'.

Install

composer require ndobromirov/php-env-dereference

Contribute.

The library complies with PSR-2. Validate with composer cs.
The run tests with composer test., (*5)

The Versions

17/03 2017

dev-master

9999999-dev

PHP environment variables dereference library.

  Sources   Download

MIT

The Requires

  • php >=5

 

The Development Requires

17/03 2017

0.3.0

0.3.0.0

PHP environment variables dereference library.

  Sources   Download

MIT

The Requires

  • php >=5

 

The Development Requires

16/03 2017

0.2.0

0.2.0.0

PHP environment variables dereference library.

  Sources   Download

MIT

The Requires

  • php >=5

 

The Development Requires

24/02 2017

0.1.1

0.1.1.0

PHP environment variables dereference library.

  Sources   Download

MIT

The Requires

  • php >=5

 

The Development Requires

24/02 2017

0.1.0

0.1.0.0

PHP environment variables dereference library.

  Sources   Download

MIT

The Requires

  • php >=5

 

The Development Requires