1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-07-22 17:18:37 +00:00

improved function

This commit is contained in:
Thomas Citharel 2015-10-18 15:59:15 +02:00 committed by Nicolas Lœuillet
parent b3cc1a14e7
commit 8ac95cbfcc

View file

@ -331,11 +331,8 @@ class EntriesExport
private function produceJSON() private function produceJSON()
{ {
$serializer = $this->prepareSerializingContent();
$jsonContent = $serializer->serialize($this->entries, 'json');
return Response::create( return Response::create(
$jsonContent, $this->prepareSerializingContent('json'),
200, 200,
array( array(
'Content-type' => 'application/json', 'Content-type' => 'application/json',
@ -347,11 +344,8 @@ class EntriesExport
private function produceXML() private function produceXML()
{ {
$serializer = $this->prepareSerializingContent();
$xmlContent = $serializer->serialize($this->entries, 'xml');
return Response::create( return Response::create(
$xmlContent, $this->prepareSerializingContent('xml'),
200, 200,
array( array(
'Content-type' => 'application/xml', 'Content-type' => 'application/xml',
@ -360,18 +354,20 @@ class EntriesExport
) )
)->send(); )->send();
} }
/** /**
* Return a Serializer object for producing processes that need it (JSON & XML). * Return a Serializer object for producing processes that need it (JSON & XML).
* *
* @return Serializer * @return Serializer
*/ */
private function prepareSerializingContent() private function prepareSerializingContent($format)
{ {
$encoders = array(new XmlEncoder(), new JsonEncoder()); $encoders = array(new XmlEncoder(), new JsonEncoder());
$normalizers = array(new ObjectNormalizer()); $normalizers = array(new ObjectNormalizer());
$normalizers[0]->setIgnoredAttributes(array('user', 'createdAt', 'updatedAt')); $normalizers[0]->setIgnoredAttributes(array('user', 'createdAt', 'updatedAt'));
$serializer = new Serializer($normalizers, $encoders);
return new Serializer($normalizers, $encoders); return $serializer->serialize($this->entries, $format);
} }
/** /**