Symfony: config file secret

That’s explore more Symfony config directory doing here

Go to config file, you will see there’s basic 2 files: packages, routes, and others files:

as symfony is a set of routes & servicesĀ , config file is actually configure those services

and before this, that’s dig first Symfony environment

there’s 2 env by default: dev and prodĀ , and you could have test too if you like to add other env

And, how env work?

Go to see public/ index.php

line 18

$env = $_SERVER['APP_ENV'] ?? 'dev';

This env variable is set to either have APP_ENV or dev

And it pass to Kernel class:

$kernel = new Kernel($env, $debug);

so find out Kernel class, which is in src/Kernel.php

look 3 methods:
registerBundles(), configureContainer() and configureRoutes()

this method is once you had installed the new bundles, it will loads to config/bundles.php file:

return [
    Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
    Symfony\Bundle\WebServerBundle\WebServerBundle::class => ['dev' => true],
    Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true],
    Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
    Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
    Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
    Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true],

and some are load to all, some load to dev, or test env:

Symfony\Bundle\WebServerBundle\WebServerBundle::class => ['dev' => true],

And 2 method: configureContainer()

this is package file loading, which load the into config/packages file or config/service.yaml or config/service_xxx.yaml:

with CONFIG_EXTS constant:

const CONFIG_EXTS = '.{php,xml,yaml,yml}';

it’s load any PHP, XML, YAML. YML files

if it has to load to packages file, it will load into dev, prod or test env by bundles.php definition

And 3rd method: configureRoutes()
basiclly do the same thing, except to the routes file:

protected function configureRoutes(RouteCollectionBuilder $routes)
    $confDir = $this->getProjectDir().'/config';

    $routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob');
    $routes->import($confDir.'/{routes}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob');
    $routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob');

So here it is the core bundle: services ( tools ) where path to go and set to which env by Symfony

and why do we know about this?

well, it will be happend that you might need to change those bundles from dev env to prod env, so if you know those core concept it will get easier to change the env as it is required