pulpmedia / serialized-response-bundle
A simple bundle to provide an easy way to send out json/xml/yaml responses of serialized objects with annotations.
Installs: 8
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 4
Forks: 1
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.3.2
- jms/serializer-bundle: dev-master
This package is auto-updated.
Last update: 2024-12-21 00:57:08 UTC
README
A simple bundle to provide an easy way to send out json/xml/yaml responses of serialized objects with annotations.
##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
.
##Installation ###Step 1 This library can be easily installed via composer
composer pulpmedia/serialized-response-bundle
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.
###Step 2 Enable the bundle in the kernel:
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( new JMS\SerializerBundle\JMSSerializerBundle(), //If you have not already done this already // ... new Pulpmedia\SerializedResponseBundle\PulpmediaSerializedResponseBundle(), ); }
##Usage Using the Bundle is as easy as it comes. By returning the Object that should be serialized and using the corresponding annotation;
<?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; } }