dev-master
9999999-devHal library
GPL
The Requires
- zendframework/zend-inputfilter 2.3.0
- zendframework/zend-validator 2.3.0
- zendframework/zend-uri 2.3.0
- zendframework/zend-servicemanager 2.3.0
The Development Requires
by David White
hal
Wallogit.com
2017 © Pedro Peláez
Hal library
A very simple Hal library for creating objects that can be turned into HAL compatible payloads., (*1)
Create the top level resource of your response. All resources require an instance as Hal\Link as a constructor parameter and the type of the resource., (*2)
$resource = new Resource(new Link('self', 'http://example.com/api/book/1'), 'book');
Now that we have our resource, we can add additional HAL attributes such as a _link, (*3)
$resource->addLink(new Link('publisher', 'http://example.com/api/publisher/56'));
Or an _embedded resource, (*4)
$resource->addEmbedded(new Resource(
new Link('self', 'http://exmaple.com/api/author/99'),
'author',
null,
null,
array(
'name' => 'George Orwell',
'born' => '25 June 1903',
'died' => '21 January 1950'
)
), 'author');
And add some attributes to the resource, (*5)
$resource->addAttributes(array(
'title' => 'Animal Farm',
'pages' => 112,
'language' => 'English',
'country' => 'United Kingdom'
));
Once you have created your Resource, you can output an array representation, (*6)
$array = $resource->toArray();
Hal library
GPL
hal