jbuilder / common
这是一个为PHP 5.4+ 创建JSON结构的库
1.0.0
2013-05-21 13:38 UTC
Requires
- php: >=5.4
This package is not auto-updated.
Last update: 2024-09-23 13:33:44 UTC
README
这是一个为PHP创建JSON结构的库。
use JBuilder\Common\Encoder; echo Encoder::encode(function($json) use ($comments) { $json->title = "This is a pen"; $json->created_at = (new \DateTime())->format(\DateTime::ISO8601); $json->updated_at = (new \DateTime())->format(\DateTime::ISO8601); $json->author(function($json) { $json->name = "Dai Akatsuka"; $json->email = "d.akatsuka@gmail.com"; $json->url = "https://github.com/dakatsuka"; }); $json->comments($comments, function($json, $comment) { $json->content = $comment->getContent(); $json->created_at = $comment->getCreatedAt(); }); });
这将构建以下结构
{ "title": "This is a pen", "created_at": "2013-05-21T16:49:37+0900", "updated_at": "2013-05-21T16:49:37+0900", "author": { "name": "Dai Akatsuka", "email": "d.akatsuka@gmail.com", "url": "https://github.com/dakatsuka" }, "comments": [ { "content": "Hello! Great!", "created_at": "2013-05-21T16:49:37+0900" }, { "content": "Hello! Great!", "created_at": "2013-05-21T16:49:37+0900" } ] }
安装
将以下行添加到您的composer.json中
{ "require": { "jbuilder/common": "dev-master" } }
然后执行
$ php composer.phar install
贡献
- 将其Fork
- 创建您的功能分支(
git checkout -b my-new-feature
) - 提交您的更改(
git commit -am '添加一些功能'
) - 推送到分支(
git push origin my-new-feature
) - 创建新的Pull Request
版权
版权(C)2013 Dai Akatsuka,在MIT许可证下发布。