-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[HttpFoundation] Add ParameterBag::getString() and deprecate accepting invalid values
#48525
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
ParameterBag::getString and replace getInt with getIntegerParameterBag::getString and replace getInt with getInteger
src/Symfony/Component/HttpFoundation/Tests/ParameterBagTest.php
Outdated
Show resolved
Hide resolved
b65b7fc to
ce6910d
Compare
0446360 to
231f96c
Compare
ParameterBag::getString and replace getInt with getIntegerParameterBag::getString and add 3rd argument to make getInt more strict
880f74d to
9717f40
Compare
522a590 to
b5c7ee3
Compare
910e200 to
166e0ad
Compare
I'll take care of this process 😃. But I am also tempted to change the behavior directly in 6.3. The modification to keep the current behavior is to replace |
166e0ad to
8862249
Compare
c5b893e to
bb1bf04
Compare
ccea2a3 to
70261b3
Compare
This is a brilliant idea, let me explain it for the readers. |
ParameterBag::getString and add 3rd argument to make getInt more strictParameterBag::getString() and deprecate accepting invalid values
ce97141 to
2fff7e5
Compare
…ing invalid values
2fff7e5 to
172f0a7
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.
(I improved the deprecation message)
|
Thank you @GromNaN. |
… behaviors (GromNaN) This PR was squashed before being merged into the 7.0 branch. Discussion ---------- [HttpFoundation] Remove deprecated classes, method and behaviors | Q | A | ------------- | --- | Branch? | 7.0 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | n/a Clean `symfony/http-foundation` from all its legacy. - Remove `RequestMatcher` and `ExpressionRequestMatcher`, deprecated since #47595 - Remove `Request::getContentType()`, deprecated since #45034 - Throw a `UnexpectedValueException` or `BadRequestException` when `ParameterBag::filter()` or `InputBag::filter()` reads an invalid value and the flag `FILTER_NULL_ON_FAILURE` is not set. new behavior announced since #48525 - Throw a `InvalidArgumentException` when calling `Request::create()` with a malformed URI, deprecated since #49376 Commits ------- 665a775 [HttpFoundation] Remove deprecated classes, method and behaviors
There were a lot of discussions on #44787 regarding the implementation. The main debate is to determine the right behavior when the value is invalid: try to convert the value, throw an exception, return the default value or the falsy?
I added plenty of test cases for the methods
getAlpha,getAlnum,getDigits,getInt,,getIntegergetStringso that we can discuss the expected result for each input value.My goals:
string, thegetStringmethod is useful to be sure we don't get an array.How are these getter methods used?
string(from routing, query string, request payload).getis used but does not validate the return type.getIntis used for pagination (UX Autocomplete) or getting an index (EasyAdmin)getAlpha,getAlnumandgetDigitscould return an array, but their return type have been modified tostring, resulting in aTypeError. example of use