8000 Fixed usage of TranslatorInterface in form extension (fixes #30591) · symfony/symfony@d8092c7 · GitHub
[go: up one dir, main page]

Skip to content

Commit d8092c7

Browse files
committed
Fixed usage of TranslatorInterface in form extension (fixes #30591)
1 parent affaa45 commit d8092c7

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

src/Symfony/Component/Form/Extension/Core/CoreExtension.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
use Symfony\Component\Form\Extension\Core\Type\TransformationFailureExtension;
2020
use Symfony\Component\PropertyAccess\PropertyAccess;
2121
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
22-
use Symfony\Component\Translation\TranslatorInterface;
22+
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
23+
use Symfony\Contracts\Translation\TranslatorInterface;
2324

2425
/**
2526
* Represents the main form extension, which loads the core functionality.
@@ -32,8 +33,14 @@ class CoreExtension extends AbstractExtension
3233
private $choiceListFactory;
3334
private $translator;
3435

35-
public function __construct(PropertyAccessorInterface $propertyAccessor = null, ChoiceListFactoryInterface $choiceListFactory = null, TranslatorInterface $translator = null)
36+
/**
37+
* @param TranslatorInterface|null $translator
38+
*/
39+
public function __construct(PropertyAccessorInterface $propertyAccessor = null, ChoiceListFactoryInterface $choiceListFactory = null, $translator = null)
3640
{
41+
if (null !== $translator && !$translator instanceof LegacyTranslatorInterface && !$translator instanceof TranslatorInterface) {
42+
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)));
43+
}
3744
$this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
3845
$this->choiceListFactory = $choiceListFactory ?: new CachingFactoryDecorator(new PropertyAccessDecorator(new DefaultChoiceListFactory(), $this->propertyAccessor));
3946
$this->translator = $translator;

src/Symfony/Component/Form/Extension/Core/EventListener/TransformationFailureListener.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
use Symfony\Component\Form\FormError;
1616
use Symfony\Component\Form\FormEvent;
1717
use Symfony\Component\Form\FormEvents;
18-
use Symfony\Component\Translation\TranslatorInterface;
18+
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
19+
use Symfony\Contracts\Translation\TranslatorInterface;
1920

2021
/**
2122
* @author Christian Flothmann <christian.flothmann@sensiolabs.de>
@@ -24,8 +25,14 @@ class TransformationFailureListener implements EventSubscriberInterface
2425
{
2526
private $translator;
2627

27-
public function __construct(TranslatorInterface $translator = null)
28+
/**
29+
* @param TranslatorInterface|null $translator
30+
*/
31+
public function __construct($translator = null)
2832
{
33+
if (null !== $translator && !$translator instanceof LegacyTranslatorInterface && !$translator instanceof TranslatorInterface) {
34+
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)));
35+
}
2936
$this->translator = $translator;
3037
}
3138

src/Symfony/Component/Form/Extension/Core/Type/TransformationFailureExtension.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
use Symfony\Component\Form\AbstractTypeExtension;
1515
use Symfony\Component\Form\Extension\Core\EventListener\TransformationFailureListener;
1616
use Symfony\Component\Form\FormBuilderInterface;
17-
use Symfony\Component\Translation\TranslatorInterface;
17+
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
18+
use Symfony\Contracts\Translation\TranslatorInterface;
1819

1920
/**
2021
* @author Christian Flothmann <christian.flothmann@sensiolabs.de>
@@ -23,8 +24,14 @@ class TransformationFailureExtension extends AbstractTypeExtension
2324
{
2425
private $translator;
2526

26-
public function __construct(TranslatorInterface $translator = null)
27+
/**
28+
* @param TranslatorInterface|null $translator
29+
*/
30+
public function __construct($translator = null)
2731
{
32+
if (null !== $translator && !$translator instanceof LegacyTranslatorInterface && !$translator instanceof TranslatorInterface) {
33+
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)));
34+
}
2835
$this->translator = $translator;
2936
}
3037

0 commit comments

Comments
 (0)
0