An open API service indexing awesome lists of open source software.

https://github.com/zircote/hal

A PHP implementation of HAL http://stateless.co/hal_specification.html
https://github.com/zircote/hal

Last synced: about 1 year ago
JSON representation

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

Awesome Lists containing this project

README

          

# Hal
[![Build Status](https://secure.travis-ci.org/zircote/Hal.png)](http://travis-ci.org/zircote/Hal)

* [HAL IETF Draft](http://tools.ietf.org/html/draft-kelly-json-hal)
* [HAL Specification](http://stateless.co/hal_specification.html)
* [Hal Specification on Github](https://github.com/mikekelly/hal_specification)
* [JSON Linking With HAL](http://blog.stateless.co/post/13296666138/json-linking-with-hal)
* [Linking In Json](http://www.mnot.net/blog/2011/11/25/linking_in_json)
* [Examples of HAL](https://gist.github.com/2289546)
* [HAL on Google Groups](https://groups.google.com/d/forum/hal-discuss)

```php
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:

```javascript
{
"_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
getXML()->asXML();
```
### Result:
```xml



1
tiber
black


2
sally
white


3
fido
gray

```
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/zircote/hal/trend.png)](https://bitdeli.com/free "Bitdeli Badge")