Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: php-5.2

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 library
Octocat-spinner-32 scripts
Octocat-spinner-32 tests
Octocat-spinner-32 CHANGELOG
Octocat-spinner-32 LICENSE-2.0.txt
Octocat-spinner-32 VERSION
Octocat-spinner-32 build.xml
Octocat-spinner-32 composer.json
Octocat-spinner-32 package.xml
Octocat-spinner-32 readme.md
readme.md

Hal

<?php
/* Create a new Resource Parent */
$parent = new Hal_Resource('/dogs');
/* Add any relevent links */
$parent->setLink(new Hal_Link('/dogs?q={text}', 'search'));
$dogs[1] =  new Hal_Resource('/dogs/1');
$dogs[1]->setData(
    array(
        'id' => '1', 
        'name' => 'tiber', 
        'color' => 'black'
    )
);
$dogs[2] =  new Hal_Resource(
    '/dogs/2',array(
        'id' => '2', 
        'name' => 'sally', 
        'color' => 'white'
    )
);
$dogs[3] =  new Hal_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>
Something went wrong with that request. Please try again.