Easy class for getting ENV values with casting and default value fallback. Great for frameworks like Nette.
The best way to install honklegion/environment
is using Composer:
$ composer require honklegion/environment
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
This package is currently maintaining by these authors.