Skip to content

[Validator] Deprecated interface still required for TranslationInterface in Validator #31025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function testSetConstraintValidatorFactory()
public function testSetTranslator()
{
$this->assertSame($this->builder, $this->builder->setTranslator(
$this->getMockBuilder('Symfony\Component\Translation\TranslatorInterface')->getMock())
$this->getMockBuilder('Symfony\Contracts\Translation\TranslatorInterface')->getMock())
);
}

Expand Down
5 changes: 4 additions & 1 deletion src/Symfony/Component/Validator/ValidatorBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,11 @@ public function setConstraintValidatorFactory(ConstraintValidatorFactoryInterfac
/**
* {@inheritdoc}
*/
public function setTranslator(LegacyTranslatorInterface $translator)
public function setTranslator($translator)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing this is a BC break - but that might be OK as maybe nobody extends this class.
If not, we need to rethink the BC layer.

{
if (!$translator instanceof LegacyTranslatorInterface && !$translator instanceof TranslatorInterface) {
throw new \TypeError(sprintf('Argument 1 passed to %s() must be an instance of %s, %s given.', __METHOD__, TranslatorInterface::class, \is_object($translator) ? \get_class($translator) : \gettype($translator)));
}
$this->translator = $translator instanceof LegacyTranslatorProxy ? $translator->getTranslator() : $translator;

return $this;
Expand Down
7 changes: 5 additions & 2 deletions src/Symfony/Component/Validator/ValidatorBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
namespace Symfony\Component\Validator;

use Doctrine\Common\Annotations\Reader;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
use Symfony\Component\Validator\Mapping\Cache\CacheInterface;
use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* A configurable builder for ValidatorInterface objects.
Expand Down Expand Up @@ -134,9 +135,11 @@ public function setConstraintValidatorFactory(ConstraintValidatorFactoryInterfac
/**
* Sets the translator used for translating violation messages.
*
* @param TranslatorInterface|LegacyTranslatorInterface $translator
*
* @return $this
*/
public function setTranslator(TranslatorInterface $translator);
public function setTranslator($translator);

/**
* Sets the default translation domain of violation messages.
Expand Down