In Symfony2, can the validation.yml file be split into multiple files using imports?

前端 未结 8 1135
旧巷少年郎
旧巷少年郎 2020-12-13 10:48

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         


        
8条回答
  •  旧巷少年郎
    2020-12-13 11:03

    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.

提交回复
热议问题