Symfony Bundles evolution

In Symfony, the structure of bundles and their registration has evolved over time.

Symfony 2

In Symfony 2, bundles were first introduced. A bundle is similar to a plugin in other software. Everything in Symfony, including both the core framework functionality and the code written for your application, is considered a bundle. Bundles give you the flexibility to use pre-built features packaged in third-party bundles.

Symfony 3

In Symfony 3, the recommended way to enable bundles in your application was by modifying the app/AppKernel.php file. You would register your bundles in the registerBundles() method of the AppKernel class. This approach allowed you to manage your bundles centrally in one place.

Symfony 4 and later

Symfony 4 introduced a new bundle structure. Instead of registering bundles in AppKernel.php, you now configure them in the config/bundles.php file. This change was made to simplify the bundle management process. In the config/bundles.php file, you specify which bundles should be enabled for any Symfony environment. For example:

// config/bundles.php
return [
   Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
   Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
   Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
   // ... other bundles
];

The all key means that the bundle is enabled for any Symfony environment. This new approach makes it easier to enable or disable bundles based on your project’s needs.

Symfony 5

Symfony 5 continued with the same bundle structure introduced in Symfony 4. The recommended bundle structure was changed, and the new AbstractBundle class defaults to this structure.

In summary, if you’re working with Symfony 4 or later, you’ll find the bundle registration process in the config/bundles.php file rather than AppKernel.php. Make sure to adjust your bundle management accordingly!

When you are using Symfony Flex, the bundles are configures automatically using recipes and you don't need to worry about changing this configuration manually.