diff --git a/DependencyInjection/FrameworkExtension.php b/DependencyInjection/FrameworkExtension.php index a52caa46c..bc09035fa 100644 --- a/DependencyInjection/FrameworkExtension.php +++ b/DependencyInjection/FrameworkExtension.php @@ -95,6 +95,7 @@ use Symfony\Component\Stopwatch\Stopwatch; use Symfony\Component\Translation\Command\XliffLintCommand as BaseXliffLintCommand; use Symfony\Component\Translation\Translator; +use Symfony\Component\Translation\TranslatorInterface; use Symfony\Component\Validator\ConstraintValidatorInterface; use Symfony\Component\Validator\ObjectInitializerInterface; use Symfony\Component\Validator\Util\LegacyTranslatorProxy; @@ -1108,7 +1109,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder $validatorBuilder = $container->getDefinition('validator.builder'); - if (class_exists(LegacyTranslatorProxy::class)) { + if (interface_exists(TranslatorInterface::class) && class_exists(LegacyTranslatorProxy::class)) { $calls = $validatorBuilder->getMethodCalls(); $calls[1] = ['setTranslator', [new Definition(LegacyTranslatorProxy::class, [new Reference('translator')])]]; $validatorBuilder->setMethodCalls($calls); diff --git a/Tests/DependencyInjection/FrameworkExtensionTest.php b/Tests/DependencyInjection/FrameworkExtensionTest.php index b6b520daa..37b958a42 100644 --- a/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -49,6 +49,7 @@ use Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer; use Symfony\Component\Serializer\Serializer; use Symfony\Component\Translation\DependencyInjection\TranslatorPass; +use Symfony\Component\Translation\TranslatorInterface; use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass; use Symfony\Component\Validator\Util\LegacyTranslatorProxy; use Symfony\Component\Workflow; @@ -819,7 +820,7 @@ 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]); - if (class_exists(LegacyTranslatorProxy::class)) { + if (interface_exists(TranslatorInterface::class) && 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]);