Skip to content

Commit

Permalink
feature #13855 Read validation contraints from Resources/config/valid…
Browse files Browse the repository at this point in the history
…ation/ 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
  • Loading branch information
fabpot committed Mar 9, 2015
2 parents 0f00f7c + e41dcb3 commit 6963887
Showing 1 changed file with 11 additions and 0 deletions.
Expand Up @@ -792,6 +792,17 @@ private function getValidatorMappingFiles(ContainerBuilder $container)
$files[1][] = realpath($file);
$container->addResource(new FileResource($file));
}

if (is_dir($dir = $dirname.'/Resources/config/validation')) {
foreach (Finder::create()->files()->in($dir)->name('*.xml') as $file) {
$files[0][] = $file->getRealpath();
}
foreach (Finder::create()->files()->in($dir)->name('*.yml') as $file) {
$files[1][] = $file->getRealpath();
}

$container->addResource(new DirectoryResource($dir));
}
}

return $files;
Expand Down

0 comments on commit 6963887

Please sign in to comment.