2017 © Pedro Peláez
 

library env

Simple library to consume environment variables

image

deinternetjongens/env

Simple library to consume environment variables

  • Wednesday, May 4, 2016
  • by Bartjuh4
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2,131 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 6 Forks
  • 0 Open issues
  • 4 Versions
  • 31 % Grown

The README.md

env

Build Status Scrutinizer Code Quality, (*1)

Simple library to get environment variables converted to simple types., (*2)

Installation

This package is installable and autoloadable via Composer as oscarotero/env., (*3)

$ composer require deinternetjongens/env

Example

// Using getenv function:
var_dump(getenv('FOO')); //string(5) "false"

// Using Env:
var_dump(Env::get('FOO')); //bool(false)

Available conversions:

  • "false" is converted to boolean false
  • "true" is converted to boolean true
  • "null" is converted to null
  • If the string contains only numbers is converted to an integer
  • If the string has quotes, remove them

To configure the conversion, you can use the following constants (all enabled by default):, (*4)

  • Env::CONVERT_BOOL To convert boolean values
  • Env::CONVERT_NULL To convert null values
  • Env::CONVERT_INT To convert integer values
  • Env::STRIP_QUOTES To remove the quotes of the strings
//Convert booleans and null, but not integers or strip quotes
Env::$options = Env::CONVERT_BOOL | Env::CONVERT_NULL;

Default value

By default, if the value does not exits, returns null, but you can change for any other value:, (*5)

Env::$default = false;

The env() function

If you don't want to complicate with classes and namespaces, you can use the env() function, like in Laravel or other libraries:, (*6)

Env::init(); //expose the function to globals

//now you can use it

var_dump(env('FOO'));

The Versions

04/05 2016

dev-master

9999999-dev

Simple library to consume environment variables

  Sources   Download

MIT

The Requires

  • php >=5.2

 

env

04/05 2016

v1.0.2

1.0.2.0

Simple library to consume environment variables

  Sources   Download

MIT

The Requires

  • php >=5.2

 

env

31/12 2015

v1.0.1

1.0.1.0 https://github.com/oscarotero/env

Simple library to consume environment variables

  Sources   Download

MIT

The Requires

  • php >=5.2

 

env

30/12 2015

v1.0.0

1.0.0.0 https://github.com/oscarotero/env

Simple library to consume environment variables

  Sources   Download

MIT

The Requires

  • php >=5.2

 

env