Skip to content

Instantly share code, notes, and snippets.

@ricfrank
Last active December 17, 2015 06:09
Show Gist options
  • Save ricfrank/5563308 to your computer and use it in GitHub Desktop.
Save ricfrank/5563308 to your computer and use it in GitHub Desktop.
#definizione servizi
#path/to/my_bundle/Resources/config/services.yml
services:
my_bundle.json_handler:
class: MyBundle\..\View\JsonViewHandler
my_bundle.view_handler:
parent: fos_rest.view_handler.default
calls:
- ['registerHandler', [ 'json', [@my_bundle.json_handler, 'createResponse'] ] ]
//classe custom handler'
namespace MyBundle\....\View;
use FOS\RestBundle\View\View,
FOS\RestBundle\View\ViewHandler,
Symfony\Component\HttpFoundation\Request,
Symfony\Component\HttpFoundation\Response;
class JsonViewHandler
{
/**
* @param ViewHandler $viewHandler
* @param View $view
* @param Request $request
* @param string $format
*
* @return Response
*/
public function createResponse(ViewHandler $handler, View $view, Request $request, $format)
{
//difinizione della logica
..
$data = ... ;
return new Response(data, 200, $view->getHeaders());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment