2017 © Pedro Peláez
 

symfony-bundle auto-json-response-bundle

A Symfony bundle with a listener which converts controller returned data to a appropriate JsonResponse.

image

chrisyue/auto-json-response-bundle

A Symfony bundle with a listener which converts controller returned data to a appropriate JsonResponse.

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

Auto Json Response Bundle

v1.1.1, (*1)

A Symfony listener which converts controller result to a appropriate JsonResponse., (*2)

SensioLabsInsight, (*3)

Latest Stable Version License Build Status Scrutinizer Code Quality Code Coverage StyleCI, (*4)

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., (*5)

# in your route file:
api:
    resource: ...
    defaults:
        _format: json

or in your controller file when you use annotation, (*6)

/**
 * @Route(...)
 */
public function putAction(Response $response, $_format = 'json')
{
    ...

    return $object;
}

or any other ways to set the $_format to json., (*7)

This bundle uses Symfony built-in serializer to normalize object, so the serialize feature should be enable if you want to deal with object:, (*8)

# 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:, (*9)

# 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, (*10)

After v1.1.0, this bundle support specify default serialization groups:, (*11)

#app/config/config.yml
chrisyue_auto_json_response:
    serializer:
        default_groups:
            - 'group1'
            - 'group2'

The Versions

11/05 2016

dev-develop

dev-develop http://chrisyue.com

A Symfony bundle with a listener which converts controller returned data to a appropriate JsonResponse.

  Sources   Download

MIT

The Requires

 

The Development Requires

json response

11/05 2016

dev-master

9999999-dev http://chrisyue.com

A Symfony bundle with a listener which converts controller returned data to a appropriate JsonResponse.

  Sources   Download

MIT

The Requires

 

The Development Requires

json response

11/05 2016

1.1.1

1.1.1.0 http://chrisyue.com

A Symfony bundle with a listener which converts controller returned data to a appropriate JsonResponse.

  Sources   Download

MIT

The Requires

 

The Development Requires

json response

08/04 2016

1.1.0

1.1.0.0 http://chrisyue.com

A Symfony bundle with a listener which converts controller returned data to a appropriate JsonResponse.

  Sources   Download

MIT

The Requires

 

The Development Requires

json response

08/04 2016

1.0.1

1.0.1.0 http://chrisyue.com

A Symfony bundle with a listener which converts controller returned data to a appropriate JsonResponse.

  Sources   Download

MIT

The Requires

 

The Development Requires

json response

06/03 2016

1.0.0

1.0.0.0 http://chrisyue.com

A Symfony bundle with a listener which converts controller returned data to a appropriate JsonResponse.

  Sources   Download

MIT

The Requires

 

The Development Requires

json response