You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A filter has parameters (``params`` node). It can also include other filters' parameters (``include`` node).
35
35
36
-
### Parameter configuration
36
+
### 2.1. Parameter configuration
37
37
38
38
Each parameter configuration has 6 options :
39
39
@@ -46,29 +46,50 @@ Each parameter configuration has 6 options :
46
46
| ``array`` | no | Boolean that indicates wheter expected parameter value is an array *(default is false)* |
47
47
| ``roles`` | no | An array of security roles allowed to use this parameter *(default is an empty array)* |
48
48
49
-
#### Default value in the case of array parameters
50
-
51
-
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.
52
-
53
-
You can see an example of this case in the sample configuration above.
49
+
#### Parameter types
54
50
55
-
## 3. Parameter types
56
-
57
-
### Definition
51
+
##### Definition
58
52
59
53
A parameter type defines :
60
54
61
55
1. how the **value** (or the **values** in the case of a parameter configured as an array) will be **casted**,
62
56
2. the **default regular expression**.
63
57
64
-
### Reference
58
+
##### Reference
65
59
66
60
| Type | Cast to | Default reg exp |
67
61
|-------------|-------------|------------------|
68
62
| **string** | PHP string | ``^.+$`` |
69
63
| **boolean** | PHP boolean | ``^true|false$`` |
70
64
| **integer** | PHP integer | ``^\d+$`` |
71
65
66
+
#### Default value in the case of array parameters
67
+
68
+
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.
69
+
70
+
You can see an example of this case in the sample configuration above.
71
+
72
+
## 3. Usage
73
+
74
+
Add a query string filter on an action thanks to the **annotation** :
75
+
76
+
```php
77
+
use Gl3n\HttpQueryStringFilterBundle\Annotation\HttpQueryStringFilter;
78
+
// ...
79
+
80
+
class BlogPostController
81
+
{
82
+
/**
83
+
* @HttpQueryStringFilter(name="blog_post_list")
84
+
*/
85
+
public function listAction(Request $request)
86
+
{
87
+
// Now your request query is filtered
88
+
$parameters = $request->query->all();
89
+
}
90
+
}
91
+
```
92
+
72
93
## 4. How to write a custom parameter type
73
94
74
95
Your parameter type class must implement ``ParameterType\ParameterTypeInterface`` with 2 methods :
0 commit comments