Skip to content

Commit bae3f70

Browse files
authored
Merge pull request #73 from lode/2.4.0
2 parents 6afd836 + fed5015 commit bae3f70

16 files changed

Lines changed: 987 additions & 641 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
vendor/
22
tests/report/
3+
.phpunit.result.cache

.scrutinizer.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
build:
22
environment:
3-
php: 7.4.0
3+
php: 8.1
44
nodes:
55
coverage:
6+
environment:
7+
php:
8+
ini:
9+
"xdebug.mode": coverage
610
tests:
711
override:
812
- command: php ./script/test_with_coverage.php

README.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Which will result in:
156156
"message": "That is not valid",
157157
"code": 422,
158158
"file": "README.md",
159-
"line": 107,
159+
"line": 137,
160160
"trace": []
161161
}
162162
}
@@ -166,6 +166,57 @@ Which will result in:
166166

167167
This can be useful for development. For production usage, you can better construct an `ErrorsDocument` with only specific values.
168168

169+
#### Using extensions and profiles
170+
171+
The [Atomic Operations extension](https://jsonapi.org/ext/atomic/) and the [Cursor Pagination profile](https://jsonapi.org/profiles/ethanresnick/cursor-pagination/) come packaged along. Any 3rd party of self-made extension can be applied with:
172+
173+
```php
174+
use alsvanzelf\jsonapi\ResourceDocument;
175+
use alsvanzelf\jsonapi\interfaces\ExtensionInterface;
176+
177+
class ExampleExtension implements ExtensionInterface {
178+
public function getOfficialLink() {
179+
return 'https://example.org/extension-documentation';
180+
}
181+
182+
public function getNamespace() {
183+
return 'foo';
184+
}
185+
}
186+
187+
$document = new ResourceDocument('user', 42);
188+
$document->add('name', 'Zaphod Beeblebrox');
189+
190+
$extension = new ExampleExtension();
191+
$document->applyExtension($extension);
192+
$document->addExtensionMember($extension, 'bar', 'baz');
193+
194+
$document->sendResponse();
195+
```
196+
197+
Which will result in:
198+
199+
```json
200+
{
201+
"foo:bar": "baz",
202+
"jsonapi": {
203+
"version": "1.1",
204+
"ext": [
205+
"https://example.org/extension-documentation"
206+
]
207+
},
208+
"data": {
209+
"type": "user",
210+
"id": "42",
211+
"attributes": {
212+
"name": "Zaphod Beeblebrox"
213+
}
214+
}
215+
}
216+
```
217+
218+
A similar flow can be used for profiles.
219+
169220
#### Other examples
170221

171222
Examples for all kind of responses are in the [/examples](/examples) directory.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
}
2424
},
2525
"require-dev": {
26-
"phpunit/phpunit": "^5.7|^6.5|^7.5|^8.5|^9.4",
26+
"phpunit/phpunit": "*",
2727
"psr/http-message": "^1.0"
2828
},
2929
"suggest": {

0 commit comments

Comments
 (0)