Skip to content

Commit 8f1d4a8

Browse files
committed
feature #13855 Read validation contraints from Resources/config/validation/ sub-dir (GromNaN)
This PR was merged into the 2.7 branch. Discussion ---------- Read validation contraints from Resources/config/validation/ sub-dir When a bundle contains many entities/documents and it uses YAML or XML format instead of annotations, it is convenient to split the validation constraints into several small files. With this simple PR, every files in the `validation` sub-directory will be loaded by the validator like it's done for doctrine mapping. ``` Resources/ config/ doctrine/ Author.orm.yml Post.orm.yml validation/ Author.yml Post.yml ``` | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | [How to split validation yaml files](http://stackoverflow.com/questions/24064813/how-to-split-validation-yaml-files-in-symfony-2-5/24210501#24210501) | License | MIT | Doc PR | symfony/symfony-docs#5060 Read more: http://blog.kevingomez.fr/2013/10/14/split-symfony2-yaml-validation-configuration-file/ Commits ------- e41dcb3 [FrameworkBundle] Read config/validation/*.(xml|yml) files
2 parents 8859259 + 361f166 commit 8f1d4a8

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,17 @@ private function getValidatorMappingFiles(ContainerBuilder $container)
792792
$files[1][] = realpath($file);
793793
$container->addResource(new FileResource($file));
794794
}
795+
796+
if (is_dir($dir = $dirname.'/Resources/config/validation')) {
797+
foreach (Finder::create()->files()->in($dir)->name('*.xml') as $file) {
798+
$files[0][] = $file->getRealpath();
799+
}
800+
foreach (Finder::create()->files()->in($dir)->name('*.yml') as $file) {
801+
$files[1][] = $file->getRealpath();
802+
}
803+
804+
$container->addResource(new DirectoryResource($dir));
805+
}
795806
}
796807

797808
return $files;

0 commit comments

Comments
 (0)