Maintainable Bundle Configuration in Symfony

Posted by Matthew Davis on October 2, 2014

When utilising 3rd-party (or your own) bundles in Symfony 2, it’s common for them to come with a set of configuration options that can be added to your config.yml file.

Over time, it’s not uncommon for the config.yml file to become littered with lots of configuration, leading to confusion about where exactly in the file the configuration is stored.

To combat this problem, it’s possible to separate out the bundle configuration making it easy to find what you’re looking for, and making it even easier to remove configuration for a bundle should you decide you don’t need it anymore.

First of all, create the app/config/bundle directory. Within this directory, create a separate file for each bundle’s configuration. For example, jms-serializer.yml. You should end up with a directory tree like this:

app/config/bundle
└── jms-serializer.yml

In your config.yml file, you can then add the following:

imports:
    - { resource: bundle/jms-serializer.yml }

Modifying a bundle’s configuration is now easier as there’s no hunting through a large file to find the right configuration section and to remove a bundle’s configuration, you can now delete the file and the import in config.yml.


Comments