Skip to content

Commit 3be9cea

Browse files
committed
Document matrix parameters
1 parent adc9c45 commit 3be9cea

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,29 @@ 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+
Matrix parameters
84+
-----------------
85+
86+
This library supports parameters inside path segments, e.g. `https://example.com/api/trainings/status=COMPLETED;orgunits=A,B/authors`:
87+
88+
```php
89+
use web\rest\{Resource, Get, Matrix};
90+
91+
#[Resource('/api/trainings')]
92+
class Trainings {
93+
94+
#[Get('/{filter}/authors')]
95+
public function authors(#[Matrix] array $filter) {
96+
$authors= [];
97+
foreach ($this->repository->find($filter) as $training) {
98+
$authors[$training->author->id()]= $training->author;
99+
}
100+
return $authors;
101+
}
102+
}
103+
```
104+
105+
The resulting value inside *$filter* will be `["status" => "COMPLETED", "orgunits" => ["A", "B"]]`.
83106

84107
Return types
85108
------------

0 commit comments

Comments
 (0)