Created
August 13, 2015 19:45
-
-
Save sameg14/36f74f67db12b96a86d8 to your computer and use it in GitHub Desktop.
Symfony index.php front controller switches on ENVIRONMENT
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 | |
use Symfony\Component\Debug\Debug; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\ClassLoader\ApcClassLoader; | |
$env = getenv('ENVIRONMENT'); | |
if (!isset($env) || empty($env)) { | |
die('Please set environment variable in nginx like so: fastcgi_param ENVIRONMENT prod;'); | |
} | |
if ($env == 'production' || $env == 'qa') { | |
$loader = require(__DIR__ . '/../app/bootstrap.php.cache'); | |
require(__DIR__ . '/../app/AppKernel.php'); | |
require(__DIR__ . '/../app/AppCache.php'); | |
$apcLoader = new ApcClassLoader('WFM_APC', $loader); | |
$loader->unregister(); | |
$apcLoader->register(true); | |
$kernel = new AppKernel($env, $debug = false); | |
$kernel->loadClassCache(); | |
$kernel = new AppCache($kernel); | |
// When using the HttpCache, you need to call the method in your front controller | |
// instead of relying on the configuration parameter | |
Request::enableHttpMethodParameterOverride(); | |
$request = Request::createFromGlobals(); | |
$response = $kernel->handle($request); | |
$response->send(); | |
$kernel->terminate($request, $response); | |
} elseif ($env == 'development' || $env == 'integration') { | |
$loader = require_once __DIR__.'/../app/autoload.php'; | |
require(__DIR__ . '/../app/AppKernel.php'); | |
Debug::enable(); | |
$kernel = new AppKernel($env, $debug = true); | |
$request = Request::createFromGlobals(); | |
$response = $kernel->handle($request); | |
$response->send(); | |
$kernel->terminate($request, $response); | |
} else { | |
die($env . ' has no valid code path'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment