1eed20a3f6
This PR was merged into the 2.3-dev branch.
Discussion
----------
[HttpFoundation] Added ParameterBag::getBoolean
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | n/a
| License | MIT
| Doc PR | n/a
At the moment to pull a boolean value from a request the user has to use `ParameterBag::filter` or use `filter_var` directly
```php
// GET /products?hide_archived=true
$request->query->filter('hide_archived', false, false, FILTER_VALIDATE_BOOLEAN);
// or
filter_var($request->query->get('hide_archived'), FILTER_VALIDATE_BOOLEAN);
```
This is a pure convenience addition, adding a nice way of pulling a boolean value from a query string or request body (especially if http form/url encoded).
Example usage:
```php
// GET /products?hide_archived=true
$request->query->getBoolean('hide_archived'); // (boolean) true
$request->query->get('hide_archived'); // (string) "true"
// GET /products?hide_archived=1
$request->query->getBoolean('hide_archived'); // (boolean) true
// GET /products?hide_archived=false
$request->query->getBoolean('hide_archived'); // (boolean) false
// GET /products?hide_archived=banana
$request->query->getBoolean('hide_archived'); // (boolean) false
```
Commits
-------
|
||
---|---|---|
.. | ||
File | ||
Session | ||
AcceptHeaderItemTest.php | ||
AcceptHeaderTest.php | ||
ApacheRequestTest.php | ||
BinaryFileResponseTest.php | ||
CookieTest.php | ||
ExpressionRequestMatcherTest.php | ||
FileBagTest.php | ||
HeaderBagTest.php | ||
IpUtilsTest.php | ||
JsonResponseTest.php | ||
ParameterBagTest.php | ||
RedirectResponseTest.php | ||
RequestMatcherTest.php | ||
RequestStackTest.php | ||
RequestTest.php | ||
ResponseHeaderBagTest.php | ||
ResponseTest.php | ||
ResponseTestCase.php | ||
ServerBagTest.php | ||
StreamedResponseTest.php |