Skip to content

Commit c3282df

Browse files
committed
Add 'usage' section in readme file
1 parent 7836293 commit c3282df

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

README.md

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ gl3n_http_query_string_filter:
2323
list:
2424
params:
2525
size: { type: string, reg_exp: '^s|m|l$', default: 's' }
26-
post_list:
26+
blog_post_list:
2727
include: [list]
2828
params:
2929
userId: { type: integer }
@@ -33,7 +33,7 @@ gl3n_http_query_string_filter:
3333
3434
A filter has parameters (``params`` node). It can also include other filters' parameters (``include`` node).
3535
36-
### Parameter configuration
36+
### 2.1. Parameter configuration
3737
3838
Each parameter configuration has 6 options :
3939
@@ -46,29 +46,50 @@ Each parameter configuration has 6 options :
4646
| ``array`` | no | Boolean that indicates wheter expected parameter value is an array *(default is false)* |
4747
| ``roles`` | no | An array of security roles allowed to use this parameter *(default is an empty array)* |
4848
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
5450
55-
## 3. Parameter types
56-
57-
### Definition
51+
##### Definition
5852
5953
A parameter type defines :
6054
6155
1. how the **value** (or the **values** in the case of a parameter configured as an array) will be **casted**,
6256
2. the **default regular expression**.
6357
64-
### Reference
58+
##### Reference
6559
6660
| Type | Cast to | Default reg exp |
6761
|-------------|-------------|------------------|
6862
| **string** | PHP string | ``^.+$`` |
6963
| **boolean** | PHP boolean | ``^true|false$`` |
7064
| **integer** | PHP integer | ``^\d+$`` |
7165
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+
7293
## 4. How to write a custom parameter type
7394

7495
Your parameter type class must implement ``ParameterType\ParameterTypeInterface`` with 2 methods :

0 commit comments

Comments
 (0)