Download the PHP package focus/json-api without Composer
On this page you can find all versions of the php package focus/json-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download focus/json-api
More information about focus/json-api
Files in focus/json-api
Package json-api
Short Description A collection of tools for working with JSON:API data.
License MIT
Informations about the package json-api
Focus JSON:API
A collection of tools for working with JSON:API data. This package is an extension of focus/data.
Installation
The best way to install and use this package is with composer:
Basic Usage
This package provides some structure to reading JSON:API formatted data. Both resource and resource collections are supported.
The typical entry point will be DocumentData
:
Note: Like JsonData
, this package supports reading JSON from
strings and PSR-7 request and response objects.
Once the document is created, the primary data can be accessed as a resource:
Or a collection of resources:
Or the included resources:
Types
Identifiers
The Identifier
object extends Data
and adds helper methods to read
the type and identifier value:
Resources
The Resource
object extends from Identifier
and adds helper methods to read
attributes and relationships:
- The value of
relation()
is an identifier of a to-one relationship. When the relationship is undefined,null
will be returned. When the relationship is defined asnull
, a blankIdentifier
will be returned. - The value of
relations()
is an identifier collection of a to-many relationship. When the relationship is undefined,null
will be returned. When the relationship is defined asnull
, an emptyIdentifierCollection
will be returned.
The return values of relation()
and relations()
are structured this way to allow
determining when a relationship is not present (undefined) versus being unset (null).
Identifier Collections
The IdentifierCollection
object represents a collection of Identifier
objects
and adds helper methods to read the identifier values:
The collection can also be iterated:
Resource Collections
The ResourceCollection
object represents a collection of Resource
objects
and adds helper methods to read the identifier values:
The collection can also be iterated: