bug #31164 [Validator] fix LegacyTranslatorProxy (nicolas-grekas)

This PR was merged into the 4.2 branch.

Discussion
----------

[Validator] fix LegacyTranslatorProxy

| Q             | A
| ------------- | ---
| Branch?       | 4.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #31161
| License       | MIT
| Doc PR        | -

Commits
-------

b1f3284669 [Validator] fix LegacyTranslatorProxy
This commit is contained in:
Nicolas Grekas 2019-04-18 15:30:30 +02:00
commit 5379e7317f

View File

@ -22,15 +22,26 @@ class LegacyTranslatorProxy implements LegacyTranslatorInterface, TranslatorInte
{
private $translator;
public function __construct(TranslatorInterface $translator)
/**
* @param LegacyTranslatorInterface|TranslatorInterface $translator
*/
public function __construct($translator)
{
if (!$translator instanceof LocaleAwareInterface) {
if ($translator instanceof LegacyTranslatorInterface) {
// no-op
} elseif (!$translator instanceof TranslatorInterface) {
throw new \InvalidArgumentException(sprintf('The translator passed to "%s()" must implement "%s" or "%s".', __METHOD__, TranslatorInterface::class, LegacyTranslatorInterface::class));
} elseif (!$translator instanceof LocaleAwareInterface) {
throw new \InvalidArgumentException(sprintf('The translator passed to "%s()" must implement "%s".', __METHOD__, LocaleAwareInterface::class));
}
$this->translator = $translator;
}
public function getTranslator(): TranslatorInterface
/**
* @return LegacyTranslatorInterface|TranslatorInterface
*/
public function getTranslator()
{
return $this->translator;
}