Last active
December 17, 2015 06:09
-
-
Save ricfrank/5563308 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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'] ] ] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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