Split Symfony2 YAML validation configuration file

Important : as j0k pointed out in the comments, Symfony 2.5 changed the way validation files are loaded. Refer to this StackOverflow answer if you are using Symfony >= 2.5.

Defining validation rules for several entities in the same file can really be a pain. Unfortunately, Symfony2 only looks in the validation.yml file by default. Let’s see how we can split the following file:

The solution lies in the AcmeBlogExtension class, and more specifically in the validator.mapping.loader.yaml_files_loader.mapping_files parameter. As this parameter defines the list of files used to map configuration rules to their entities, we just have to add our owns to the list.

In the extension, I assume that the validation files are stored in the Resources/config/validation directory. For the record, here are the files:

If you don’t want to list yourself the files, you can use the Finder class to inspect the directory for you.