Download the PHP package aaronbullard/dogpile without Composer
On this page you can find all versions of the php package aaronbullard/dogpile. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aaronbullard/dogpile
More information about aaronbullard/dogpile
Files in aaronbullard/dogpile
Package dogpile
Short Description JSON:API helper library to cleanly import included relationships
License MIT
Informations about the package dogpile
Dogpile
JSON:API helper library to cleanly import included relationships
Installation
Library
Composer
Testing
Usage
First, visit https://jsonapi.org for documentation on JSON:API standard. This library attempts to simplify and modularize included related resource objects in api calls.
Ex. GET /posts/1?include=author,comments,comments.author
This library will quickly query and include the related 'author' and 'comments' assosciated with the resource. To do so, requires a few interface implementations.
How it works
The Dogpile\ResourceManager class contains several ResourceQuery objects for each resource type. When an array of included relationships are provided, the Dogpile\QueryBuilder class will use the ResourceIdentifiers from the RelationshipCollection and query the resources via the RepositoryQuery::findHavingIds() method. Each resource will only be queried once.
Setup
First
Dogpile requires a Dogpile\Contracts\ResourceQuery interface implementation for each resource. As in the above example, you would want an implementation for 'people' (to query authors); and one for 'comments'.
Second
Register your ResourceQuery handlers with your Dogpile\ResourceManager
Third
Dogpile\Contracts\ResourceQuery::findHavingIds() must return a Dogpile\Collections\ResourceCollection class containing objects that implement the Dogpile\Contracts\Resource interface.
Fourth
As stated in step above, each Resource object must implement the Resource::realtionships() interface which returns a RelationshipCollection class. The Dogpile\Collections\RelationshipCollection class can be implemented as such below.
For more examples, see the tests: tests\Functional\ResourceManagerTest.php