bckp / environment
Simple class for getting environment in proper type with fallback
v1.0
2023-08-01 12:26 UTC
Requires
- php: >= 8.0
Requires (Dev)
- nette/tester: ^2.5
- phpstan/phpstan: ^1.0
- vimeo/psalm: ^4.30
This package is auto-updated.
Last update: 2025-04-19 13:28:44 UTC
README
Easy class for getting ENV values with casting and default value fallback. Great for frameworks like Nette.
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.