From: Thomas Citharel Date: Sun, 18 Oct 2015 13:59:15 +0000 (+0200) Subject: improved function X-Git-Tag: 2.0.0-alpha.1~14^2~5 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=8ac95cbfcc2fa3e115bef369be216f7aa30f7311;hp=b3cc1a14e7b9939fdaf7e71fac40ed7c42727854;p=github%2Fwallabag%2Fwallabag.git improved function --- diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index 33ff6311..e073606c 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); } /**