Skip to content

Commit 0364135

Browse files
bug #31925 [Form] fix usage of legacy TranslatorInterface (nicolas-grekas)
This PR was merged into the 4.2 branch. Discussion ---------- [Form] fix usage of legacy TranslatorInterface | Q | A | ------------- | --- | Branch? | 4.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- 0fbfefe [Form] fix usage of legacy TranslatorInterface
2 parents 51299b4 + 0fbfefe commit 0364135

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
use Symfony\Component\Form\FormView;
2121
use Symfony\Component\OptionsResolver\Options;
2222
use Symfony\Component\OptionsResolver\OptionsResolver;
23-
use Symfony\Component\Translation\TranslatorInterface;
23+
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
24+
use Symfony\Contracts\Translation\TranslatorInterface;
2425

2526
class FileType extends AbstractType
2627
{
@@ -35,8 +36,14 @@ class FileType extends AbstractType
3536

3637
private $translator;
3738

38-
public function __construct(TranslatorInterface $translator = null)
39+
/**
40+
* @param TranslatorInterface|null $translator
41+
*/
42+
public function __construct($translator = null)
3943
{
44+
if (null !== $translator && !$translator instanceof LegacyTranslatorInterface && !$translator instanceof TranslatorInterface) {
45+
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)));
46+
}
4047
$this->translator = $translator;
4148
}
4249

src/Symfony/Component/Form/Tests/Extension/Core/Type/FileTypeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Symfony\Component\Form\RequestHandlerInterface;
1818
use Symfony\Component\HttpFoundation\File\File;
1919
use Symfony\Component\HttpFoundation\File\UploadedFile;
20-
use Symfony\Component\Translation\TranslatorInterface;
20+
use Symfony\Contracts\Translation\TranslatorInterface;
2121

2222
class FileTypeTest extends BaseTypeTest
2323
{

0 commit comments

Comments
 (0)