承接 chrisyue/auto-json-response-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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.

SensioLabsInsight

Latest Stable Version License Build Status Scrutinizer Code Quality Code Coverage StyleCI

Features

  • Convert null to JsonResponse(null, 204)
  • Convert $array|$object to JsonResponse($array|$normalizedObject)
  • Convert $array|$object to JsonResponse($array|$normalizedObject, 201) if the method is POST

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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-02-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固