|
17 | 17 | use ApiPlatform\Metadata\ApiProperty;
|
18 | 18 | use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
|
19 | 19 | use ApiPlatform\Symfony\Validator\Metadata\Property\Restriction\PropertySchemaRestrictionMetadataInterface;
|
| 20 | +use Psr\Container\ContainerInterface; |
20 | 21 | use Symfony\Component\Validator\Constraint;
|
21 | 22 | use Symfony\Component\Validator\Constraints\Bic;
|
22 | 23 | use Symfony\Component\Validator\Constraints\CardScheme;
|
@@ -72,7 +73,7 @@ final class ValidatorPropertyMetadataFactory implements PropertyMetadataFactoryI
|
72 | 73 | /**
|
73 | 74 | * @param PropertySchemaRestrictionMetadataInterface[] $restrictionsMetadata
|
74 | 75 | */
|
75 |
| - public function __construct(private readonly ValidatorMetadataFactoryInterface $validatorMetadataFactory, private readonly PropertyMetadataFactoryInterface $decorated, private readonly iterable $restrictionsMetadata = []) |
| 76 | + public function __construct(private readonly ValidatorMetadataFactoryInterface $validatorMetadataFactory, private readonly PropertyMetadataFactoryInterface $decorated, private readonly iterable $restrictionsMetadata = [], private readonly ?ContainerInterface $container = null) |
76 | 77 | {
|
77 | 78 | }
|
78 | 79 |
|
@@ -153,7 +154,18 @@ private function getValidationGroups(ValidatorClassMetadataInterface $classMetad
|
153 | 154 | {
|
154 | 155 | if (
|
155 | 156 | isset($options['validation_groups'])
|
156 |
| - && !\is_callable($options['validation_groups']) |
| 157 | + && ( |
| 158 | + !\is_callable($options['validation_groups']) |
| 159 | + && !( |
| 160 | + 1 === count($options['validation_groups']) |
| 161 | + && null !== ($validationGroups = $options['validation_groups'][0] ?? null) |
| 162 | + && $this->container |
| 163 | + && \is_string($validationGroups) |
| 164 | + && $this->container->has($validationGroups) |
| 165 | + && ($service = $this->container->get($validationGroups)) |
| 166 | + && \is_callable($service) |
| 167 | + ) |
| 168 | + ) |
157 | 169 | ) {
|
158 | 170 | return $options['validation_groups'];
|
159 | 171 | }
|
|
0 commit comments