Skip to content

Commit a36627a

Browse files
committed
Document parameter conversions [skip ci]
1 parent 3263a57 commit a36627a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,26 @@ To supply the source explicitely, you can use parameter attributes:
8080
* `#[Stream]` will pass an `io.streams.InputStream` instance to stream the request body to the parameter
8181
* `#[Request]` will pass the complete `web.Request` object
8282

83+
Parameter conversions
84+
---------------------
85+
86+
Parameters can be converted from their input. This library comes with a built-in conversion named *SeparatedBy*:
87+
88+
```php
89+
use web\rest\{Resource, Get, Param, SeparatedBy};
90+
91+
#[Resource('/api/trainings')]
92+
class Trainings {
93+
94+
#[Get('/completed')]
95+
public function completed(#[Param, SeparatedBy(',')] array $orgunits) {
96+
return $this->repository->find(['status' => 'COMPLETED', 'orgunits' => $orgunits]);
97+
}
98+
}
99+
```
100+
101+
The *orgunits* parameter can now be supplied in the URL as follows: `https://example.com/api/trainings/completed?orgunits=A,B` and the resulting value inside *$orgunits* will be `["A", "B"]`. User-defined conversions can be supplied by implementing the `web.rest.Conversion` interface.
102+
83103
Matrix parameters
84104
-----------------
85105

0 commit comments

Comments
 (0)