Skip to content

Commit cd35bb1

Browse files
[Contracts] extract LocaleAwareInterface out of TranslatorInterface
1 parent 81e0f38 commit cd35bb1

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

Tests/DependencyInjection/AddValidatorInitializersPassTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\DependencyInjection\Reference;
1818
use Symfony\Component\Validator\DependencyInjection\AddValidatorInitializersPass;
1919
use Symfony\Component\Validator\Util\LegacyTranslatorProxy;
20+
use Symfony\Contracts\Translation\LocaleAwareInterface;
2021
use Symfony\Contracts\Translation\TranslatorInterface;
2122
use Symfony\Contracts\Translation\TranslatorTrait;
2223

@@ -72,7 +73,7 @@ public function testLegacyTranslatorProxy()
7273
}
7374
}
7475

75-
class TestTranslator implements TranslatorInterface
76+
class TestTranslator implements TranslatorInterface, LocaleAwareInterface
7677
{
7778
use TranslatorTrait;
7879
}

Util/LegacyTranslatorProxy.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Validator\Util;
1313

1414
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
15+
use Symfony\Contracts\Translation\LocaleAwareInterface;
1516
use Symfony\Contracts\Translation\TranslatorInterface;
1617

1718
/**
@@ -23,6 +24,9 @@ class LegacyTranslatorProxy implements LegacyTranslatorInterface, TranslatorInte
2324

2425
public function __construct(TranslatorInterface $translator)
2526
{
27+
if (!$translator instanceof LocaleAwareInterface) {
28+
throw new \InvalidArgumentException(sprintf('The translator passed to "%s()" must implement "%s".', __METHOD__, LocaleAwareInterface::class));
29+
}
2630
$this->translator = $translator;
2731
}
2832

ValidatorBuilder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use Symfony\Component\Validator\Mapping\Loader\YamlFileLoader;
3131
use Symfony\Component\Validator\Util\LegacyTranslatorProxy;
3232
use Symfony\Component\Validator\Validator\RecursiveValidator;
33+
use Symfony\Contracts\Translation\LocaleAwareInterface;
3334
use Symfony\Contracts\Translation\TranslatorInterface;
3435
use Symfony\Contracts\Translation\TranslatorTrait;
3536

@@ -332,7 +333,7 @@ public function getValidator()
332333
$translator = $this->translator;
333334

334335
if (null === $translator) {
335-
$translator = new class() implements TranslatorInterface {
336+
$translator = new class() implements TranslatorInterface, LocaleAwareInterface {
336337
use TranslatorTrait;
337338
};
338339
// Force the locale to be 'en' when no translator is provided rather than relying on the Intl default locale

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": "^7.1.3",
20-
"symfony/contracts": "^1.0",
20+
"symfony/contracts": "^1.0.2",
2121
"symfony/polyfill-ctype": "~1.8",
2222
"symfony/polyfill-mbstring": "~1.0"
2323
},

0 commit comments

Comments
 (0)