Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 74a18bc

Browse filesBrowse 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 ------- a12656e [FrameworkBundle] decorate the ValidatorBuilder's translator with LegacyTranslatorProxy
2 parents c009e60 + a12656e commit 74a18bc
Copy full SHA for 74a18bc

File tree

3 files changed

+18
-2
lines changed
Filter options

3 files changed

+18
-2
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+7Lines 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' => []];

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
+6-1Lines 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]);

‎src/Symfony/Component/Validator/ValidatorBuilder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/ValidatorBuilder.php
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,11 @@ public function setConstraintValidatorFactory(ConstraintValidatorFactoryInterfac
258258
*/
259259
public function setTranslator(LegacyTranslatorInterface $translator)
260260
{
261-
$this->translator = $translator instanceof LegacyTranslatorProxy ? $translator->getTranslator() : $translator;
261+
$this->translator = $translator;
262+
263+
while ($this->translator instanceof LegacyTranslatorProxy) {
264+
$this->translator = $this->translator->getTranslator();
265+
}
262266

263267
return $this;
264268
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.