chrisyue/auto-json-response-bundle
Composer 安装命令:
composer require chrisyue/auto-json-response-bundle
包简介
A Symfony bundle with a listener which converts controller returned data to a appropriate JsonResponse.
关键字:
README 文档
README
v1.1.1
A Symfony listener which converts controller result to a appropriate JsonResponse.
Features
- Convert
nulltoJsonResponse(null, 204) - Convert
$array|$objecttoJsonResponse($array|$normalizedObject) - Convert
$array|$objecttoJsonResponse($array|$normalizedObject, 201)if the method isPOST
Installation
$ composer require chrisyue/auto-json-response-bundle
// AppKernel.php public function registerBundles() { $bundles = array( // ... new Chrisyue\Bundle\AutoJsonResponseBundle\ChrisyueAutoJsonResponseBundle(), ); }
Usage
This bundle will take effect if the route _format parameter is set to json.
# in your route file: api: resource: ... defaults: _format: json
or in your controller file when you use annotation
/** * @Route(...) */ public function putAction(Response $response, $_format = 'json') { ... return $object; }
or any other ways to set the $_format to json.
This bundle uses Symfony built-in serializer to normalize object, so the serialize feature should be enable if you want to deal with object:
# app/config/config.yml framework: # ... serializer: enabled: true
with the power of the built-in serializer, we can do more configuration to meet our needs, like convert camalCase property to snake_case:
# app/config/config.yml framework: serializer: enable_annotations: true name_converter: serializer.name_converter.camel_case_to_snake_case
More information about serialize, just check symfony official documentation
After v1.1.0, this bundle support specify default serialization groups:
#app/config/config.yml chrisyue_auto_json_response: serializer: default_groups: - 'group1' - 'group2'
统计信息
- 总下载量: 409
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-02-21