1717use ApiPlatform \Metadata \ApiProperty ;
1818use ApiPlatform \Metadata \Property \Factory \PropertyMetadataFactoryInterface ;
1919use ApiPlatform \Symfony \Validator \Metadata \Property \Restriction \PropertySchemaRestrictionMetadataInterface ;
20+ use ApiPlatform \Symfony \Validator \ValidationGroupsExtractorTrait ;
21+ use Psr \Container \ContainerInterface ;
2022use Symfony \Component \Validator \Constraint ;
2123use Symfony \Component \Validator \Constraints \Bic ;
2224use Symfony \Component \Validator \Constraints \CardScheme ;
4749 */
4850final class ValidatorPropertyMetadataFactory implements PropertyMetadataFactoryInterface
4951{
52+ use ValidationGroupsExtractorTrait {
53+ getValidationGroups as extractValidationGroups;
54+ }
55+
5056 /**
5157 * @var string[] A list of constraint classes making the entity required
5258 */
@@ -72,8 +78,13 @@ final class ValidatorPropertyMetadataFactory implements PropertyMetadataFactoryI
7278 /**
7379 * @param PropertySchemaRestrictionMetadataInterface[] $restrictionsMetadata
7480 */
75- public function __construct (private readonly ValidatorMetadataFactoryInterface $ validatorMetadataFactory , private readonly PropertyMetadataFactoryInterface $ decorated , private readonly iterable $ restrictionsMetadata = [])
76- {
81+ public function __construct (
82+ private readonly ValidatorMetadataFactoryInterface $ validatorMetadataFactory ,
83+ private readonly PropertyMetadataFactoryInterface $ decorated ,
84+ private readonly iterable $ restrictionsMetadata = [],
85+ ?ContainerInterface $ container = null ,
86+ ) {
87+ $ this ->container = $ container ;
7788 }
7889
7990 /**
@@ -151,11 +162,8 @@ public function create(string $resourceClass, string $property, array $options =
151162 */
152163 private function getValidationGroups (ValidatorClassMetadataInterface $ classMetadata , array $ options ): array
153164 {
154- if (
155- isset ($ options ['validation_groups ' ])
156- && !\is_callable ($ options ['validation_groups ' ])
157- ) {
158- return $ options ['validation_groups ' ];
165+ if (null !== ($ groups = $ this ->extractValidationGroups ($ options ['validation_groups ' ] ?? null ))) {
166+ return $ groups ;
159167 }
160168
161169 if (!method_exists ($ classMetadata , 'getDefaultGroup ' )) {
0 commit comments