-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] Deprecate use of Locale
validation constraint without setting "canonicalize" option to true
#26075
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
Conversation
b9af78c
to
2229cec
Compare
public function __construct($options = null) | ||
{ | ||
if (!($options['canonicalize'] ?? false)) { | ||
@trigger_error('"canonicalize" option with value `false` is deprecated since Symfony 4.1 and will be removed in 5.0. Use "canonicalize"=>true instead.', E_USER_DEPRECATED); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The .... Set it to true
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took as example the syntax at Email::__construct()
. Updated.
@@ -30,7 +30,7 @@ class LocaleValidator extends ConstraintValidator | |||
public function validate($value, Constraint $constraint) | |||
{ | |||
if (!$constraint instanceof Locale) { | |||
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Locale'); | |||
throw new UnexpectedTypeException($constraint, Locale::class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated, should be reverted to ease merger's job
); | ||
} | ||
|
||
/** | ||
* @dataProvider getInvalidLocales | ||
*/ | ||
public function testInvalidLocales($locale) | ||
public function testInvalidLocales(string $locale) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be reverted to ease merger's job
3d1d2d2
to
d465dbd
Compare
Comments addressed. |
d465dbd
to
e5c4c2c
Compare
@fabpot, @nicolas-grekas; should we consider valid a locale including variants? "it_IT_NEDIS_ROJAZ_1901" by instance: http://php.net/manual/en/locale.getallvariants.php |
Only if a real world app needs it. Let's not spend time on theoretical improvements. |
I can't imagine a practical use case using variants right now, but I think we should left a note about the situation in docs, explaining that locales including variants will not be considered valid. WDYT? |
e5c4c2c
to
3e3d565
Compare
Do you know how we could avoid having different results per platform? AppVeyor is reading "en-us.utf8@VARIANT" as a valid locale, while in Travis it is invalid. Shouldn't both environments be using the same bundled ICU data? |
let's make the test case independent from the data version instead, we're not testing the data set here. |
3e3d565
to
7a47aef
Compare
public function __construct($options = null) | ||
{ | ||
if (!($options['canonicalize'] ?? false)) { | ||
@trigger_error('The "canonicalize" option with value `false` is deprecated since Symfony 4.1 and will be removed in 5.0. Set it to `true` instead.', E_USER_DEPRECATED); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we just merged a PR that removes all occurences of "and will be removed in 5.0."
would you mind removing them from this PR please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! Done ;)
7a47aef
to
8a8d1ec
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made some minor comments
public function __construct($options = null) | ||
{ | ||
if (!($options['canonicalize'] ?? false)) { | ||
@trigger_error('The "canonicalize" option with value `false` is deprecated since Symfony 4.1. Set it to `true` instead.', E_USER_DEPRECATED); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of backticks, you should use "
, and make one sentence;
The "canonicalize" option with value "false" is deprecated since Symfony 4.1, set it to "true" instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Message updated. Thank you.
public function testNullIsValid() | ||
/** | ||
* @group legacy | ||
* @expectedDeprecation The "canonicalize" option with value `false` is deprecated since Symfony 4.1. Set it to `true` instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to change those expectations.
8a8d1ec
to
4f08f20
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after the double-dots are removed
public function __construct($options = null) | ||
{ | ||
if (!($options['canonicalize'] ?? false)) { | ||
@trigger_error('The "canonicalize" option with value "false" is deprecated since Symfony 4.1, set it to "true" instead..', E_USER_DEPRECATED); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double-dot :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry. Fixed.
…nicalize" option to `true`
4f08f20
to
1572540
Compare
Thank you @phansys. |
…raint without setting "canonicalize" option to `true` (phansys) This PR was merged into the 4.1-dev branch. Discussion ---------- [Validator] Deprecate use of `Locale` validation constraint without setting "canonicalize" option to `true` |Q |A | |--- |--- | |Branch |master | |Bug fix? |no | |New feature? |no | |BC breaks? |no | |Deprecations?|yes | |Tests pass? |yes | |Fixed tickets|#22353 | |License |MIT | |Doc PR |symfony/symfony-docs#9248| See #22353 (comment). Commits ------- 1572540 Deprecate use of `Locale` validation constraint without setting "canonicalize" option to `true`
…` validation constraint (phansys, javiereguiluz) This PR was merged into the master branch. Discussion ---------- [Validator] Add docs for "canonicalize" option at `Locale` validation constraint Related to symfony/symfony#22353, symfony/symfony#26075. Closes #7660. Commits ------- 14f10bc Final changes 4c28e1f Minor changes 0cc4ee8 Add docs for "canonicalize" option at `Locale` validation constraint
Maybe I'm missing something, but how can setting https://github.com/symfony/symfony/blob/4.0/src/Symfony/Component/Validator/Constraints/Locale.php |
hmm, deprecating a value of the option at the same time it is added looks indeed weird, as it means we cannot write code running both on 4.0 and on 4.1 without deprecation |
Because the deprecation is not about using the option itself, but about passing |
@phansys But the option didn't exist before 4.1, therefore you couldn't even pass |
@emodric but omitting it is equivalent to passing |
Right @emodric, this option will be introduced in 4.1, and the deprecation will be thrown if you omit it or if you pass |
Okay, I understand, but:
How to solve this case that @stof mentions, or should we check for kernel version to avoid the deprecation? |
Except a build matrix executing same build for both versions, I can't imagine which scenario could require avoid the deprecation without changing the codebase triggering it. But I think there is no way to use this validator without deprecation in |
Build matrix discovered this deprecation for me, yes. No worries, I will add a Thanks for your help! |
See #22353 (comment).