Skip to content

Commit

Permalink
Introducing env.json for enviromental variables
Browse files Browse the repository at this point in the history
  • Loading branch information
tracend committed Apr 1, 2012
1 parent 66aa23c commit 5af6959
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
env.json
app/plugins
12 changes: 12 additions & 0 deletions env.sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"localhost": {
"base": "",
"plugins": "",
"debug": "true"
},
"domain.com": {
"base": "",
"plugins": "",
"cdn": "http://cdn.'.$_SERVER['SERVER_NAME'].'/"
}
}
54 changes: 26 additions & 28 deletions html/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
********************************************************************************/


// Set to true to enable debug mode (where supported)
define('DEBUG',true);
//===============================================
// ENVIRONMENT SETUP
//===============================================
$env = json_decode( file_get_contents("../env.json") );


//===============================================
// PATHS
Expand All @@ -27,34 +30,29 @@
// full path of where the templates reside
define('TEMPLATES', $_SERVER['DOCUMENT_ROOT'] . WEB_FOLDER . 'templates/');


// find if this is running from localhost
define("IS_LOCALHOST", (strpos($_SERVER['SERVER_NAME'], "localhost") !== false) );


// Optional Attributes

if(IS_LOCALHOST){

// include a BASE constant here if this is a clone site, when you are developing locally
//define('BASE', APP);

// you can set the location of your plugins - by default a subdir in the app folder
//define('PLUGINS', APP . 'plugins/');

} else {

// include a BASE constant here if this is a clone site, when publically released
//define('BASE', APP);

// you can set the location of your plugins - by default a subdir in the app folder
//define('PLUGINS', APP . 'plugins/');

// the url of your content delivery network, if you're using one
//define('CDN', 'http://cdn.' . $_SERVER['SERVER_NAME'] . WEB_FOLDER);
// Process enviromental variables (from env.json)
foreach( $env as $domain => $setup ){
// check the domain against each set
if( strpos($_SERVER['SERVER_NAME'], $domain) !== false ){
// available options: base, plugins, cdn, debug
// - include a BASE constant here if this is a clone site
if( !empty($setup->base) ) eval("define('BASE', '$setup->base');");
// - you can set the location of your plugins - by default a subdir in the app folder
if( !empty($setup->plugins) ) eval("define('PLUGINS', '$setup->plugins');");
if( !empty($setup->cdn) ) eval("define('CDN', '$setup->cdn');");
if( !empty($setup->debug) ) eval("define('DEBUG', '$setup->debug');");
break;
}
var_dump(DEBUG);

}

// Other Constants
// - find if this is running from localhost
define("IS_LOCALHOST", (strpos($_SERVER['SERVER_NAME'], "localhost") !== false) );
// - set to true to enable debug mode (where supported)
if(!defined("DEBUG")) define('DEBUG', false);


//===============================================
// Start the controller
Expand All @@ -66,7 +64,7 @@
// find the core file second
require_once(BASE.'bin/init.php');
} else {
die("Website Offline");
die("Environment varialbes not setup properly. Open env.json and edit as needed...");
}

?>

0 comments on commit 5af6959

Please sign in to comment.