Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created December 5, 2020 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/551925d10d0099b0957f0f1d356cc768 to your computer and use it in GitHub Desktop.
Save parzibyte/551925d10d0099b0957f0f1d356cc768 to your computer and use it in GitHub Desktop.
<?php
namespace Parzibyte;
use Exception;
class Utils
{
static function getVarFromEnvironmentVariables($key)
{
if (defined("_ENV_CACHE")) {
$vars = _ENV_CACHE;
} else {
$file = "env.php";
if (!file_exists($file)) {
throw new Exception("The environment file ($file) does not exists. Please create it");
}
$vars = parse_ini_file($file);
define("_ENV_CACHE", $vars);
}
if (isset($vars[$key])) {
return $vars[$key];
} else {
throw new Exception("The specified key (" . $key . ") does not exist in the environment file");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment