Skip to content

Commit 40ad682

Browse files
Make trans + %count% parameter resolve plurals
1 parent 655aab9 commit 40ad682

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

Extension/Csrf/CsrfExtension.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Form\AbstractExtension;
1515
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
16+
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
1617
use Symfony\Contracts\Translation\TranslatorInterface;
1718

1819
/**
@@ -28,11 +29,14 @@ class CsrfExtension extends AbstractExtension
2829

2930
/**
3031
* @param CsrfTokenManagerInterface $tokenManager The CSRF token manager
31-
* @param TranslatorInterface $translator The translator for translating error messages
32+
* @param TranslatorInterface|null $translator The translator for translating error messages
3233
* @param string|null $translationDomain The translation domain for translating
3334
*/
34-
public function __construct(CsrfTokenManagerInterface $tokenManager, TranslatorInterface $translator = null, string $translationDomain = null)
35+
public function __construct(CsrfTokenManagerInterface $tokenManager, $translator = null, string $translationDomain = null)
3536
{
37+
if (null !== $translator && !$translator instanceof LegacyTranslatorInterface && !$translator instanceof TranslatorInterface) {
38+
throw new \TypeError(sprintf('Argument 2 passed to %s() must be an instance of %s, %s given.', __METHOD__, TranslatorInterface::class, \is_object($translator) ? \get_class($translator) : \gettype($translator)));
39+
}
3640
$this->tokenManager = $tokenManager;
3741
$this->translator = $translator;
3842
$this->translationDomain = $translationDomain;

Extension/Csrf/EventListener/CsrfValidationListener.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Form\Util\ServerParams;
1919
use Symfony\Component\Security\Csrf\CsrfToken;
2020
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
21+
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
2122
use Symfony\Contracts\Translation\TranslatorInterface;
2223

2324
/**
@@ -40,8 +41,14 @@ public static function getSubscribedEvents()
4041
);
4142
}
4243

43-
public function __construct(string $fieldName, CsrfTokenManagerInterface $tokenManager, string $tokenId, string $errorMessage, TranslatorInterface $translator = null, string $translationDomain = null, ServerParams $serverParams = null)
44+
/**
45+
* @param TranslatorInterface|null $translator
46+
*/
47+
public function __construct(string $fieldName, CsrfTokenManagerInterface $tokenManager, string $tokenId, string $errorMessage, $translator = null, string $translationDomain = null, ServerParams $serverParams = null)
4448
{
49+
if (null !== $translator && !$translator instanceof LegacyTranslatorInterface && !$translator instanceof TranslatorInterface) {
50+
throw new \TypeError(sprintf('Argument 5 passed to %s() must be an instance of %s, %s given.', __METHOD__, TranslatorInterface::class, \is_object($translator) ? \get_class($translator) : \gettype($translator)));
51+
}
4552
$this->fieldName = $fieldName;
4653
$this->tokenManager = $tokenManager;
4754
$this->tokenId = $tokenId;

Extension/Csrf/Type/FormTypeCsrfExtension.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\Form\Util\ServerParams;
2020
use Symfony\Component\OptionsResolver\OptionsResolver;
2121
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
22+
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
2223
use Symfony\Contracts\Translation\TranslatorInterface;
2324

2425
/**
@@ -33,8 +34,14 @@ class FormTypeCsrfExtension extends AbstractTypeExtension
3334
private $translationDomain;
3435
private $serverParams;
3536

36-
public function __construct(CsrfTokenManagerInterface $defaultTokenManager, bool $defaultEnabled = true, string $defaultFieldName = '_token', TranslatorInterface $translator = null, string $translationDomain = null, ServerParams $serverParams = null)
37+
/**
38+
* @param TranslatorInterface|null $translator
39+
*/
40+
public function __construct(CsrfTokenManagerInterface $defaultTokenManager, bool $defaultEnabled = true, string $defaultFieldName = '_token', $translator = null, string $translationDomain = null, ServerParams $serverParams = null)
3741
{
42+
if (null !== $translator && !$translator instanceof LegacyTranslatorInterface && !$translator instanceof TranslatorInterface) {
43+
throw new \TypeError(sprintf('Argument 4 passed to %s() must be an instance of %s, %s given.', __METHOD__, TranslatorInterface::class, \is_object($translator) ? \get_class($translator) : \gettype($translator)));
44+
}
3845
$this->defaultTokenManager = $defaultTokenManager;
3946
$this->defaultEnabled = $defaultEnabled;
4047
$this->defaultFieldName = $defaultFieldName;

Extension/Validator/Type/UploadValidatorExtension.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Form\AbstractTypeExtension;
1515
use Symfony\Component\OptionsResolver\Options;
1616
use Symfony\Component\OptionsResolver\OptionsResolver;
17+
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
1718
use Symfony\Contracts\Translation\TranslatorInterface;
1819

1920
/**
@@ -25,8 +26,14 @@ class UploadValidatorExtension extends AbstractTypeExtension
2526
private $translator;
2627
private $translationDomain;
2728

28-
public function __construct(TranslatorInterface $translator, string $translationDomain = null)
29+
/**
30+
* @param TranslatorInterface $translator
31+
*/
32+
public function __construct($translator, string $translationDomain = null)
2933
{
34+
if (!$translator instanceof LegacyTranslatorInterface && !$translator instanceof TranslatorInterface) {
35+
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)));
36+
}
3037
$this->translator = $translator;
3138
$this->translationDomain = $translationDomain;
3239
}

0 commit comments

Comments
 (0)