ekino/hal-client

此包已废弃,不再维护。未建议替代包。

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是一个轻量级的库,用于消费HAL资源。

使用Composer安装

添加依赖

php composer.phar require ekino/hal-client

如果询问版本,请输入 'dev-master'(除非您想要其他版本)

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

限制

不支持POST/PUT/PATCH/DELETE方法。

用法

<?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');
}

集成JMS/Deserializer

该库支持将资源对象反序列化为原生PHP对象。

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

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