-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] Exclude patterns in auto mapping #32015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
Comments
What do you think about: framework:
validation:
auto_mapping:
App\Entity\:
services: []
exclude:
- App\Entity\User Also, currently you can use the glob syntax to list only the classes you want to include (whitelist). |
I like it better, yes 🙂 You can do a whitelist but I think it defeats the purpose since you have to think about it each time you add a new class. |
This was referenced Jun 17, 2019
xabbuh
added a commit
that referenced
this issue
Oct 30, 2019
…sable auto-validation (dunglas) This PR was squashed before being merged into the 4.4 branch (closes #32107). Discussion ---------- [Validator] Add AutoMapping constraint to enable or disable auto-validation | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #32070, #32015 <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | todo As discussed in #32070 and #32015, it's sometimes mandatory to prevent some classes or properties to be auto mapped (auto-validated). This PR introduces a new constraint, `@AutoMapping` allowing to do exactly that. Examples: Class: ```php use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; /** * @Orm\Entity * @Assert\AutoMapping(false) */ class DoctrineLoaderNoAutoMappingEntity { /** * @Orm\Id * @Orm\Column */ public $id; /** * @Orm\Column(length=20, unique=true) */ public $maxLength; } ``` Property: ```php namespace Symfony\Bridge\Doctrine\Tests\Fixtures; use Doctrine\ORM\Mapping as ORM; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Validator\Constraints as Assert; /** * @Orm\Entity */ class DoctrineLoaderEntity extends DoctrineLoaderParentEntity { /** * @Orm\Id * @Orm\Column */ public $id; /** * @Orm\Column(length=10) * @Assert\AutoMapping(false) */ public $noAutoMapping; } ``` The rules are the following: * If the constraint is present on a property, and set to true, auto-mapping is always on, regardless of the config, and of any class level annotation * If the constraint is present on a property, and set to false, auto-mapping is always off, regardless of the config, and of any class level annotation * If the constraint is present on a class, and set to true, auto-mapping is always on except if a the annotation has been added to a specific property, and regardless of the config * If the constraint is present on a class, and set to false, auto-mapping is always off except if a the annotation has been added to a specific property, and regardless of the config Commits ------- f6519ce [Validator] Add AutoMapping constraint to enable or disable auto-validation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
Like autowiring/autoconfiguration, it should be possible to define an exclude glob patterns for the new auto mapping feature.
This way, it should be possible to add auto mapping for an entire directory (like
App\Entity\
) and to exclude some files in it (likeApp\Entity\User
).Example
I'm not sure how we could add this feature with the current way to configure it.
Today we can do:
With this configuration, only the
validator.property_info_loader
is used to load the validation constraints.Maybe something like this would be okay, to look like the services configuration?
It would mean the previous way of configuring it would add the mapping to the
include
key.WDYT?
The text was updated successfully, but these errors were encountered: