-
-
Notifications
You must be signed in to change notification settings - Fork 950
fix(symfony): fix resolving groups in ValidationGroupsExtractorTrait when GroupSequence #7272
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
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| use ApiPlatform\Validator\Exception\ValidationException; | ||
| use ApiPlatform\Validator\ValidatorInterface; | ||
| use Psr\Container\ContainerInterface; | ||
| use Symfony\Component\Validator\Constraints\GroupSequence; | ||
| use Symfony\Component\Validator\Validator\ValidatorInterface as SymfonyValidatorInterface; | ||
|
|
||
| /** | ||
|
|
@@ -25,19 +26,34 @@ | |
| */ | ||
| final class Validator implements ValidatorInterface | ||
| { | ||
| use ValidationGroupsExtractorTrait; | ||
|
|
||
| public function __construct(private readonly SymfonyValidatorInterface $validator, ?ContainerInterface $container = null) | ||
| public function __construct(private readonly SymfonyValidatorInterface $validator, private readonly ?ContainerInterface $container = null) | ||
| { | ||
| $this->container = $container; | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function validate(object $data, array $context = []): void | ||
| { | ||
| $violations = $this->validator->validate($data, null, $this->getValidationGroups($context['groups'] ?? null, $data)); | ||
| if (null !== $validationGroups = $context['groups'] ?? null) { | ||
| if ( | ||
| $this->container | ||
| && \is_string($validationGroups) | ||
| && $this->container->has($validationGroups) | ||
| && ($service = $this->container->get($validationGroups)) | ||
| && \is_callable($service) | ||
| ) { | ||
| $validationGroups = $service($data); | ||
| } elseif (\is_callable($validationGroups)) { | ||
| $validationGroups = $validationGroups($data); | ||
| } | ||
|
|
||
| if (!$validationGroups instanceof GroupSequence) { | ||
| $validationGroups = (array) $validationGroups; | ||
|
Contributor
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. But passing array of groups is not the same as passing GroupSequence 🤔
Contributor
Author
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 just a revert of changes made in #7184 This condition says - if
Contributor
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. Oh right,read it wrong 🤦♂️
Contributor
Author
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. Yes, yes ) Yesterday I did the same )) |
||
| } | ||
| } | ||
|
|
||
| $violations = $this->validator->validate($data, null, $validationGroups); | ||
| if (0 !== \count($violations)) { | ||
| throw new ValidationException($violations); | ||
| } | ||
|
|
||
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 a bc but as it was tagged like a week ago and we revert it impacts should be negligible.