2017 © Pedro Peláez
 

library siren

A library for creating and parsing Siren APIs in PHP

image

tomphp/siren

A library for creating and parsing Siren APIs in PHP

  • Thursday, January 12, 2017
  • by tomphp
  • Repository
  • 1 Watchers
  • 2 Stars
  • 68 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Siren

A serialiser and parser for Siren APIs., (*1)

Siren

Siren is a schema for HATEOAS APIs which uses JSON., (*2)

Current State

This project's releases strongly adhere to SemVer. At this point in time, this project is in zero point state. While it's functionality is sound and working, large backwards compatibility breaks can be expected in new releases., (*3)

Installing

composer require tomphp/siren:dev-master

Serialising

Creating an entity is done using the builder; this is created by calling TomPHP\Siren\Entity::builder()., (*4)

use TomPHP\Siren\{Entity, Action};

$editAction = Action::builder()
    ->setName('edit')
    ->setTitle('Edit User')
    ->setHref('http://example.com/api/v1/users/ea019642-9c53-415f-88b6-e191dea184f9')
    ->setMethod('PUT')
    ->setType('application/vnd.siren+json')
    ->addField('email', ['email-class'], 'email', 'test@example.com', 'Email Address')
    ->build();

$user = Entity::builder()
    ->addLink('self', 'http://example.com/api/v1/users/ea019642-9c53-415f-88b6-e191dea184f9')
    ->addProperty('full_name', 'Tom Oram')
    ->addProperty('email', 'tom@example.com')
    ->addClass('item')
    ->addAction($editAction)
    ->build();

print(json_encode($user->toArray());

Parsing

An entity can be created from a JSON decoded array by using fromArray() constructor., (*5)

// Assuming the JSON from the serialising example.

$user = Entity::fromArray(json_decode($json, true));

echo 'Name: ' . $user->getProperty('full_name') . PHP_EOL;
echo 'Email: ' . $user->getProperty('email') . PHP_EOL;

$editAction = $user->getAction('edit');
echo 'Edit Action ' . $editAction->getMehod() . ' ' . $editAction->getHref() . PHP_EOL;

Contributing

I want to get this project stable as soon as possible, so any help I can get is greatly appreciated. If you think you can help, please submit a Pull Request., (*6)

The Versions

12/01 2017

dev-master

9999999-dev

A library for creating and parsing Siren APIs in PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

05/12 2016

v0.1.0

0.1.0.0

A library for creating and parsing Siren APIs in PHP

  Sources   Download

MIT

The Requires

 

The Development Requires