2017 © Pedro Peláez
 

library hal

A PHP implementation of HAL http://stateless.co/hal_specification.html

image

zircote/hal

A PHP implementation of HAL http://stateless.co/hal_specification.html

  • Tuesday, November 27, 2012
  • by hjr3
  • Repository
  • 4 Watchers
  • 96 Stars
  • 137,058 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 5 Forks
  • 3 Open issues
  • 8 Versions
  • 5 % Grown

The README.md

Hal

Build Status, (*1)

<?php
use Hal\Resource,
    Hal\Link;
/* Create a new Resource Parent */
$parent = new Resource('/dogs');
/* Add any relevent links */
$parent->setLink(new Link('/dogs?q={text}', 'search'));
$dogs[1] =  new Resource('/dogs/1');
$dogs[1]->setData(
    array(
        'id' => '1', 
        'name' => 'tiber', 
        'color' => 'black'
    )
);
$dogs[2] =  new Resource(
    '/dogs/2',array(
        'id' => '2', 
        'name' => 'sally', 
        'color' => 'white'
    )
);
$dogs[3] =  new Resource(
    '/dogs/3',array(
        'id' => '3', 
        'name' => 'fido', 
        'color' => 'gray'
    )
);
/* Add the embedded resources */
foreach ($dogs as $dog) {
    $parent->setEmbedded('dog', $dog);
}
echo (string) $parent;

Result:

{
  "_links":{
        "self":{
            "href":"\/dogs"
        },
        "search":{
            "href":"\/dogs?q={text}"
        }
    },
    "_embedded":{
        "dog":[
            {
                "_links":{
                    "self":{
                        "href":"\/dogs\/1"
                    }
                },
                "id":"1",
                "name":"tiber",
                "color":"black"
            },
            {
                "_links":{
                    "self":{
                        "href":"\/dogs\/2"
                    }
                },
                "id":"2",
                "name":"sally",
                "color":"white"
            },
            {
                "_links":{
                    "self":{
                        "href":"\/dogs\/3"
                    }
                },
                "id":"3",
                "name":"fido",
                "color":"gray"
            }
        ]
    }
}

Generating XML output

<?php
echo $parent->getXML()->asXML();

Result:

<?xml version="1.0"?>
<resource href="/dogs">
    <link href="/dogs?q={text}" rel="search" />
    <resource href="/dogs/1" rel="dog">
        <id>1</id>
        <name>tiber</name>
        <color>black</color>
    </resource>
    <resource href="/dogs/2" rel="dog">
        <id>2</id>
        <name>sally</name>
        <color>white</color>
    </resource>
    <resource href="/dogs/3" rel="dog">
        <id>3</id>
        <name>fido</name>
        <color>gray</color>
    </resource>
</resource>

Bitdeli Badge, (*2)

The Versions

27/11 2012

dev-master

9999999-dev https://github.com/zircote/Hal/

A PHP implementation of HAL http://stateless.co/hal_specification.html

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.3

 

The Development Requires

api json hal hateoas

27/11 2012

0.3.0

0.3.0.0 https://github.com/zircote/Hal/

A PHP implementation of HAL http://stateless.co/hal_specification.html

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.3

 

The Development Requires

api json hal hateoas

27/11 2012

0.3.1

0.3.1.0 https://github.com/zircote/Hal/

A PHP implementation of HAL http://stateless.co/hal_specification.html

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.3

 

The Development Requires

api json hal hateoas

27/11 2012

0.3.2

0.3.2.0 https://github.com/zircote/Hal/

A PHP implementation of HAL http://stateless.co/hal_specification.html

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.3

 

The Development Requires

api json hal hateoas

27/11 2012

0.3.3

0.3.3.0 https://github.com/zircote/Hal/

A PHP implementation of HAL http://stateless.co/hal_specification.html

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.3

 

The Development Requires

api json hal hateoas

27/11 2012

0.4.0

0.4.0.0 https://github.com/zircote/Hal/

A PHP implementation of HAL http://stateless.co/hal_specification.html

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.3

 

The Development Requires

api json hal hateoas

19/04 2012

0.1.0

0.1.0.0 https://github.com/zircote/Hal/

A PHP implementation of HAL http://stateless.co/hal_specification.html

  Sources   Download

The Requires

  • php >=5.2.4

 

api json hal hateoas

01/04 2012

0.2.0

0.2.0.0 https://github.com/zircote/Hal/

A PHP implementation of HAL http://stateless.co/hal_specification.html

  Sources   Download

Apache2

The Requires

  • php >=5.3.3

 

api json hal hateoas