|
| 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 |
0 commit comments