-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] fix some type annotations #42012
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
use Symfony\Component\PropertyAccess\PropertyAccess; | ||
use Symfony\Component\PropertyAccess\PropertyAccessorInterface; | ||
use Symfony\Component\PropertyAccess\PropertyPath; | ||
use Symfony\Component\PropertyAccess\PropertyPathInterface; | ||
|
||
/** | ||
* Adds property path support to a choice list factory. | ||
|
@@ -59,19 +60,17 @@ public function getDecoratedFactory() | |
/** | ||
* {@inheritdoc} | ||
* | ||
* @param iterable $choices The choices | ||
* @param callable|string|PropertyPath|null $value The callable or path for | ||
* generating the choice values | ||
* @param mixed $value | ||
* | ||
* @return ChoiceListInterface The choice list | ||
* @return ChoiceListInterface | ||
*/ | ||
public function createListFromChoices($choices, $value = null) | ||
{ | ||
if (\is_string($value)) { | ||
$value = new PropertyPath($value); | ||
} | ||
|
||
if ($value instanceof PropertyPath) { | ||
if ($value instanceof PropertyPathInterface) { | ||
$accessor = $this->propertyAccessor; | ||
$value = function ($choice) use ($accessor, $value) { | ||
// The callable may be invoked with a non-object/array value | ||
|
@@ -88,18 +87,17 @@ public function createListFromChoices($choices, $value = null) | |
/** | ||
* {@inheritdoc} | ||
* | ||
* @param callable|string|PropertyPath|null $value The callable or path for | ||
* generating the choice values | ||
* @param mixed $value | ||
* | ||
* @return ChoiceListInterface The choice list | ||
* @return ChoiceListInterface | ||
*/ | ||
public function createListFromLoader(ChoiceLoaderInterface $loader, $value = null) | ||
{ | ||
if (\is_string($value)) { | ||
$value = new PropertyPath($value); | ||
} | ||
|
||
if ($value instanceof PropertyPath) { | ||
if ($value instanceof PropertyPathInterface) { | ||
$accessor = $this->propertyAccessor; | ||
$value = function ($choice) use ($accessor, $value) { | ||
// The callable may be invoked with a non-object/array value | ||
|
@@ -116,13 +114,13 @@ public function createListFromLoader(ChoiceLoaderInterface $loader, $value = nul | |
/** | ||
* {@inheritdoc} | ||
* | ||
* @param array|callable|string|PropertyPath|null $preferredChoices The preferred choices | ||
* @param callable|string|PropertyPath|null $label The callable or path generating the choice labels | ||
* @param callable|string|PropertyPath|null $index The callable or path generating the view indices | ||
* @param callable|string|PropertyPath|null $groupBy The callable or path generating the group names | ||
* @param array|callable|string|PropertyPath|null $attr The callable or path generating the HTML attributes | ||
* @param mixed $preferredChoices | ||
* @param mixed $label | ||
* @param mixed $index | ||
* @param mixed $groupBy | ||
* @param mixed $attr | ||
* | ||
* @return ChoiceListView The choice list view | ||
* @return ChoiceListView | ||
*/ | ||
public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean using mixed for a decorator makes sense as the class does not know what it decorates that might have widened the range of accepted parameters types. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I agree with this :) |
||
{ | ||
|
@@ -132,7 +130,7 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null, | |
$label = new PropertyPath($label); | ||
} | ||
|
||
if ($label instanceof PropertyPath) { | ||
if ($label instanceof PropertyPathInterface) { | ||
$label = function ($choice) use ($accessor, $label) { | ||
return $accessor->getValue($choice, $label); | ||
}; | ||
|
@@ -142,7 +140,7 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null, | |
$preferredChoices = new PropertyPath($preferredChoices); | ||
} | ||
|
||
if ($preferredChoices instanceof PropertyPath) { | ||
if ($preferredChoices instanceof PropertyPathInterface) { | ||
$preferredChoices = function ($choice) use ($accessor, $preferredChoices) { | ||
try { | ||
return $accessor->getValue($choice, $preferredChoices); | ||
|
@@ -157,7 +155,7 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null, | |
$index = new PropertyPath($index); | ||
} | ||
|
||
if ($index instanceof PropertyPath) { | ||
if ($index instanceof PropertyPathInterface) { | ||
$index = function ($choice) use ($accessor, $index) { | ||
return $accessor->getValue($choice, $index); | ||
}; | ||
|
@@ -167,7 +165,7 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null, | |
$groupBy = new PropertyPath($groupBy); | ||
} | ||
|
||
if ($groupBy instanceof PropertyPath) { | ||
if ($groupBy instanceof PropertyPathInterface) { | ||
$groupBy = function ($choice) use ($accessor, $groupBy) { | ||
try { | ||
return $accessor->getValue($choice, $groupBy); | ||
|
@@ -182,7 +180,7 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null, | |
$attr = new PropertyPath($attr); | ||
} | ||
|
||
if ($attr instanceof PropertyPath) { | ||
if ($attr instanceof PropertyPathInterface) { | ||
$attr = function ($choice) use ($accessor, $attr) { | ||
return $accessor->getValue($choice, $attr); | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -260,8 +260,16 @@ private static function resolveValidationGroups($groups, FormInterface $form) | |
|
||
private static function getConstraintsInGroups($constraints, $group) | ||
{ | ||
return array_filter($constraints, static function (Constraint $constraint) use ($group) { | ||
return \in_array($group, $constraint->groups, true); | ||
$groups = (array) $group; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is coming from \Symfony\Component\Validator\Constraints\GroupSequence::$groups and according to it's type, $group itself could also be a GroupSequence again. So there is still something not right. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's true, yet nobody reported this as a bug ever, so that the urgency on this is zero on my side :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using a nested array seems to be the same as using a nested GroupSequence. If the nested group sequence is not supported, we probably should just remove the type from GroupSequence::$groups. It's also not documented in https://symfony.com/doc/current/validation/sequence_provider.html |
||
|
||
return array_filter($constraints, static function (Constraint $constraint) use ($groups) { | ||
foreach ($groups as $group) { | ||
if (\in_array($group, $constraint->groups, true)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
}); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.