1. Go to this page and download the library: Download jpolvora/dotenvy 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/ */
jpolvora / dotenvy example snippets
function (string $key, string $value, array $args)
$dotenvy = new \Dotenvy\Dotenvy(__DIR__); //directory of containing files (.env and .env.example)
$environment = $dotenvy->execute();
if (is_string($environment)) throw new Exception('Invalid env: ' . $environment);
var_dump($environment);
$envoptions = array();
$dotenvy = new \Dotenvy\Dotenvy(__DIR__, $options);
$is_production = TRUE; //my custom logic to get info about production mode
if ($is_production) {
if ($dotenvy->hasCacheFile()) {
$dotenvy->executeFromCache();
} else {
$envresult = $dotenvy->execute();
if (is_array($envresult)) {
$dotenvy->writeCache($envresult);
} else {
throw new \Exception($envresult);
}
}
} else {
//not in production mode
//delete cache file if exist
$dotenvy->clearCache();
$dotenvy->execute();
}