Skip to content

Instantly share code, notes, and snippets.

@mmoscosa
Last active December 17, 2015 10:09
Show Gist options
  • Save mmoscosa/5592822 to your computer and use it in GitHub Desktop.
Save mmoscosa/5592822 to your computer and use it in GitHub Desktop.
<?php
/**
* Set up environment (development vs. production).
*/
$environment = 'production';
// Switch environment on hostname for requests coming through HTTP protocol
$hostname = !empty($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : false;
$developmentHostnames = array(
'dev.test.peachymondays.com', // localhost development (mmoscosa)
'peachymondays_dev.mmoscosa.homelinux.net',
'localhost' // Added by JA for local dev environment
);
if (in_array($hostname, $developmentHostnames)) {
$environment = 'development';
}
// Switch environment by environment variable for shells run from command-line
if (getenv('CAKE_ENV')) {
$environment = getenv('CAKE_ENV');
}
// Set correct environment
Configure::write('environment', $environment);
$debug = 0;
// Enable debugging in development environment
if ($environment === 'development') {
$debug = 2;
}
// Enable debugging in production environment by adding ?debug={level} to URL
if (isset($_GET['debug'])) {
$debug = $_GET['debug'];
} else if (isset($_COOKIE['debug'])) {
$debug = $_COOKIE['debug'];
}
if ($debug > 0) {
setcookie('debug', $debug, time() + 3600, '/'); // expire in 1 hour
} elseif ($debug === '0') {
setcookie('debug', '', time() - 3600, '/'); // expired 1 hour ago
}
// Set correct debug level
Configure::write('debug', $debug);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment