Skip to content

[HttpFoundation] Added ParameterBag::getBoolean #11086

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

Merged
merged 1 commit into from
Jun 16, 2014

Conversation

peterjmit
Copy link
Contributor

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

// 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:

// 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

*
* @return int The filtered value
*
* @api
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be removed

Added the getBoolean method as a convenience on top of the pre-existing
ParameterBag::filter method
@fabpot
Copy link
Member

fabpot commented Jun 16, 2014

👍

1 similar comment
@stof
Copy link
Member

stof commented Jun 16, 2014

👍

@fabpot
Copy link
Member

fabpot commented Jun 16, 2014

Thank you @peterjmit.

@fabpot fabpot merged commit 36c58f8 into symfony:master Jun 16, 2014
fabpot added a commit that referenced this pull request Jun 16, 2014
…jmit)

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
-------

36c58f8 [HttpFoundation] Added ParameterBag::getBoolean
@peterjmit peterjmit deleted the parameter-bag-get-boolean branch June 16, 2014 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants