Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vendor/
tests/report/
.phpunit.result.cache
6 changes: 5 additions & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
build:
environment:
php: 7.4.0
php: 8.1
nodes:
coverage:
environment:
php:
ini:
"xdebug.mode": coverage
tests:
override:
- command: php ./script/test_with_coverage.php
Expand Down
53 changes: 52 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ Which will result in:
"message": "That is not valid",
"code": 422,
"file": "README.md",
"line": 107,
"line": 137,
"trace": []
}
}
Expand All @@ -166,6 +166,57 @@ Which will result in:

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

#### Using extensions and profiles

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:

```php
use alsvanzelf\jsonapi\ResourceDocument;
use alsvanzelf\jsonapi\interfaces\ExtensionInterface;

class ExampleExtension implements ExtensionInterface {
public function getOfficialLink() {
return 'https://example.org/extension-documentation';
}

public function getNamespace() {
return 'foo';
}
}

$document = new ResourceDocument('user', 42);
$document->add('name', 'Zaphod Beeblebrox');

$extension = new ExampleExtension();
$document->applyExtension($extension);
$document->addExtensionMember($extension, 'bar', 'baz');

$document->sendResponse();
```

Which will result in:

```json
{
"foo:bar": "baz",
"jsonapi": {
"version": "1.1",
"ext": [
"https://example.org/extension-documentation"
]
},
"data": {
"type": "user",
"id": "42",
"attributes": {
"name": "Zaphod Beeblebrox"
}
}
}
```

A similar flow can be used for profiles.

#### Other examples

Examples for all kind of responses are in the [/examples](/examples) directory.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
}
},
"require-dev": {
"phpunit/phpunit": "^5.7|^6.5|^7.5|^8.5|^9.4",
"phpunit/phpunit": "*",
"psr/http-message": "^1.0"
},
"suggest": {
Expand Down
Loading