Skip to content

Commit a466db3

Browse files
[Validator] Add #[ExtendsValidationFor] to declare new constraints for a class
1 parent 2a2b7ce commit a466db3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@
214214
use Symfony\Component\TypeInfo\TypeResolver\TypeResolverInterface;
215215
use Symfony\Component\Uid\Factory\UuidFactory;
216216
use Symfony\Component\Uid\UuidV4;
217+
use Symfony\Component\Validator\Attribute\ExtendsValidationFor;
217218
use Symfony\Component\Validator\Constraint;
218219
use Symfony\Component\Validator\Constraints\ExpressionLanguageProvider;
219220
use Symfony\Component\Validator\Constraints\Traverse;
@@ -1819,10 +1820,16 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
18191820
if (class_exists(ValidatorAttributeMetadataPass::class) && (!($config['enable_attributes'] ?? false) || !$container->getParameter('kernel.debug'))) {
18201821
// The $reflector argument hints at where the attribute could be used
18211822
$container->registerAttributeForAutoconfiguration(Constraint::class, function (ChildDefinition $definition, Constraint $attribute, \ReflectionClass|\ReflectionMethod|\ReflectionProperty $reflector) {
1822-
$definition->addTag('validator.attribute_metadata');
1823+
$definition->addTag('validator.attribute_metadata')
1824+
->addTag('container.excluded', ['source' => 'because it\'s a validator constraint extension']);
18231825
});
18241826
}
18251827

1828+
$container->registerAttributeForAutoconfiguration(ExtendsValidationFor::class, function (ChildDefinition $definition, ExtendsValidationFor $attribute) {
1829+
$definition->addTag('validator.attribute_metadata', ['for' => $attribute->class])
1830+
->addTag('container.excluded', ['source' => 'because it\'s a validator constraint extension']);
1831+
});
1832+
18261833
if ($config['enable_attributes'] ?? false) {
18271834
$validatorBuilder->addMethodCall('enableAttributeMapping');
18281835
}

0 commit comments

Comments
 (0)