2017 © Pedro Peláez
 

library hypermedia-collection-json

Hypermedia Collection+Json Library for PHP

image

kwattro/hypermedia-collection-json

Hypermedia Collection+Json Library for PHP

  • Wednesday, August 27, 2014
  • by ikwattro
  • Repository
  • 0 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

PHP Library for handling Hypermedia Collection+Json Format

! WIP Status, (*1)

Link to the Collection+Json Specification : https://github.com/collection-json/spec, (*2)

Installation

Add the library to your composer.json file, (*3)

{
    "require": {
        // your other deps,
        "kwattro/hypermedia-collection-json": "0.1@dev"
    }
}

Usage

Usage of the library is simple :, (*4)

Create a new Collection :

require_once 'vendor/autoload.php';

use Kwattro\Hypermedia\CollectionJson\Collection;

$collection = new Collection();
$collection->addHref('http://example.com/api/movies');

Add items to the collection

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);

(De-)Serializing

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

Tests

The lib is using phpspec, (*6)

Running the test suite

bin/phpspec run

TO-DO

  • Implementing JMS/Serializer (partially done)
  • Full compliant with Hypermedia Spec

The Versions

27/08 2014

dev-master

9999999-dev

Hypermedia Collection+Json Library for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

api json rest collection hypermedia