Skip to content

Instantly share code, notes, and snippets.

@mtthlm
Created June 23, 2014 17:17
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 mtthlm/d2dc97444558c1cfb907 to your computer and use it in GitHub Desktop.
Save mtthlm/d2dc97444558c1cfb907 to your computer and use it in GitHub Desktop.
Enhanced Foolproof Multi-Environment Config
<?php
define('CRAFT_ENVIRONMENT', call_user_func_array(function ($environments, $fallback) {
if (array_key_exists('APP_ENV', $_SERVER) && in_array($environment = $_SERVER['APP_ENV'], array_keys($environments))) {
return $environment;
}
foreach ($environments as $environment => $value) {
$serverName = $_SERVER['SERVER_NAME'];
if ((is_array($value) && in_array($serverName, $value)) || $e == $value) {
return $environment;
}
}
return $fallback;
}, array(
// Environment Definitions
array(
'local' => array('local.project.com'),
'dev' => array('dev.project.com'),
'staging' => array('staging.project.com'),
),
// Default Environment
'production',
)));
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment