ekino/hal-client

This package is abandoned and no longer maintained. No replacement package was suggested.

HalClient

1.0.0 2014-10-17 10:28 UTC

This package is auto-updated.

Last update: 2024-02-25 21:37:51 UTC


README

Build Status

HalClient is a lightweight library to consume HAL resources.

Installation using Composer

Add the dependency:

php composer.phar require ekino/hal-client

If asked for a version, type in 'dev-master' (unless you want another version):

Please provide a version constraint for the ekino/hal-client requirement: dev-master

Limitations

There is no support for POST/PUT/PATCH/DELETE methods.

Usage

<?php

// create a HttpClient to perform http request
$client = new FileGetContentsHttpClient('http://propilex.herokuapp.com', array(
    'Authorization' => 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='
));

// create an entry point to retrieve the data
$entryPoint = new EntryPoint('/', $client);
$resource = $entryPoint->get(); // return the main resource

// retrieve a Resource object, which acts as a Pager
$pager = $resource->get('p:documents');

$pager->get('page');

$collection = $pager->get('documents'); // return a ResourceCollection

// a ResourceCollection implements the \Iterator and \Countable interface
foreach ($collection as $document) {
    // the document is a resource object
    $document->get('title');
}

Integrate JMS/Deserializer

The library support deserialization of Resource object into native PHP object.

$serializer = Ekino\HalClient\Deserialization\Builder::build();

$object = $serializer->deserialize($resource, 'Acme\Article', 'hal');