Skip to content

Latest commit

 

History

History
57 lines (40 loc) · 2.14 KB

README.md

File metadata and controls

57 lines (40 loc) · 2.14 KB

HonkLegion/Environment

Easy class for getting ENV values with casting and default value fallback. Great for frameworks like Nette.

Coverage Status Tests Downloads this Month Scrutinizer Code Quality Latest stable License

Installation

The best way to install honklegion/environment is using Composer:

$ composer require honklegion/environment

Example

imagine, you have set your ENV as follows:

FOO=false
BAR=1
KEYS=1|2|3

Lets see PHP code

use HonkLegion\Environment;

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

// Using Environment function:
var_dump(Environment::Bool('foo')); //bool(false)

// But we can go even further:
var_dump(Environment::Bool('BAR')); //bool(true)
var_dump(Environment::Float('BAR')); //float(1.0)

// What about multi-values?
var_dump(Environment::array('KEYS', '|', Environment::String)); //array(3) [0 => '1', 1 => '2', 2 => '3'] - notice we have strings
var_dump(Environment::array('KEYS', '|', Environment::Int)); //array(3) [0 => 1, 1 => 2, 2 => 3] - notice we have int

// Default values? No problem!
var_dump(Environment::Bool('prod', true)); //bool(true) * even bin is not set

Development

This package is currently maintaining by these authors.