Last active
April 26, 2017 14:03
-
-
Save Abban/5820865 to your computer and use it in GitHub Desktop.
Add web environments to Anchor CMS
This file contains 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 | |
switch (WEB_ENV) | |
{ | |
case 'local': | |
case 'development': | |
case 'staging': | |
case 'preview': | |
return array( | |
'default' => 'mysql', | |
'prefix' => 'anchor_', | |
'connections' => array( | |
'mysql' => array( | |
'driver' => 'mysql', | |
'hostname' => 'localhost', | |
'port' => '', | |
'username' => 'root', | |
'password' => 'root', | |
'database' => 'anchor', | |
'charset' => 'utf8' | |
) | |
) | |
); | |
break; | |
case 'production': | |
return array( | |
'default' => 'mysql', | |
'prefix' => 'anchor_', | |
'connections' => array( | |
'mysql' => array( | |
'driver' => 'mysql', | |
'hostname' => 'HOST', | |
'port' => '', | |
'username' => 'USER', | |
'password' => 'PASS', | |
'database' => 'DATABASE', | |
'charset' => 'utf8' | |
) | |
) | |
); | |
break; | |
default: | |
break; | |
} |
This file contains 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 | |
// Define Environments - may be a string or array of options for an environment | |
$environments = array( | |
'local' => array('.local', 'local.'), | |
'development' => '.dev', | |
'staging' => 'stage.', | |
'preview' => 'preview.', | |
); | |
// Get Server name | |
$server_name = $_SERVER['SERVER_NAME']; | |
foreach($environments AS $key => $env) | |
{ | |
if(is_array($env)) | |
{ | |
foreach ($env as $option) | |
{ | |
if(stristr($server_name, $option)) | |
{ | |
define('WEB_ENV', $key); | |
break 2; | |
} | |
} | |
} | |
else | |
{ | |
if(strstr($server_name, $env)) | |
{ | |
define('WEB_ENV', $key); | |
break; | |
} | |
} | |
} | |
// If no environment is default to production | |
if(!defined('WEB_ENV')) define('WEB_ENV', 'production'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment