geosocio/serialize-response

This package is abandoned and no longer maintained. The author suggests using the geosocio/http-serializer package instead.

Serializes a Controller Response

1.0.3 2017-06-19 17:44 UTC

This package is auto-updated.

Last update: 2020-12-11 16:44:29 UTC


README

Serializes a Controller Response.

Example

This controller's response would get serialized into the same format of the request.

public function showAction(Post $post) {
    return $post;
}

Configuration

Define a service in your configuration like this:

app.return_listener:
    class: GeoSocio\SerializeResponse\EventListener\KernelViewListener
    arguments:
        - '@serializer'
        - '@serializer'
        - '@security.token_storage'
        -
            - 'anonymous'
    tags:
        - { name: kernel.event_listener, event: kernel.view }

You can customize the Serialization Groups that are used by implementing GeoSocio\SerializeResponse\Serializer\UserGroupsInterface. Then getGroups will be executed on the currently authenticated user and the object that is being normalized will be passed as an argument.