Right now, I have a file called validation.yml with the validation of all the bundle\'s entities in one file.
validation.yml
Blogger\\BlogBundle\\Ent
This is YAML alternative to @MaksSlesarenko answer.
parameters:
validator.mapping.loader.yaml_files_loader.mapping_files:
- "%kernel.root_dir%/../src/CompanyName/TestBundle/Resources/config/validation/Entity.DbObject.yml"
BTW is there any way to change %kernel.root_dir%/../src/CompanyName/TestBundle/
to some bundle root variable (like %kernel.root_dir%
)?
Another alternative:
public function load(array $configs, ContainerBuilder $container)
{
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$validatorFiles = $container->getParameter('validator.mapping.loader.yaml_files_loader.mapping_files');
$finder = new Finder();
foreach ($finder->files()->in(__DIR__ . '/../Resources/config/validation') as $file) {
$validatorFiles[] = $file->getRealPath();
}
$container->setParameter('validator.mapping.loader.yaml_files_loader.mapping_files', $validatorFiles);
}
This way, using the Finder Component, you don't have to be concerned about touching this file each time you add a new validator file.
Solutions above are not working in Symfony 2.3.
In 2.3 it's easier to load multiple Yml files from loader. For example:
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
$loader->load('services/menu.yml'); //new file to load
Symfony 2.5 broke the above solutions. See: https://stackoverflow.com/a/24210501/175753
Add these lines in load
method of src/Blogger/BlogBundle/DependencyInjection/BloggerBlogExtension.php
.
public function load(array $configs, ContainerBuilder $container)
{
//...
$yamlMappingFiles = $container->getParameter('validator.mapping.loader.yaml_files_loader.mapping_files');
$yamlMappingFiles[] = __DIR__.'/../Resources/config/comment.yml';
$yamlMappingFiles[] = __DIR__.'/../Resources/config/enquiry.yml';
$container->setParameter('validator.mapping.loader.yaml_files_loader.mapping_files', $yamlMappingFiles);
}
As of Symfony
2.7
, XML and Yaml constraint files located in theResources/config/validation
sub-directory of a bundle are loaded.
Prior to2.7
, onlyResources/config/validation.yml
(or .xml) were loaded.
More info at: