Download the PHP package gl3n/http-query-string-filter-bundle without Composer
On this page you can find all versions of the php package gl3n/http-query-string-filter-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gl3n/http-query-string-filter-bundle
More information about gl3n/http-query-string-filter-bundle
Files in gl3n/http-query-string-filter-bundle
Package http-query-string-filter-bundle
Short Description Easy validation, casting and authorization of HTTP query string parameters
License
Informations about the package http-query-string-filter-bundle
HttpQueryStringFilterBundle
Easy validation, casting and authorization of HTTP query string parameters.
1. Installation
Install the bundle through composer, then add it to your AppKernel.php
file :
2. Configuration
Here is a sample filters configuration :
A filter has parameters (params
node). It can also include other filters' parameters (include
node).
2.1. Parameter configuration
Each parameter configuration has 6 options :
Name | Required | Description |
---|---|---|
type | yes | string , boolean or integer (see below for detail) |
||
reg_exp |
no | The regular expression to use for validation (default depends on the parameter type) |
default |
no | Default value (will be casted depending on the parameter type) |
required |
no | Boolean that indicates whether the parameter is required (default is false) |
array |
no | Boolean that indicates wheter expected parameter value is an array (default is false) |
roles |
no | An array of security roles allowed to use this parameter (default is an empty array) |
Parameter types
Definition
A parameter type defines :
- how the value (or the values in the case of a parameter configured as an array) will be casted,
- the default regular expression.
Reference
Type | Cast to | Default reg exp |
---|---|---|
string | PHP string | ^.+$ |
boolean | PHP boolean | ^true|false$ |
integer | PHP integer | ^\d+$ |
Default value in the case of array parameters
In this special case, default value is evaluated through Symfony Expression Language component. Then if the result in an array : each value is casted depending on the configured parameter type.
You can see an example of this case in the sample configuration above.
3. Usage
Add a query string filter on an action thanks to the annotation :
4. How to write a custom parameter type
Your parameter type class must implement ParameterType\ParameterTypeInterface
with 2 methods :
castValue($value)
getDefaultRegExp()
Then declare it as a service, and add the tag gl3n_http_query_string_filter.parameter_type
with the property type
.
Here is an example of XML declaration :