[Validator] fix LegacyTranslatorProxy

This commit is contained in:
Nicolas Grekas 2019-04-18 13:59:33 +02:00
parent cc497a57c5
commit b1f3284669

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;
}