简体   繁体   中英

Symfony2 multiple Environments

I was wondering if there is any possibility to define multiple environments in Symfony's app.php ?

src/web/app.php:

$kernel = new AppKernel('benchmark', false);
$kernel = new AppKernel('benchmark,dev', false);   // < Incl. the dev tools

Why do I ask? Isn't this a stupid question? Because the default check syntax seems to support multiple environments in_array() or do I misinterpret something here?

src/app/AppKernel.php:

if (in_array($this->getEnvironment(), array('dev'))) {
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            ...
}

The "check" in the app/AppKernel is here to check if there are some bundles you want available in several environments, such as "test" or "dev" for example.

you could then have in your AppKernel following lines :

if (in_array($this->getEnvironment(), array('dev', 'test'))) {
            $bundles[] = new My\Bundle\Uber\MyUberBundle();
            ...
}

that will enable this example bundle in both dev and test environments.

So the app.php doesn't support multiple environment definitions. If you want several envs you can still define new files as app.php and app_dev.php :)

For example an admin.php with itself look something like

<?php

use Symfony\Component\ClassLoader\ApcClassLoader;
use Symfony\Component\HttpFoundation\Request;

$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
require_once __DIR__.'/../app/AppKernel.php';
$kernel = new AppKernel('admin', false);
$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM