Skip to content

Instantly share code, notes, and snippets.

@Abban
Last active April 26, 2017 14:03
Show Gist options
  • Save Abban/5820865 to your computer and use it in GitHub Desktop.
Save Abban/5820865 to your computer and use it in GitHub Desktop.
Add web environments to Anchor CMS
<?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;
}
<?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