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
This commit is contained in:
commit
74a18bcff4
@ -97,6 +97,7 @@ use Symfony\Component\Translation\Command\XliffLintCommand as BaseXliffLintComma
|
|||||||
use Symfony\Component\Translation\Translator;
|
use Symfony\Component\Translation\Translator;
|
||||||
use Symfony\Component\Validator\ConstraintValidatorInterface;
|
use Symfony\Component\Validator\ConstraintValidatorInterface;
|
||||||
use Symfony\Component\Validator\ObjectInitializerInterface;
|
use Symfony\Component\Validator\ObjectInitializerInterface;
|
||||||
|
use Symfony\Component\Validator\Util\LegacyTranslatorProxy;
|
||||||
use Symfony\Component\WebLink\HttpHeaderSerializer;
|
use Symfony\Component\WebLink\HttpHeaderSerializer;
|
||||||
use Symfony\Component\Workflow;
|
use Symfony\Component\Workflow;
|
||||||
use Symfony\Component\Workflow\WorkflowInterface;
|
use Symfony\Component\Workflow\WorkflowInterface;
|
||||||
@ -1107,6 +1108,12 @@ class FrameworkExtension extends Extension
|
|||||||
|
|
||||||
$validatorBuilder = $container->getDefinition('validator.builder');
|
$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']);
|
$container->setParameter('validator.translation_domain', $config['translation_domain']);
|
||||||
|
|
||||||
$files = ['xml' => [], 'yml' => []];
|
$files = ['xml' => [], 'yml' => []];
|
||||||
|
@ -50,6 +50,7 @@ use Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer;
|
|||||||
use Symfony\Component\Serializer\Serializer;
|
use Symfony\Component\Serializer\Serializer;
|
||||||
use Symfony\Component\Translation\DependencyInjection\TranslatorPass;
|
use Symfony\Component\Translation\DependencyInjection\TranslatorPass;
|
||||||
use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass;
|
use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass;
|
||||||
|
use Symfony\Component\Validator\Util\LegacyTranslatorProxy;
|
||||||
use Symfony\Component\Workflow;
|
use Symfony\Component\Workflow;
|
||||||
|
|
||||||
abstract class FrameworkExtensionTest extends TestCase
|
abstract class FrameworkExtensionTest extends TestCase
|
||||||
@ -818,7 +819,11 @@ abstract class FrameworkExtensionTest extends TestCase
|
|||||||
$this->assertSame('setConstraintValidatorFactory', $calls[0][0]);
|
$this->assertSame('setConstraintValidatorFactory', $calls[0][0]);
|
||||||
$this->assertEquals([new Reference('validator.validator_factory')], $calls[0][1]);
|
$this->assertEquals([new Reference('validator.validator_factory')], $calls[0][1]);
|
||||||
$this->assertSame('setTranslator', $calls[1][0]);
|
$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('setTranslationDomain', $calls[2][0]);
|
||||||
$this->assertSame(['%validator.translation_domain%'], $calls[2][1]);
|
$this->assertSame(['%validator.translation_domain%'], $calls[2][1]);
|
||||||
$this->assertSame('addXmlMappings', $calls[3][0]);
|
$this->assertSame('addXmlMappings', $calls[3][0]);
|
||||||
|
@ -258,7 +258,11 @@ class ValidatorBuilder implements ValidatorBuilderInterface
|
|||||||
*/
|
*/
|
||||||
public function setTranslator(LegacyTranslatorInterface $translator)
|
public function setTranslator(LegacyTranslatorInterface $translator)
|
||||||
{
|
{
|
||||||
$this->translator = $translator instanceof LegacyTranslatorProxy ? $translator->getTranslator() : $translator;
|
$this->translator = $translator;
|
||||||
|
|
||||||
|
while ($this->translator instanceof LegacyTranslatorProxy) {
|
||||||
|
$this->translator = $this->translator->getTranslator();
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user