-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] add union types #41998
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
[Form] add union types #41998
Conversation
nicolas-grekas
commented
Jul 6, 2021
Q | A |
---|---|
Branch? | 6.0 |
Bug fix? | no |
New feature? | no |
Deprecations? | no |
Tickets | Part of #41424 |
License | MIT |
Doc PR | - |
e5f1b12
to
2259027
Compare
459f57c
to
6fe6d29
Compare
I would appreciate a closer review on this one:
I'd like a closer check on this second commit please. /cc @HeahDude in case you're around, since this touches ChoiceType :) |
6fe6d29
to
2493e24
Compare
@@ -303,7 +301,7 @@ public function handleRequest($request = null); | |||
* | |||
* @throws Exception\AlreadySubmittedException if the form has already been submitted | |||
*/ | |||
public function submit($submittedData, bool $clearMissing = true); | |||
public function submit(string|array|null $submittedData, bool $clearMissing = true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should deprecate not passing anything else before doing this, or we might break some code, I'm even surprised that tests are passing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the interface: implementations can still accept more types. See eg Form
, where I put mixed
here.
src/Symfony/Component/Form/ChoiceList/Factory/CachingFactoryDecorator.php
Show resolved
Hide resolved
@@ -259,7 +259,7 @@ private static function resolveValidationGroups(string|GroupSequence|array|calla | |||
return (array) $groups; | |||
} | |||
|
|||
private static function getConstraintsInGroups(array $constraints, string $group): array | |||
private static function getConstraintsInGroups(array $constraints, string|array $group): array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if $group
can be an array then the implementation looks buggy to me, shouldn't it be something like:
return array_filter($constraints, static function (Constraint $constraint) use ($group) {
return \is_array($group) ? 0 < array_intersect($group, $contraint->groups)
: \in_array($group, $constraint->groups, true);
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method updated to deal with arrays.
In theory it could also be a GroupSequence
, but the code doesn't deal with that.
Would you like to have a look?
2493e24
to
c8a1d0c
Compare
@@ -57,7 +57,7 @@ class GroupSequence | |||
/** | |||
* The groups in the sequence. | |||
* | |||
* @var string[]|string[][]|GroupSequence[] | |||
* @var array<string|string[]|GroupSequence> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/cc @HeahDude here you see that nested GroupSequence
s might be legal
c8a1d0c
to
0480be6
Compare
This PR was merged into the 5.2 branch. Discussion ---------- [Form] backport type fixes | Q | A | ------------- | --- | Branch? | 5.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Backported from #41998 Commits ------- 75691c6 [Form] backport type fixes
This PR was merged into the 4.4 branch. Discussion ---------- [Form] fix some type annotations | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Backported from #41998 The change in `FormValidator` is likely a bug fix, but it could be an incomplete one. `testFieldsValidateInSequenceWithNestedGroupsArray` triggers a call to `getConstraintsInGroups` with an array. I'd appreciate if `@HeahDude`, `@xabbuh`, or anyone with a better knowledge of Form could have a look please. Commits ------- e49441d [Form] fix some type annotations