Last active
December 18, 2015 18:50
-
-
Save selvinortiz/5828875 to your computer and use it in GitHub Desktop.
CRAFT:Env
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 | |
/** | |
* @=ENV | |
* | |
* @author Selvin Ortiz (http://twitter.com/selvinortiz) | |
* | |
* 1. Define the craft path relative to this file | |
* 2. Define the domain name this site is running under | |
* 3. Define the ip address that requested this resource | |
* 4. Define the environment we are working under | |
* | |
* @example | |
* The environment will be determined based on the following conditions | |
* | |
* (local) | |
* The ip address may be 127.0.0.1 | |
* The ip address may be 127.0.0.2 | |
* The domain name may contain the "local" trigger word as in "site.local" or "site.local.dev" | |
* | |
* (dev) | |
* The domain name may contain the "dev" trigger word as in "dev.site.com" | |
* | |
* (stage) | |
* The domain name may contain the "stage" trigger word as in "stage.site.com" | |
* | |
* (live) | |
* When all other conditions fail | |
*/ | |
define('__CRAFT', realpath(__DIR__.'/../craft') ); | |
define('__DOMAIN', $_SERVER['SERVER_NAME']); // Using instead of HTTP_HOST which is defined by the client header! | |
define('__IPADDRESS', $_SERVER['REMOTE_ADDR']); | |
// Sets up the local environment | |
// The local development environment is special and I treat it as such | |
switch ( __IPADDRESS ) | |
{ | |
case '127.0.0.1': // localhost | |
case '127.0.0.2': // vhost | |
define('__ENV', 'local'); | |
break; | |
default: | |
if ( stripos(__DOMAIN, 'local') !== false ) | |
{ | |
define('__ENV', 'local'); | |
} | |
break; | |
} | |
// Checks whether the local environment has been set | |
if ( !defined('__ENV') ) | |
{ | |
if ( stripos(__DOMAIN, 'dev') !== false ) | |
{ | |
define('__ENV', 'dev'); | |
} | |
elseif ( stripos(__DOMAIN, 'stage') !== false ) | |
{ | |
define('__ENV', 'stage'); | |
} | |
else | |
{ | |
define('__ENV', 'live'); | |
} | |
} | |
//-------------------------------------------------------------------------------- | |
// @=CRAFT | |
//-------------------------------------------------------------------------------- | |
$path = __CRAFT.'/app/index.php'; | |
if ( ! is_file($path) ) | |
{ | |
exit('Your craft path is not set up correctly <var>'.__FILE__.'</var>'); | |
} | |
require_once $path; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment