Reputation: 580
I read through the Symfony2 documentation about environments. It only mentions executing the application in different environments by using /app.php or /app_dev.php. The default .htaccess file rewrites requests to / to /app.php which is great for the production environment.
What's the best approach to having my app determine the environment without having to use the specific front controller in the uri? I'm using PagodaBox for my production server and have an APP_ENV variable set to 'production'. Should I just place the conditional logic in app.php to determine which appkernel to use?
$env = getenv('APP_ENV');
if ( ! $env )
{
$env = 'development';
}
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\ClassLoader\ApcClassLoader;
use Symfony\Component\Debug\Debug;
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
require_once __DIR__.'/../app/AppKernel.php';
if ( $env == 'production' )
{
$kernel = new AppKernel('prod', TRUE);
}
elseif ($env == 'testing')
{
// Placeholder for when I'll need a testing environment
}
else
{
Debug::enable();
$kernel = new AppKernel('dev', TRUE);
}
$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
Upvotes: 1
Views: 368
Reputation: 12033
Yes, it`s right decision. For example symfony console do it the same without considering the input parameters
$input = new ArgvInput();
$env = $input->getParameterOption(array('--env', '-e'), getenv('SYMFONY_ENV') ?: 'dev');
$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(array('--no-debug', '')) && $env !== 'prod';
$kernel = new AppKernel($env, $debug);
Upvotes: 1