Skip to content

Commit

Permalink
Switched environment detection mechanism - look for 2 config files (l…
Browse files Browse the repository at this point in the history
…ocal and global).
  • Loading branch information
kip9 committed Jan 28, 2014
1 parent a8f36b4 commit 9c45688
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,47 @@
* NOTE: If you change these, also change the error_reporting() code below
*
*/
define('ENVIRONMENT', 'development');

// Looking for local environment configuration under application/config/environment.php
$appDir = dirname(__FILE__);
if(file_exists($appDir)){
$localEnvConfigFile = $appDir.'/application/config/environment.php';
if(file_exists($localEnvConfigFile)){
include_once($localEnvConfigFile);
}
}
// Looking for global environment configuration under /etc/nilai/environment.php
const NILAI_ENV_CONFIG_GLOBAL = '/etc/nilai/environment.php';
if(!defined('ENVIRONMENT')){
if(file_exists(NILAI_ENV_CONFIG_GLOBAL)){
include_once(NILAI_ENV_CONFIG_GLOBAL);
}
}
if(!defined('ENVIRONMENT')){
define('ENVIRONMENT', 'production');
}

/*
*---------------------------------------------------------------
* ERROR REPORTING
*---------------------------------------------------------------
*
* Different environments will require different levels of error reporting.
* By default development will show errors but testing and live will hide them.
* All environments report lots of info except of production
*/

if (defined('ENVIRONMENT'))
{
switch (ENVIRONMENT)
{
case 'development':
error_reporting(E_ALL);
break;

case 'staging':
break;
case 'production':
error_reporting(0);
break;

default:
exit('The application environment is not set correctly.');
error_reporting(E_ALL);
break;

}
}

Expand Down

0 comments on commit 9c45688

Please sign in to comment.