diff --git a/DependencyInjection/FrameworkExtension.php b/DependencyInjection/FrameworkExtension.php index b390f2978..a52caa46c 100644 --- a/DependencyInjection/FrameworkExtension.php +++ b/DependencyInjection/FrameworkExtension.php @@ -97,6 +97,7 @@ use Symfony\Component\Translation\Translator; use Symfony\Component\Validator\ConstraintValidatorInterface; use Symfony\Component\Validator\ObjectInitializerInterface; +use Symfony\Component\Validator\Util\LegacyTranslatorProxy; use Symfony\Component\WebLink\HttpHeaderSerializer; use Symfony\Component\Workflow; use Symfony\Component\Workflow\WorkflowInterface; @@ -1107,6 +1108,12 @@ private function registerValidationConfiguration(array $config, ContainerBuilder $validatorBuilder = $container->getDefinition('validator.builder'); + if (class_exists(LegacyTranslatorProxy::class)) { + $calls = $validatorBuilder->getMethodCalls(); + $calls[1] = ['setTranslator', [new Definition(LegacyTranslatorProxy::class, [new Reference('translator')])]]; + $validatorBuilder->setMethodCalls($calls); + } + $container->setParameter('validator.translation_domain', $config['translation_domain']); $files = ['xml' => [], 'yml' => []]; diff --git a/Tests/DependencyInjection/FrameworkExtensionTest.php b/Tests/DependencyInjection/FrameworkExtensionTest.php index 862786c9b..b6b520daa 100644 --- a/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -50,6 +50,7 @@ use Symfony\Component\Serializer\Serializer; use Symfony\Component\Translation\DependencyInjection\TranslatorPass; use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass; +use Symfony\Component\Validator\Util\LegacyTranslatorProxy; use Symfony\Component\Workflow; abstract class FrameworkExtensionTest extends TestCase @@ -818,7 +819,11 @@ public function testValidation() $this->assertSame('setConstraintValidatorFactory', $calls[0][0]); $this->assertEquals([new Reference('validator.validator_factory')], $calls[0][1]); $this->assertSame('setTranslator', $calls[1][0]); - $this->assertEquals([new Reference('translator')], $calls[1][1]); + if (class_exists(LegacyTranslatorProxy::class)) { + $this->assertEquals([new Definition(LegacyTranslatorProxy::class, [new Reference('translator')])], $calls[1][1]); + } else { + $this->assertEquals([new Reference('translator')], $calls[1][1]); + } $this->assertSame('setTranslationDomain', $calls[2][0]); $this->assertSame(['%validator.translation_domain%'], $calls[2][1]); $this->assertSame('addXmlMappings', $calls[3][0]);