APP_ENV=dev
DATABASE_DNS=mysql:host=localhost;dbname=test;
DATABASE_USER="root"
DATABASE_PASSWORD=root
MODULE_ENABLED=true
<?php
use DevCoder\DotEnv;
$absolutePathToEnvFile = __DIR__ . '/.env';
(new DotEnv($absolutePathToEnvFile))->load();
/**
* string(33) "mysql:host=localhost;dbname=test;"
*/
var_dump(getenv('DATABASE_DNS'));
/**
* Removes double and single quotes from the variable:
*
* string(4) "root"
*/
var_dump(getenv('DATABASE_USER'));
/**
* Processes booleans as such:
*
* bool(true)
*/
var_dump(getenv('MODULE_ENABLED'));
Ideal for small project
Simple and easy!
Also the variables are parsed according to the configuration passed as parameter to the constructor. The available processors are:
VARIABLE=false
will be processed to bool(false)
NOTE: VARIABLE="true"
will be processed to string(4) "true"
VARIABLE="anything"
will be processed to string(8) "anything"