Skip to content

Commit 98e2030

Browse files
bug #31108 [FrameworkBundle] decorate the ValidatorBuilder's translator with LegacyTranslatorProxy (nicolas-grekas)
This PR was merged into the 4.2 branch. Discussion ---------- [FrameworkBundle] decorate the ValidatorBuilder's translator with LegacyTranslatorProxy | Q | A | ------------- | --- | Branch? | 4.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #31092, #31025 | License | MIT | Doc PR | - This allows defining a translator that implements only the new interface and use it with ValidatorBuilder. ping @dvdknaap, @snebes since you were affected. Commits ------- a12656eaad [FrameworkBundle] decorate the ValidatorBuilder's translator with LegacyTranslatorProxy
2 parents 5dbb0d1 + d21899f commit 98e2030

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
use Symfony\Component\Translation\Translator;
9898
use Symfony\Component\Validator\ConstraintValidatorInterface;
9999
use Symfony\Component\Validator\ObjectInitializerInterface;
100+
use Symfony\Component\Validator\Util\LegacyTranslatorProxy;
100101
use Symfony\Component\WebLink\HttpHeaderSerializer;
101102
use Symfony\Component\Workflow;
102103
use Symfony\Component\Workflow\WorkflowInterface;
@@ -1107,6 +1108,12 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
11071108

11081109
$validatorBuilder = $container->getDefinition('validator.builder');
11091110

1111+
if (class_exists(LegacyTranslatorProxy::class)) {
1112+
$calls = $validatorBuilder->getMethodCalls();
1113+
$calls[1] = ['setTranslator', [new Definition(LegacyTranslatorProxy::class, [new Reference('translator')])]];
1114+
$validatorBuilder->setMethodCalls($calls);
1115+
}
1116+
11101117
$container->setParameter('validator.translation_domain', $config['translation_domain']);
11111118

11121119
$files = ['xml' => [], 'yml' => []];

Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
use Symfony\Component\Serializer\Serializer;
5151
use Symfony\Component\Translation\DependencyInjection\TranslatorPass;
5252
use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass;
53+
use Symfony\Component\Validator\Util\LegacyTranslatorProxy;
5354
use Symfony\Component\Workflow;
5455

5556
abstract class FrameworkExtensionTest extends TestCase
@@ -818,7 +819,11 @@ public function testValidation()
818819
$this->assertSame('setConstraintValidatorFactory', $calls[0][0]);
819820
$this->assertEquals([new Reference('validator.validator_factory')], $calls[0][1]);
820821
$this->assertSame('setTranslator', $calls[1][0]);
821-
$this->assertEquals([new Reference('translator')], $calls[1][1]);
822+
if (class_exists(LegacyTranslatorProxy::class)) {
823+
$this->assertEquals([new Definition(LegacyTranslatorProxy::class, [new Reference('translator')])], $calls[1][1]);
824+
} else {
825+
$this->assertEquals([new Reference('translator')], $calls[1][1]);
826+
}
822827
$this->assertSame('setTranslationDomain', $calls[2][0]);
823828
$this->assertSame(['%validator.translation_domain%'], $calls[2][1]);
824829
$this->assertSame('addXmlMappings', $calls[3][0]);

0 commit comments

Comments
 (0)