ekino / hal-client
此包已废弃,不再维护。未建议替代包。
HalClient
1.0.0
2014-10-17 10:28 UTC
Requires
- php: >=5.4.0
- doctrine/collections: ~1.2
- guzzle/parser: ~3.9
Requires (Dev)
- doctrine/collections: ~1.2
- jms/serializer: ~0.16
Suggests
- jms/serializer: Enable support of Resource Deserialization
This package is auto-updated.
Last update: 2024-02-25 21:37:51 UTC
README
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');