Fixed usage of TranslatorInterface in form extension (fixes #30591)
This commit is contained in:
parent
affaa45537
commit
d8092c7b7b
@ -19,7 +19,8 @@ use Symfony\Component\Form\ChoiceList\Factory\PropertyAccessDecorator;
|
|||||||
use Symfony\Component\Form\Extension\Core\Type\TransformationFailureExtension;
|
use Symfony\Component\Form\Extension\Core\Type\TransformationFailureExtension;
|
||||||
use Symfony\Component\PropertyAccess\PropertyAccess;
|
use Symfony\Component\PropertyAccess\PropertyAccess;
|
||||||
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
|
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
|
||||||
use Symfony\Component\Translation\TranslatorInterface;
|
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
|
||||||
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the main form extension, which loads the core functionality.
|
* Represents the main form extension, which loads the core functionality.
|
||||||
@ -32,8 +33,14 @@ class CoreExtension extends AbstractExtension
|
|||||||
private $choiceListFactory;
|
private $choiceListFactory;
|
||||||
private $translator;
|
private $translator;
|
||||||
|
|
||||||
public function __construct(PropertyAccessorInterface $propertyAccessor = null, ChoiceListFactoryInterface $choiceListFactory = null, TranslatorInterface $translator = null)
|
/**
|
||||||
|
* @param TranslatorInterface|null $translator
|
||||||
|
*/
|
||||||
|
public function __construct(PropertyAccessorInterface $propertyAccessor = null, ChoiceListFactoryInterface $choiceListFactory = null, $translator = null)
|
||||||
{
|
{
|
||||||
|
if (null !== $translator && !$translator instanceof LegacyTranslatorInterface && !$translator instanceof TranslatorInterface) {
|
||||||
|
throw new \TypeError(sprintf('Argument 3 passed to %s() must be an instance of %s, %s given.', __METHOD__, TranslatorInterface::class, \is_object($translator) ? \get_class($translator) : \gettype($translator)));
|
||||||
|
}
|
||||||
$this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
|
$this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
|
||||||
$this->choiceListFactory = $choiceListFactory ?: new CachingFactoryDecorator(new PropertyAccessDecorator(new DefaultChoiceListFactory(), $this->propertyAccessor));
|
$this->choiceListFactory = $choiceListFactory ?: new CachingFactoryDecorator(new PropertyAccessDecorator(new DefaultChoiceListFactory(), $this->propertyAccessor));
|
||||||
$this->translator = $translator;
|
$this->translator = $translator;
|
||||||
|
@ -15,7 +15,8 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
|||||||
use Symfony\Component\Form\FormError;
|
use Symfony\Component\Form\FormError;
|
||||||
use Symfony\Component\Form\FormEvent;
|
use Symfony\Component\Form\FormEvent;
|
||||||
use Symfony\Component\Form\FormEvents;
|
use Symfony\Component\Form\FormEvents;
|
||||||
use Symfony\Component\Translation\TranslatorInterface;
|
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
|
||||||
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Christian Flothmann <christian.flothmann@sensiolabs.de>
|
* @author Christian Flothmann <christian.flothmann@sensiolabs.de>
|
||||||
@ -24,8 +25,14 @@ class TransformationFailureListener implements EventSubscriberInterface
|
|||||||
{
|
{
|
||||||
private $translator;
|
private $translator;
|
||||||
|
|
||||||
public function __construct(TranslatorInterface $translator = null)
|
/**
|
||||||
|
* @param TranslatorInterface|null $translator
|
||||||
|
*/
|
||||||
|
public function __construct($translator = null)
|
||||||
{
|
{
|
||||||
|
if (null !== $translator && !$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;
|
$this->translator = $translator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,8 @@ namespace Symfony\Component\Form\Extension\Core\Type;
|
|||||||
use Symfony\Component\Form\AbstractTypeExtension;
|
use Symfony\Component\Form\AbstractTypeExtension;
|
||||||
use Symfony\Component\Form\Extension\Core\EventListener\TransformationFailureListener;
|
use Symfony\Component\Form\Extension\Core\EventListener\TransformationFailureListener;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Symfony\Component\Translation\TranslatorInterface;
|
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
|
||||||
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Christian Flothmann <christian.flothmann@sensiolabs.de>
|
* @author Christian Flothmann <christian.flothmann@sensiolabs.de>
|
||||||
@ -23,8 +24,14 @@ class TransformationFailureExtension extends AbstractTypeExtension
|
|||||||
{
|
{
|
||||||
private $translator;
|
private $translator;
|
||||||
|
|
||||||
public function __construct(TranslatorInterface $translator = null)
|
/**
|
||||||
|
* @param TranslatorInterface|null $translator
|
||||||
|
*/
|
||||||
|
public function __construct($translator = null)
|
||||||
{
|
{
|
||||||
|
if (null !== $translator && !$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;
|
$this->translator = $translator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user