+ ]
+ );
+ }
+
+ /**
+ * Dump a XML file.
+ *
+ * @return Response
+ */
+ private function produceXml()
+ {
+ return Response::create(
+ $this->prepareSerializingContent('xml'),
+ 200,
+ [
+ 'Content-type' => 'application/xml',
+ 'Content-Disposition' => 'attachment; filename="' . $this->title . '.xml"',
+ 'Content-Transfer-Encoding' => 'UTF-8',
+ ]
+ );
+ }
+
+ /**
+ * Dump a TXT file.
+ *
+ * @return Response
+ */
+ private function produceTxt()
+ {
+ $content = '';
+ $bar = str_repeat('=', 100);
+ foreach ($this->entries as $entry) {
+ $content .= "\n\n" . $bar . "\n\n" . $entry->getTitle() . "\n\n" . $bar . "\n\n";
+ $content .= trim(preg_replace('/\s+/S', ' ', strip_tags($entry->getContent()))) . "\n\n";
+ }
+
+ return Response::create(
+ $content,
+ 200,
+ [
+ 'Content-type' => 'text/plain',
+ 'Content-Disposition' => 'attachment; filename="' . $this->title . '.txt"',
+ 'Content-Transfer-Encoding' => 'UTF-8',
+ ]
+ );
+ }
+
+ /**
+ * Return a Serializer object for producing processes that need it (JSON & XML).
+ *
+ * @param string $format
+ *
+ * @return Serializer
+ */
+ private function prepareSerializingContent($format)
+ {
+ $serializer = SerializerBuilder::create()->build();
+
+ return $serializer->serialize(
+ $this->entries,
+ $format,
+ SerializationContext::create()->setGroups(['entries_for_user'])
+ );