diff options
Diffstat (limited to 'src/Wallabag/ApiBundle/Controller/WallabagRestController.php')
-rw-r--r-- | src/Wallabag/ApiBundle/Controller/WallabagRestController.php | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index 7d8cfbba..44fd9683 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php | |||
@@ -2,18 +2,21 @@ | |||
2 | 2 | ||
3 | namespace Wallabag\ApiBundle\Controller; | 3 | namespace Wallabag\ApiBundle\Controller; |
4 | 4 | ||
5 | use FOS\RestBundle\Controller\FOSRestController; | 5 | use FOS\RestBundle\Controller\AbstractFOSRestController; |
6 | use JMS\Serializer\SerializationContext; | ||
6 | use Nelmio\ApiDocBundle\Annotation\ApiDoc; | 7 | use Nelmio\ApiDocBundle\Annotation\ApiDoc; |
7 | use Symfony\Component\HttpFoundation\JsonResponse; | 8 | use Symfony\Component\HttpFoundation\JsonResponse; |
8 | use Symfony\Component\Security\Core\Exception\AccessDeniedException; | 9 | use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
9 | 10 | ||
10 | class WallabagRestController extends FOSRestController | 11 | class WallabagRestController extends AbstractFOSRestController |
11 | { | 12 | { |
12 | /** | 13 | /** |
13 | * Retrieve version number. | 14 | * Retrieve version number. |
14 | * | 15 | * |
15 | * @ApiDoc() | 16 | * @ApiDoc() |
16 | * | 17 | * |
18 | * @deprecated Should use info endpoint instead | ||
19 | * | ||
17 | * @return JsonResponse | 20 | * @return JsonResponse |
18 | */ | 21 | */ |
19 | public function getVersionAction() | 22 | public function getVersionAction() |
@@ -24,6 +27,24 @@ class WallabagRestController extends FOSRestController | |||
24 | return (new JsonResponse())->setJson($json); | 27 | return (new JsonResponse())->setJson($json); |
25 | } | 28 | } |
26 | 29 | ||
30 | /** | ||
31 | * Retrieve information about the wallabag instance. | ||
32 | * | ||
33 | * @ApiDoc() | ||
34 | * | ||
35 | * @return JsonResponse | ||
36 | */ | ||
37 | public function getInfoAction() | ||
38 | { | ||
39 | $info = [ | ||
40 | 'appname' => 'wallabag', | ||
41 | 'version' => $this->container->getParameter('wallabag_core.version'), | ||
42 | 'allowed_registration' => $this->container->getParameter('wallabag_user.registration_enabled'), | ||
43 | ]; | ||
44 | |||
45 | return (new JsonResponse())->setJson($this->get('jms_serializer')->serialize($info, 'json')); | ||
46 | } | ||
47 | |||
27 | protected function validateAuthentication() | 48 | protected function validateAuthentication() |
28 | { | 49 | { |
29 | if (false === $this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) { | 50 | if (false === $this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) { |
@@ -44,4 +65,22 @@ class WallabagRestController extends FOSRestController | |||
44 | 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()); |
45 | } | 66 | } |
46 | } | 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 | } | ||
47 | } | 86 | } |