[FrameworkBundle] decorate the ValidatorBuilder's translator with LegacyTranslatorProxy
This commit is contained in:
parent
dc2edaffe2
commit
a12656eaad
@ -97,6 +97,7 @@ use Symfony\Component\Translation\Command\XliffLintCommand as BaseXliffLintComma
|
||||
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 @@ class FrameworkExtension extends Extension
|
||||
|
||||
$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' => []];
|
||||
|
@ -50,6 +50,7 @@ use Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer;
|
||||
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 @@ abstract class FrameworkExtensionTest extends TestCase
|
||||
$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]);
|
||||
|
@ -258,7 +258,11 @@ class ValidatorBuilder implements ValidatorBuilderInterface
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user