! WIP Status
Link to the Collection+Json Specification : https://github.com/collection-json/spec
Add the library to your composer.json file
{
"require": {
// your other deps,
"kwattro/hypermedia-collection-json": "0.1@dev"
}
}
Usage of the library is simple :
require_once 'vendor/autoload.php';
use Kwattro\Hypermedia\CollectionJson\Collection;
$collection = new Collection();
$collection->addHref('http://example.com/api/movies');
use Kwattro\Hypermedia\CollectionJson\Collection;
use Kwattro\Hypermedia\CollectionJson\Item;
$collection = new Collection();
$item = new Item();
$item->addData(array('name' => 'John', 'city' => 'Paradise City');
$item->addHref('http://example.com/user/1234/john');
$collection->addItem($item);
In order to serialize/deserialize objects, you just need to call the Serializer create static method :
use Kwattro\Hypermedia\CollectionJson\Serializer;
// $myCollection = ... creating collection and items objects
$json = Serializer::create()->serialize($myCollection); // Returns a Json representation
// Deserializing :
$myObject = Serializer::create()->deserialize($json); // Returns a Collection object
The lib is using phpspec
bin/phpspec run
- Implementing JMS/Serializer (partially done)
- Full compliant with Hypermedia Spec