Home

Awesome

Environment

This micro-component aims to make it easy to retrieve environment configuration variables from as many different sources as possible.

<?php
$defaultValues = [
    'ENVIRONMENT_NAME' => 'live',
    'MAINTENANCE_READ_ONLY' => false,
    "ENABLE_NEW_FEATURE" => false
]
$getEnv = new Environment\Source\GetEnv;
$default = new Environment\Source\ArrayObject($defaultValues);
$environment = new Environment\Reader([$getEnv, $default]);
switch ($environment->ENVIRONMENT_NAME) {
    case 'live':
        define('LOG_LEVEL', 'NOTICE');
        break;
    case 'developement':
        define('LOG_LEVEL', 'DEBUG');
        break;
}

// Or maybe use the shortcut API
use Environment\Api as Env;

Env::alwaysReadFrom([$getEnv, $default]);
if (Env::ENVIRONMENT_NAME->is('live')) {
    // ...
}
?>

The competition

Here is a list of some projects I took a look before bothering myself to create this one. If this library is not useful to you, some of these may come to be.

I also put some of the reasons I did not choose to use the given library, just for my memory sake: