Different environments in the same front controller

If you are familiar with symfony 1.x you should know that the framework comes with a different front controller for each environment, for instance: frontend.php for production, frontend_dev.php for development and frontend_stage.php for stage environment.

Well, I like much to have just one unique front controller which handle the different environments we have. That is what I do in all my projects, and here is the code snippet to do it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
$domainArrayReversed = array_reverse(explode('.', $_SERVER['HTTP_HOST']));
$subdomain = isset($domainArrayReversed[2]) ? $domainArrayReversed[2] : '';

//This is for switching the environment based on the subdomain
$debug = false;
$app = 'frontend';

switch ($subdomain) {
    case 'local':
    case 'dev':
        $env = 'dev';
        $debug = true;
        break;
    case 'stage':
        $env = 'stage';
        break;
    case 'www':
    default:
        $env = 'prod';
        break;
}

require_once(dirname(__FILE__) . '/../config/ProjectConfiguration.class.php');

$configuration = ProjectConfiguration::getApplicationConfiguration($app, $env, $debug);
$sfContext = sfContext::createInstance($configuration);
$sfContext->dispatch();

So with the above script we will be running the application on DEV mode when we use it local.hasheado.com or dev.hasheado.com.

I hope this script will be helpful for you.