2017 © Pedro Peláez
 

library php-siren

A PHP Library for handling Siren JSON hypermedia

image

danbelden/php-siren

A PHP Library for handling Siren JSON hypermedia

  • Saturday, September 9, 2017
  • by DanBelden
  • Repository
  • 0 Watchers
  • 1 Stars
  • 1,567 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 3 Versions
  • 18 % Grown

The README.md

danbelden/php-siren

Build Status Scrutinizer Code Quality Maintainability Latest Stable Version Total Downloads, (*1)

A PHP Library for handling Siren JSON hypermedia documents, (*2)

Overview

This is a library based around the Siren hypermedia data standard: - https://github.com/kevinswiber/siren - https://groups.google.com/forum/#!forum/siren-hypermedia, (*3)

It provides objects and validation for handling this structured data format., (*4)

Requires

PHP 5.3 and above., (*5)

Installation

Composer

To install this package with composer, run the following command:, (*6)

composer require danbelden/php-siren "^1.0", (*7)

Documentation

Using the example target JSON defined in the standards: - https://github.com/kevinswiber/siren, (*8)

$document = new Document();
$document->addClass('order');

$properties = [
    'orderNumber' => 42,
    'itemCount'   => 3,
    'status'      => 'pending'
];
$document->setProperties($properties);

$entityOne = new Entity();
$entityOne->setClass([ 'items', 'collection' ])
    ->setRel([ 'http://x.io/rels/order-items' ])
    ->setHref('http://api.x.io/orders/42/items');

$entityTwoLink = new Link();
$entityTwoLink->setRel([ 'self' ])
    ->setHref('http://api.x.io/customers/pj123');

$entityTwo = new Entity();
$entityTwo->setClass([ 'info', 'customer' ])
    ->setRel([ 'http://x.io/rels/customer' ])
    ->setProperties([
        'customerId' => 'pj123',
        'name' => 'Peter Joseph'
    ])
    ->setLinks([ $entityTwoLink ]);

$entities = [ $entityOne, $entityTwo ];
$document->setEntities($entities);

$actionFieldOne = new Field();
$actionFieldOne->setName('orderNumber')
    ->setType('hidden')
    ->setValue('42');

$actionFieldTwo = new Field();
$actionFieldTwo->setName('productCode')
    ->setType('text');

$actionFieldThree = new Field();
$actionFieldThree->setName('quantity')
    ->setType('number');

$actionOne = new Action();
$actionOne->setName('add-item')
    ->setTitle('Add Item')
    ->setMethod('POST')
    ->setHref('http://api.x.io/orders/42/items')
    ->setType('application/x-www-form-urlencoded')
    ->setFields([ $actionFieldOne, $actionFieldTwo, $actionFieldThree ]);

$actions = [ $actionOne ];
$document->setActions($actions);

$linkOne = new Link();
$linkOne->setRel([ 'self' ])
    ->setHref('http://api.x.io/orders/42');

$linkTwo = new Link();
$linkTwo->setRel([ 'previous' ])
    ->setHref('http://api.x.io/orders/41');

$linkThree = new Link();
$linkThree->setRel([ 'next' ])
    ->setHref('http://api.x.io/orders/43');

$links = [ $linkOne, $linkTwo, $linkThree ];
$document->setLinks($links);

Enjoy., (*9)

The Versions

09/09 2017

dev-master

9999999-dev

A PHP Library for handling Siren JSON hypermedia

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

14/05 2017

v1.0.1

1.0.1.0

A PHP Library for handling Siren JSON hypermedia

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

14/05 2017

v1.0

1.0.0.0

A PHP Library for handling JSON hypermedia formats

  Sources   Download

MIT

The Development Requires