PHP code example of remotelyliving / php-env
1. Go to this page and download the library: Download remotelyliving/php-env library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
remotelyliving / php-env example snippets
// 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();