aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Wallabag/ApiBundle/Controller/EntryRestController.php19
-rw-r--r--src/Wallabag/ApiBundle/Controller/SearchRestController.php19
-rw-r--r--src/Wallabag/ApiBundle/Controller/WallabagRestController.php19
-rw-r--r--tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php5
4 files changed, 21 insertions, 41 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
index f792aaf2..a79e852c 100644
--- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
@@ -4,7 +4,6 @@ namespace Wallabag\ApiBundle\Controller;
4 4
5use Hateoas\Configuration\Route; 5use Hateoas\Configuration\Route;
6use Hateoas\Representation\Factory\PagerfantaFactory; 6use Hateoas\Representation\Factory\PagerfantaFactory;
7use JMS\Serializer\SerializationContext;
8use Nelmio\ApiDocBundle\Annotation\ApiDoc; 7use Nelmio\ApiDocBundle\Annotation\ApiDoc;
9use Symfony\Component\HttpFoundation\JsonResponse; 8use Symfony\Component\HttpFoundation\JsonResponse;
10use Symfony\Component\HttpFoundation\Request; 9use Symfony\Component\HttpFoundation\Request;
@@ -774,24 +773,6 @@ class EntryRestController extends WallabagRestController
774 } 773 }
775 774
776 /** 775 /**
777 * Shortcut to send data serialized in json.
778 *
779 * @param mixed $data
780 *
781 * @return JsonResponse
782 */
783 private function sendResponse($data)
784 {
785 // https://github.com/schmittjoh/JMSSerializerBundle/issues/293
786 $context = new SerializationContext();
787 $context->setSerializeNull(true);
788
789 $json = $this->get('jms_serializer')->serialize($data, 'json', $context);
790
791 return (new JsonResponse())->setJson($json);
792 }
793
794 /**
795 * Retrieve value from the request. 776 * Retrieve value from the request.
796 * Used for POST & PATCH on a an entry. 777 * Used for POST & PATCH on a an entry.
797 * 778 *
diff --git a/src/Wallabag/ApiBundle/Controller/SearchRestController.php b/src/Wallabag/ApiBundle/Controller/SearchRestController.php
index 6620107d..f8da0ad4 100644
--- a/src/Wallabag/ApiBundle/Controller/SearchRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/SearchRestController.php
@@ -4,7 +4,6 @@ namespace Wallabag\ApiBundle\Controller;
4 4
5use Hateoas\Configuration\Route; 5use Hateoas\Configuration\Route;
6use Hateoas\Representation\Factory\PagerfantaFactory; 6use Hateoas\Representation\Factory\PagerfantaFactory;
7use JMS\Serializer\SerializationContext;
8use Nelmio\ApiDocBundle\Annotation\ApiDoc; 7use Nelmio\ApiDocBundle\Annotation\ApiDoc;
9use Pagerfanta\Adapter\DoctrineORMAdapter; 8use Pagerfanta\Adapter\DoctrineORMAdapter;
10use Pagerfanta\Pagerfanta; 9use Pagerfanta\Pagerfanta;
@@ -64,22 +63,4 @@ class SearchRestController extends WallabagRestController
64 63
65 return $this->sendResponse($paginatedCollection); 64 return $this->sendResponse($paginatedCollection);
66 } 65 }
67
68 /**
69 * Shortcut to send data serialized in json.
70 *
71 * @param mixed $data
72 *
73 * @return JsonResponse
74 */
75 private function sendResponse($data)
76 {
77 // https://github.com/schmittjoh/JMSSerializerBundle/issues/293
78 $context = new SerializationContext();
79 $context->setSerializeNull(true);
80
81 $json = $this->get('jms_serializer')->serialize($data, 'json', $context);
82
83 return (new JsonResponse())->setJson($json);
84 }
85} 66}
diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
index 3c7ad0cf..f18b0910 100644
--- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
@@ -3,6 +3,7 @@
3namespace Wallabag\ApiBundle\Controller; 3namespace Wallabag\ApiBundle\Controller;
4 4
5use FOS\RestBundle\Controller\FOSRestController; 5use FOS\RestBundle\Controller\FOSRestController;
6use JMS\Serializer\SerializationContext;
6use Nelmio\ApiDocBundle\Annotation\ApiDoc; 7use Nelmio\ApiDocBundle\Annotation\ApiDoc;
7use Symfony\Component\HttpFoundation\JsonResponse; 8use Symfony\Component\HttpFoundation\JsonResponse;
8use Symfony\Component\Security\Core\Exception\AccessDeniedException; 9use Symfony\Component\Security\Core\Exception\AccessDeniedException;
@@ -64,4 +65,22 @@ class WallabagRestController extends FOSRestController
64 throw $this->createAccessDeniedException('Access forbidden. Entry user id: ' . $requestUserId . ', logged user id: ' . $user->getId()); 65 throw $this->createAccessDeniedException('Access forbidden. Entry user id: ' . $requestUserId . ', logged user id: ' . $user->getId());
65 } 66 }
66 } 67 }
68
69 /**
70 * Shortcut to send data serialized in json.
71 *
72 * @param mixed $data
73 *
74 * @return JsonResponse
75 */
76 protected function sendResponse($data)
77 {
78 // https://github.com/schmittjoh/JMSSerializerBundle/issues/293
79 $context = new SerializationContext();
80 $context->setSerializeNull(true);
81
82 $json = $this->get('jms_serializer')->serialize($data, 'json', $context);
83
84 return (new JsonResponse())->setJson($json);
85 }
67} 86}
diff --git a/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php
index f096f21b..fd524639 100644
--- a/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php
@@ -3,7 +3,6 @@
3namespace Tests\Wallabag\ApiBundle\Controller; 3namespace Tests\Wallabag\ApiBundle\Controller;
4 4
5use Tests\Wallabag\ApiBundle\WallabagApiTestCase; 5use Tests\Wallabag\ApiBundle\WallabagApiTestCase;
6use Wallabag\CoreBundle\Entity\Entry;
7 6
8class SearchRestControllerTest extends WallabagApiTestCase 7class SearchRestControllerTest extends WallabagApiTestCase
9{ 8{
@@ -19,7 +18,7 @@ class SearchRestControllerTest extends WallabagApiTestCase
19 18
20 $content = json_decode($this->client->getResponse()->getContent(), true); 19 $content = json_decode($this->client->getResponse()->getContent(), true);
21 20
22 $this->assertGreaterThanOrEqual(1, count($content)); 21 $this->assertGreaterThanOrEqual(1, \count($content));
23 $this->assertArrayHasKey('items', $content['_embedded']); 22 $this->assertArrayHasKey('items', $content['_embedded']);
24 $this->assertGreaterThanOrEqual(0, $content['total']); 23 $this->assertGreaterThanOrEqual(0, $content['total']);
25 $this->assertSame(1, $content['page']); 24 $this->assertSame(1, $content['page']);
@@ -49,7 +48,7 @@ class SearchRestControllerTest extends WallabagApiTestCase
49 48
50 $content = json_decode($this->client->getResponse()->getContent(), true); 49 $content = json_decode($this->client->getResponse()->getContent(), true);
51 50
52 $this->assertGreaterThanOrEqual(1, count($content)); 51 $this->assertGreaterThanOrEqual(1, \count($content));
53 $this->assertArrayHasKey('items', $content['_embedded']); 52 $this->assertArrayHasKey('items', $content['_embedded']);
54 $this->assertGreaterThanOrEqual(0, $content['total']); 53 $this->assertGreaterThanOrEqual(0, $content['total']);
55 $this->assertSame(1, $content['page']); 54 $this->assertSame(1, $content['page']);