Download the PHP package freddiegar/json-api-mapper without Composer
On this page you can find all versions of the php package freddiegar/json-api-mapper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download freddiegar/json-api-mapper
More information about freddiegar/json-api-mapper
Files in freddiegar/json-api-mapper
Package json-api-mapper
Short Description Mapper response json-api in PHP
License MIT
Informations about the package json-api-mapper
JSON Api Mapper
It is a mapper in PHP from response jsonapi.org.
This library create a object from response json-api. Access to elements in response easily
Status Branch
Requisites
- php >= 7.1.3
Install
Usage
Creating instance of Mapper, see $jsonApiResponse here
By example, get data resource
By example, get included
By example, get errors, see $jsonApiResponse here
Find
Get data with id
= 2
Get included by type
= people
Get included with type
= people and id
= 3
Alias in JsonApiResponse class
You can use any option to access to data in that response
Method* | Alias | Property | Description |
---|---|---|---|
getData() | data() | data | Return object DataMapper if exists in response, else null |
getErrors() | errors() | errors | Return object ErrorsMapper if exists in response, else null |
getMeta() | meta() | meta | Return object MetaMapper if exists in response, else null |
getJsonApi() | jsonapi() | jsonapi | Return object JsonApiMapper if exists in response, else null |
getIncluded() | included() | included | Return object IncludedMapper if exists in response, else null |
getLinks() | links() | links | Return object LinksMapper if exists in response, else null |
Performance
You will prefer to use get* (getData(), getErrors()) methods accessors, they are direct call, any other ways are overloading (__call
and __get
), this are slower
Response Used In Example
You can see all example here