remotelyliving / php-env
A library to marshall environment variables from environments
1.0.0
2020-05-24 20:04 UTC
Requires
- php: >=7.4
- ext-filter: *
- ext-json: *
- ext-mbstring: *
- myclabs/php-enum: ^1.0
Requires (Dev)
- maglnet/composer-require-checker: ^2.0
- php-coveralls/php-coveralls: ^2.2
- phpunit/phpunit: ^9.0
- squizlabs/php_codesniffer: ^3.3
- vimeo/psalm: ^3.7
This package is auto-updated.
Last update: 2024-10-19 23:38:05 UTC
README
php-env
🌎 An Environment Abstraction for PHP 🌎
Use Cases
If you want a boundary between you and your runtime environment, this library can help. If you like to use .env files this library can help.
Installation
composer require remotelyliving/php-env
Usage
Create The Application Environment
<?php // needs to be set before hand through docker or could grab the app environment from cli args // EnvironmentType is an enum that you can extend to add more values to $envType = new EnvironmentType(getenv('ENVIRONMENT')); $envFile = "/my/app/envs/.{$envType}.env"; // we can now create the app environment $env = Environment::createWithEnvFile($envType, $envFile); // tells you which environment you're in $env->is(EnvironmentType::DEVELOPMENT()); // true $env->is(EnvironmentType::PRODUCTION()); // false // tells you if a var exists $env->has('FOO'); // true // returns a value caster of a value that can then be called to get stricter types $env->get('FOO')->asArray(); $env->get('BAR')->asBoolean(); $env->get('BAR')->asInteger();