2017 © Pedro Peláez
 

library php-env

Envrionment variable helper

image

rb-cohen/php-env

Envrionment variable helper

  • Tuesday, September 6, 2016
  • by rb-cohen
  • Repository
  • 1 Watchers
  • 0 Stars
  • 360 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 15 % Grown

The README.md

php-env

Useful function for getting envrionment varibles for config, with a default fallback if the variable is not set., (*1)

Functions

env($name, $default = null)

Looks for an environment variable called $name, returning $default if the variable is not available., (*2)

$default can be an anonymous function, which will be called to obtain a value if the environment variable is not set., (*3)

Strings 'true', 'false' and 'null' will be converted to their PHP types true, false and null., (*4)

env_to_array($name, $default = array())

Similar to env, calls env internally, but will split the env variable or default value in to an array by comma., (*5)

Also trims the array values., (*6)

resolve_value($value)

Used by env() to recursively call anonymous functions to resolve a value if the variable is not set., (*7)

Examples

Basic config

$config = [
  'mysql' => [
    'host' => env('DB_HOST', 'localhost'),
    'username' => env('DB_USERNAME', 'dbuser'),
    'password' => env('DB_PASSWORD'),
    'dbname' => env('DB_NAME', 'my_database'),
  ]
];

Using an anonymous function

$username = env('USER', function(){
  return exec('whoami');
});

The Versions

06/09 2016

dev-master

9999999-dev

Envrionment variable helper

  Sources   Download

MIT

The Development Requires

by Arron Woods

06/09 2016

1.0.0

1.0.0.0

Envrionment variable helper

  Sources   Download

MIT

The Development Requires

by Arron Woods