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

提供HAL json/xml支持

dev-master / 1.0.x-dev 2013-04-27 21:46 UTC

This package is auto-updated.

Last update: 2020-06-02 23:04:30 UTC


README

此包用于创建HAL json。它快速且实用,存在的唯一原因是为了我的个人教育。请随意使用。

使用方法

<?php

use JoshuaEstes\Hal\Link;
use JoshuaEstes\Hal\Resource;

// This is required, you need to give the location of where the user is at
$resource = new Resource(new Link('/location', 'self'));

// Define a new resource
$productResource        = new Resource(new Link('/product/123', 'self'), 'products');
$productResource->title = 'Test Product';

// Add the resource to your main resource
$resource->addResource($productResource);

// You can add more links too
$resource->addLink(new Link('/location/next', 'next'));
$resource->addLink(new Link('/location/previous', 'previous'));

// Now you can dump the json
echo $resource->asJson();

测试

请确保安装composer.phar

php composer.phar install --dev
php bin/phpunit