From 8ac95cbfcc2fa3e115bef369be216f7aa30f7311 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sun, 18 Oct 2015 15:59:15 +0200 Subject: [PATCH] improved function --- src/Wallabag/CoreBundle/Helper/EntriesExport.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index 33ff6311b..e073606cf 100644 --- a/src/Wallabag/CoreBundle/Helper/EntriesExport.php +++ b/src/Wallabag/CoreBundle/Helper/EntriesExport.php @@ -331,11 +331,8 @@ class EntriesExport private function produceJSON() { - $serializer = $this->prepareSerializingContent(); - $jsonContent = $serializer->serialize($this->entries, 'json'); - return Response::create( - $jsonContent, + $this->prepareSerializingContent('json'), 200, array( 'Content-type' => 'application/json', @@ -347,11 +344,8 @@ class EntriesExport private function produceXML() { - $serializer = $this->prepareSerializingContent(); - $xmlContent = $serializer->serialize($this->entries, 'xml'); - return Response::create( - $xmlContent, + $this->prepareSerializingContent('xml'), 200, array( 'Content-type' => 'application/xml', @@ -360,18 +354,20 @@ class EntriesExport ) )->send(); } + /** * Return a Serializer object for producing processes that need it (JSON & XML). * * @return Serializer */ - private function prepareSerializingContent() + private function prepareSerializingContent($format) { $encoders = array(new XmlEncoder(), new JsonEncoder()); $normalizers = array(new ObjectNormalizer()); $normalizers[0]->setIgnoredAttributes(array('user', 'createdAt', 'updatedAt')); + $serializer = new Serializer($normalizers, $encoders); - return new Serializer($normalizers, $encoders); + return $serializer->serialize($this->entries, $format); } /**