[Validator] Add support of nested attributes#41994
Conversation
|
Hey! I think @przemyslaw-bogusz has recently worked with this code. Maybe they can help review this? Cheers! Carsonbot |
|
As this is a new feature it should target |
|
Alright, I'll rebase to 5.4! |
| ]), | ||
| Assert\Choice(choices: ['A', 'B'], message: 'Must be one of %choices%') | ||
| ] | ||
| public $firstName; |
There was a problem hiding this comment.
the Ci reports PHP Fatal error: Constant expression contains invalid operations
nicolas-grekas
left a comment
There was a problem hiding this comment.
Let's wait for the RFC to be merged before merging :)
| Assert\All([ | ||
| 'constraints' => [ | ||
| new Assert\NotNull(), | ||
| new Assert\Range(min: 3), | ||
| ], | ||
| ]), |
There was a problem hiding this comment.
| Assert\All([ | |
| 'constraints' => [ | |
| new Assert\NotNull(), | |
| new Assert\Range(min: 3), | |
| ], | |
| ]), | |
| Assert\All( | |
| constraints: [ | |
| new Assert\NotNull(), | |
| new Assert\Range(min: 3), | |
| ], | |
| ), |
Let's switch to named arguments, like we did for the other constraints.
| } | ||
|
|
||
| if (\PHP_VERSION_ID >= 80100) { | ||
| yield 'nested_attributes' => ['Symfony\Component\Validator\Tests\Fixtures\Attribute\Nested']; |
There was a problem hiding this comment.
| yield 'nested_attributes' => ['Symfony\Component\Validator\Tests\Fixtures\Attribute\Nested']; | |
| yield 'nested_attributes' => ['Symfony\Component\Validator\Tests\Fixtures\NestedAttribute']; |
Let's keep the directory structure flat
11508eb to
bc996cc
Compare
|
Added missing tests for
|
bc996cc to
6635f91
Compare
0a9b7f5 to
1a34fc3
Compare
|
In order to get the PHP 8.0 testsuite green, you need to exclude your new fixtures in |
derrabus
left a comment
There was a problem hiding this comment.
LGTM, once patch-types.php has been updated.
src/Symfony/Component/Validator/Tests/Mapping/Loader/AnnotationLoaderTest.php
Outdated
Show resolved
Hide resolved
Will do, thanks! |
1a34fc3 to
1449450
Compare
|
This is now available in the 8.1 PHP branch. |
|
Thank you @alexandre-daubois. |
…constraints (alexandre-daubois) This PR was merged into the 5.4 branch. Discussion ---------- [Validator] Add attributes documentation of composite constraints Related pull-request: symfony/symfony#41994 Not really sure how to precise it only works for attributes in PHP 8.1, not 8.0. If you have a solution, please let me know! Commits ------- 7099e3f [Validator] Add attributes documentation of composite constraints
|
@alexandre-daubois @fabpot |
|
@chekalsky Did you experience any issues when using |
| ], | ||
| 'bar' => new Assert\Range(min: 5), | ||
| 'baz' => new Assert\Required([new Assert\Email()]), | ||
| 'qux' => new Assert\Optional([new Assert\NotBlank()]), |
|
@xabbuh Yes, but only when it is not nested (e.g. I am trying to make one of the properties itself optional). Does it make sense? |
|
Well, |
…ructor (derrabus) This PR was merged into the 7.2 branch. Discussion ---------- [Validator] Add $groups and $payload to Compound constructor | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | N/A | License | MIT While reviewing #49547 I noticed that the `$groups` and `$payload` parameters introduced in #41994 cannot be leveraged in compound constraints. I'd like to change that. Commits ------- bf4207c [Validator] Add $groups and $payload to Compound constructor
Although the RFC (https://wiki.php.net/rfc/new_in_initializers) is in the voting phase (until 14 July), it is already well on its way to passing.
Based on @nikic's development (php/php-src#7153), this makes the development of support possible. It will obviously take a little while before this pull request is merged.
If this pull request is OK for you, I'll get to work on writing the existing documentation for the attribute validation constraints.
Not sure about the Symfony version to target, as
AtLeastOneOfhas been introduced in 5.1. Although, I couldn't find attributes validation documentation for 4.4.