Created
February 28, 2016 09:34
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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