jbuilder/common
Composer 安装命令:
composer require jbuilder/common
包简介
This is a library for creating the structure of the JSON for PHP 5.4+
README 文档
README
This is a library for creating the structure of the JSON for PHP.
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(); }); });
This will build the following structure:
{
"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"
}
]
}
Installation
Add this lines to your composer.json:
{
"require": {
"jbuilder/common": "dev-master"
}
}
And then execute:
$ php composer.phar install
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request
Copyright
Copyright (C) 2013 Dai Akatsuka, released under the MIT License.
统计信息
- 总下载量: 30.95k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 13
- 点击次数: 2
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-05-21