+ private function produceJSON()
+ {
+ $serializer = $this->prepareSerializingContent();
+ $jsonContent = $serializer->serialize($this->entries, 'json');
+
+ return Response::create(
+ $jsonContent,
+ 200,
+ array(
+ 'Content-type' => 'application/json',
+ 'Content-Disposition' => 'attachment; filename="'.$this->title.'.json"',
+ 'Content-Transfer-Encoding' => 'UTF-8',
+ )
+ )->send();
+ }
+
+ private function produceXML()
+ {
+ $serializer = $this->prepareSerializingContent();
+ $xmlContent = $serializer->serialize($this->entries, 'xml');
+
+ return Response::create(
+ $xmlContent,
+ 200,
+ array(
+ 'Content-type' => 'application/xml',
+ 'Content-Disposition' => 'attachment; filename="'.$this->title.'.xml"',
+ 'Content-Transfer-Encoding' => 'UTF-8',
+ )
+ )->send();
+ }
+ /**
+ * Return a Serializer object for producing processes that need it (JSON & XML).
+ *
+ * @return Serializer
+ */
+ private function prepareSerializingContent()
+ {
+ $encoders = array(new XmlEncoder(), new JsonEncoder());
+ $normalizers = array(new ObjectNormalizer());
+ $normalizers[0]->setIgnoredAttributes(array('user', 'createdAt', 'updatedAt'));
+
+ return new Serializer($normalizers, $encoders);
+ }
+