SerializedResponseBundle
A simple bundle to provide an easy way to send out json/xml/yaml responses of serialized objects with annotations., (*1)
Introduction
This Bundle allows you to directly return serializable objects as from within a controller to receive a serialized response in json/xml/yaml format. It requires jms/serializer-bundle
., (*2)
Installation
Step 1
This library can be easily installed via composer, (*3)
composer pulpmedia/serialized-response-bundle, (*4)
or just add it to your composer.json file directly. This will install the pulpmedia/serialized-response-bundle and jms/serializer if not already installed., (*5)
Step 2
Enable the bundle in the kernel:, (*6)
``` php
<?php
// app/AppKernel.php, (*7)
public function registerBundles()
{
$bundles = array(
new JMS\SerializerBundle\JMSSerializerBundle(), //If you have not already done this already
// ...
new Pulpmedia\SerializedResponseBundle\PulpmediaSerializedResponseBundle(),
);
}, (*8)
##Usage
Using the Bundle is as easy as it comes. By returning the Object that should be serialized and using the corresponding annotation;
``` php
<?php
namespace My\Bundle\Controller
use Pulpmedia\SerializedResponseBundle\Annotation\SerializedResponse;
// ...
class MyController extents Controller{
/**
* @Route("/get/{id}")
* @SerializedResponse(format="json/xml/yaml")
*/
public function getAction($id){
$em = $this->getDoctrine()->getManager();
if($object = $em->getRepository('MyBundle:Entity')->find($id)){
return $object;
}
return null;
}
}