zircote/hal
Composer 安装命令:
composer require zircote/hal
包简介
A PHP implementation of HAL http://stateless.co/hal_specification.html
README 文档
README
- HAL IETF Draft
- HAL Specification
- Hal Specification on Github
- JSON Linking With HAL
- Linking In Json
- Examples of HAL
- HAL on Google Groups
<?php use Hal\Resource, Hal\Link; /* Create a new Resource Parent */ $parent = new Resource('/dogs'); /* Add any relevent links */ $parent->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:
{ "_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 echo $parent->getXML()->asXML();
Result:
<?xml version="1.0"?> <resource href="/dogs"> <link href="/dogs?q={text}" rel="search" /> <resource href="/dogs/1" rel="dog"> <id>1</id> <name>tiber</name> <color>black</color> </resource> <resource href="/dogs/2" rel="dog"> <id>2</id> <name>sally</name> <color>white</color> </resource> <resource href="/dogs/3" rel="dog"> <id>3</id> <name>fido</name> <color>gray</color> </resource> </resource>
zircote/hal 适用场景与选型建议
zircote/hal 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 232.12k 次下载、GitHub Stars 达 94, 最近一次更新时间为 2012 年 04 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「json」 「api」 「hal」 「HATEOAS」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 zircote/hal 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 zircote/hal 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 zircote/hal 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kinikit - PHP Application development framework MVC component
Build a Hypermedia API response once and return it in multiple formats
ext-json wrapper with sane defaults
HAL+JSON & HAL+XML API transformer outputting valid API responses.
A package to cast json fields, each sub-keys is castable
for HATEOAS REST web services
统计信息
- 总下载量: 232.12k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 96
- 点击次数: 9
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2012-04-19