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
[Validator] Passing Constraints to Object similar to Assert\Collection #54746
Comments
This kind of configuration typically belongs into class metadata. What's the reason why we don't have configured metadata for those classes in your context? |
Like I said:
For example, the max length of some fields in my use case depends on some configuration that is unique for some clients. |
That does not answer the question for me. So your metadata depends on "some outside value". Why is that a problem? |
Let's say for example I got a Shop system, that on multiple instances of my customers. I don't think it would be a good idea to alter the class Metadata each time the validate function is called? |
What is an "instance" in this context?
I never said you should do that. We just need to make sure, the class metadata can be different for each shop.
I never suggested to do that either. |
Each of my customers gets their own shop instance (a virtual server) with a Magento Shop System.
Theoretically, but I don't see how the Attribute Constraints (the fixed values?) and the dynamic Constraints (the ones that I currently need this feature for) should be mixed. Especially if I'm outside Symfony framework and can't rely on DI |
Description
Discussion from there: #54299
I got some nested Object is want to be validated,
but the Constraints depends on some outside value, so I can't use Attributes on their properties
Using
Assert\Collection
, I could validate them if they were arrays, but that might not always be the case.I could use Serializer to normalize the objects, but that might give a different result in their error messages.
So instead, a new
Assert\ValidObject
(or something) that takes an array of constraints and uses it for validation instead of the Class Metadata.Should probably use PropertyInfo / PropertyAccess to get from the keys to the real properties?
Or maybe a way to extend the use of
Assert\Valid
?Example
Example Entities:
Example:
The text was updated successfully, but these errors were encountered: