Skip to content

Commit c70e59f

Browse files
committed
Merge branch 'v3'
2 parents 8373012 + d0d1baf commit c70e59f

157 files changed

Lines changed: 3803 additions & 6256 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/lint.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: lint
22
on:
33
pull_request:
4+
types: [opened, synchronize, reopened, ready_for_review]
45
paths:
56
- "**.php"
67

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: test
22
on:
33
pull_request:
4+
types: [opened, synchronize, reopened, ready_for_review]
45
paths:
56
- "**.php"
67

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ while being easy to understand for people without knowledge of the jsonapi stand
88
The JSON:API standard makes it easy for clients to fetch multiple resources in one call and understand the relations between them.
99
Read more about it at [jsonapi.org](https://jsonapi.org/).
1010

11+
The library's code uses strict typing and is checked against a high standard in phpstan and rector. It is tested extensively with 99% coverage.
12+
1113

1214
## Installation
1315

@@ -17,11 +19,11 @@ Read more about it at [jsonapi.org](https://jsonapi.org/).
1719
composer require alsvanzelf/jsonapi
1820
```
1921

20-
The library supports, and is is tested on, php versions 5.6, 7 and 8.
22+
The library requires php 8.2. Use the latest [v2.x release](/releases/tag/v2.5.0) for lower php versions.
2123

22-
#### Upgrading from v1
24+
#### Upgrading from v1 or v2
2325

24-
If you used v1 of this library, see [UPGRADE_1_TO_2.md](/UPGRADE_1_TO_2.md) on how to upgrade.
26+
If you used v1 or v2 of this library, see [UPGRADE_1_TO_2.md](/UPGRADE_1_TO_2.md) or [UPGRADE_2_TO_3.md](/UPGRADE_1_TO_2.md) on how to upgrade.
2527

2628

2729

@@ -32,7 +34,7 @@ If you used v1 of this library, see [UPGRADE_1_TO_2.md](/UPGRADE_1_TO_2.md) on h
3234
```php
3335
use alsvanzelf\jsonapi\ResourceDocument;
3436

35-
$document = new ResourceDocument($type='user', $id=42);
37+
$document = new ResourceDocument(type: 'user', id: 42);
3638
$document->add('name', 'Zaphod Beeblebrox');
3739
$document->add('heads', 2);
3840
$document->sendResponse();
@@ -175,11 +177,11 @@ use alsvanzelf\jsonapi\ResourceDocument;
175177
use alsvanzelf\jsonapi\interfaces\ExtensionInterface;
176178

177179
class ExampleExtension implements ExtensionInterface {
178-
public function getOfficialLink() {
180+
public function getOfficialLink(): string {
179181
return 'https://example.org/extension-documentation';
180182
}
181183

182-
public function getNamespace() {
184+
public function getNamespace(): string {
183185
return 'foo';
184186
}
185187
}

UPGRADE_2_TO_3.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Upgrade from library v2 to v3
2+
3+
## Enums
4+
5+
All constants have been replaced by enums.
6+
7+
Content types:
8+
- `Document::CONTENT_TYPE_OFFICIAL` (`'application/vnd.api+json'`) to `ContentTypeEnum::Official`
9+
- `Document::CONTENT_TYPE_DEBUG` (`'application/json'`) to `ContentTypeEnum::Debug`
10+
- `Document::CONTENT_TYPE_JSONP` (`'application/javascript'`) to `ContentTypeEnum::Jsonp`
11+
12+
Jsonapi versions:
13+
- `Document::JSONAPI_VERSION_1_0` (`'1.0'`) to `JsonapiVersionEnum::V_1_0`
14+
- `Document::JSONAPI_VERSION_1_1` (`'1.1'`) to `JsonapiVersionEnum::V_1_1`
15+
- `Document::JSONAPI_VERSION_LATEST` (`'1.1'`) to `JsonapiVersionEnum::latest()` (still refering to v1.1)
16+
17+
Document levels:
18+
- `Document::LEVEL_ROOT` (`'root'`) to `DocumentLevelEnum::Root`
19+
- `Document::LEVEL_JSONAPI` (`'jsonapi'`) to `DocumentLevelEnum::Jsonapi`
20+
- `Document::LEVEL_Resource` (`'resource'`) to `DocumentLevelEnum::Resource`
21+
22+
Sorting orders (as return value in the `order` field from `RequestParser->getSortFields()`):
23+
- `RequestParser::SORT_ASCENDING` (`'ascending'`) to `SortOrderEnum::Ascending`
24+
- `RequestParser::SORT_DESCENDING` (`'descending'`) to `SortOrderEnum::Descending`
25+
26+
Relationship types:
27+
- `RelationshipObject::TO_ONE` (`'one'`) to `RelationshipTypeEnum::ToOne`
28+
- `RelationshipObject::TO_MANY` (`'many'`) to `RelationshipTypeEnum::ToMany`
29+
30+
Validator object containers (only used internally):
31+
- `Validator::OBJECT_CONTAINER_*` to `ObjectContainerEnum::*`
32+
33+
34+
## Strict type checking
35+
36+
When using the library you shouldn't notice this unless passing values of the wrong type. When extending the library you probably will notice this when overriding methods.
37+
38+
In both cases the upgrade is relatively easy, you can just follow php's type errors. Using phpstan will also help you find typing mismatches.
39+
40+
Some invalid types were already checked at run-time and threw library exceptions. This now changed into php type errors.
41+
42+
43+
## Object properties are uninitialized by default
44+
45+
Objects more often use uninitialized properties. In some cases, `has*()` helper methods have been added to support the new flow. Otherwise, an `isset()` can be used if needed.
46+
47+
_This should only affect you when you extend the libraries classes. Otherwise you can just use the library methods to handle these properties._
48+
49+
- `->links`, on `Document`, `ErrorObject`, `RelationshipObject`, `ResourceObject`, can be checked with `->hasLinks()`
50+
- `Document`: `->httpStatusCode`, `->jsonapi`, `->meta`
51+
- `ErrorObject`: `->id`, `->code`, `->title`, `->detail`, `->meta`, `->httpStatusCode`
52+
- `JsonapiObject`: `->meta`, `->version`
53+
- `LinkObject`: `->href`, `->rel`, `->describedby`, `->title`, `->type`, `->meta`
54+
- `RelationshipObject`: `->meta`, `->resource`, `->type`
55+
- `ResourceDocument`: `->resource`
56+
- `ResourceIdentifierObject`: `->type`, `->id`, `->lid`, `->meta`, `->validator`
57+
- `ResourceObject`: `->attributes`, `->relationships`
58+
59+
60+
## Json encoding and decoding errors
61+
62+
The default encoding options changed to also include `JSON_THROW_ON_ERROR`. Failure to encode already used to throw an exception, but now it will default to a `\JsonException`.
63+
64+
65+
## Removed deprecations
66+
67+
- Old v1-style classes (`base.php`, `collection.php`, `error.php`, `errors.php`, `exception.php`, `resource.php`, `response.php`)
68+
- Array-style links (`->appendLink()`, `->addLinksArray()`, `->appendLinkObject()`, `ErrorObject->appendTypeLink()`, `LinksArray`, `LinksObject->append()`)
69+
- `CursorPaginationProfile->getKeyword()`
70+
- `Converter::mergeProfilesInContentType()`, use `Converter::prepareContentType()` instead

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
}
1414
],
1515
"require": {
16-
"php": ">=5.6",
16+
"php": ">=8.2",
1717
"ext-json": "*"
1818
},
1919
"autoload": {

0 commit comments

Comments
 (0)