dev-master
9999999-devHypermedia Collection+Json Library for PHP
MIT
The Requires
- php >=5.3.2
- doctrine/collections 1.*
- jms/serializer 0.17.*@dev
The Development Requires
api json rest collection hypermedia
Wallogit.com
2017 © Pedro Peláez
Hypermedia Collection+Json Library for PHP
! WIP Status, (*1)
Link to the Collection+Json Specification : https://github.com/collection-json/spec, (*2)
Add the library to your composer.json file, (*3)
{
"require": {
// your other deps,
"kwattro/hypermedia-collection-json": "0.1@dev"
}
}
Usage of the library is simple :, (*4)
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 :, (*5)
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, (*6)
bin/phpspec run
Hypermedia Collection+Json Library for PHP
MIT
api json rest collection hypermedia