Skip to content

Instantly share code, notes, and snippets.

@pgilad
Created February 28, 2016 09:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pgilad/4e0c76568b8ce99dca89 to your computer and use it in GitHub Desktop.
Save pgilad/4e0c76568b8ce99dca89 to your computer and use it in GitHub Desktop.
Env.php that loads yml and json files from env-config and returns the accumulated configuartion
<?php
ini_set('display_errors', true);
ini_set('display_startup_errors', true);
error_reporting(E_ALL ^ E_DEPRECATED ^ E_NOTICE ^ E_STRICT);
if (function_exists('newrelic_disable_autorum')) {
newrelic_disable_autorum();
}
$files = glob(__DIR__ . '/env-config/*.{json,yml}', GLOB_BRACE);
return array_reduce($files, function($config, $file) {
$extension = pathinfo($file, PATHINFO_EXTENSION);
if ($extension === 'json') {
$contents = json_decode(file_get_contents($file), true);
} elseif ($extension === 'yml') {
$contents = yaml_parse_file($file);
} else {
throw new Exception("Unrecognized file extension to load: $extension");
}
return array_merge($config, $contents);
}, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment