|
1 | 1 | # Upgrade from library v2 to v3 |
2 | 2 |
|
3 | | -## Checking links, ... |
| 3 | +## Enums |
4 | 4 |
|
5 | | -Objects more often use uninitialized properties. `has*()` helper methods have been added to support the new flow. |
| 5 | +All constants have been replaced by enums. |
6 | 6 |
|
7 | | -- `$object->links` to `if ($object->hasLinks()) $object->links` |
| 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` |
8 | 11 |
|
9 | | -## Interfaces |
| 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) |
10 | 16 |
|
11 | | -When extending interfaces, you'll have to add method argument types and return types. |
| 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` |
12 | 21 |
|
13 | | -Check [all interfaces](/src/interfaces) for the correct typing. |
| 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` |
14 | 25 |
|
15 | | -## Enums |
| 26 | +Relationship types: |
| 27 | +- `RelationshipObject::TO_ONE` (`'one'`) to `RelationshipTypeEnum::ToOne` |
| 28 | +- `RelationshipObject::TO_MANY` (`'many'`) to `RelationshipTypeEnum::ToMany` |
16 | 29 |
|
17 | | -Content types: |
18 | | -- `Document::CONTENT_TYPE_OFFICIAL` to `ContentTypeEnum::Official` |
19 | | -- `Document::CONTENT_TYPE_DEBUG` to `ContentTypeEnum::Debug` |
20 | | -- `Document::CONTENT_TYPE_JSONP` to `ContentTypeEnum::Jsonp` |
| 30 | +Validator object containers (only used internally): |
| 31 | +- `Validator::OBJECT_CONTAINER_*` to `ObjectContainerEnum::*` |
21 | 32 |
|
22 | | -Jsonapi versions: |
23 | | -- `Document::JSONAPI_VERSION_1_0` to `JsonapiVersionEnum::V_1_0` |
24 | | -- `Document::JSONAPI_VERSION_1_1` to `JsonapiVersionEnum::V_1_1` |
25 | | -- `Document::JSONAPI_VERSION_LATEST` to `JsonapiVersionEnum::Latest` |
26 | 33 |
|
27 | | -Document levels: |
28 | | -- `Document::LEVEL_ROOT` to `DocumentLevelEnum::Root` |
29 | | -- `Document::LEVEL_JSONAPI` to `DocumentLevelEnum::Jsonapi` |
30 | | -- `Document::LEVEL_Resource` to `DocumentLevelEnum::Resource` |
| 34 | +## Strict type checking |
31 | 35 |
|
32 | | -Sorting orders: |
33 | | -- `RequestParser->getSortFields()` returns a `SortOrderEnum` instead of `string` for the `order` field |
| 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. |
34 | 37 |
|
35 | | -Relationship types: |
36 | | -- `RelationshipObject::TO_ONE` to `RelationshipTypeEnum::ToOne` |
37 | | -- `RelationshipObject::TO_MANY` to `RelationshipTypeEnum::ToMany` |
| 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. |
38 | 39 |
|
39 | | -## Internal |
| 40 | +Some invalid types were already checked at run-time and threw library exceptions. This now changed into php type errors. |
40 | 41 |
|
41 | | -Enums: |
42 | | -- `RequestParser::SORT_*` to `SortOrderEnum::*` |
43 | | -- `Validator::OBJECT_CONTAINER_*` to `ObjectContainerEnum::*` |
| 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 |
0 commit comments