Use FQCN instead of service alias

This commit is contained in:
Yassine Guedidi
2022-08-28 02:01:46 +02:00
parent 156158673f
commit eb43c78720
62 changed files with 579 additions and 404 deletions

View File

@ -3,6 +3,7 @@
namespace Wallabag\ApiBundle\Controller;
use JMS\Serializer\SerializationContext;
use JMS\Serializer\SerializerInterface;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Symfony\Component\HttpFoundation\JsonResponse;
@ -19,7 +20,7 @@ class ConfigRestController extends WallabagRestController
{
$this->validateAuthentication();
$json = $this->get('jms_serializer')->serialize(
$json = $this->get(SerializerInterface::class)->serialize(
$this->getUser()->getConfig(),
'json',
SerializationContext::create()->setGroups(['config_api'])

View File

@ -4,7 +4,9 @@ namespace Wallabag\ApiBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Translation\TranslatorInterface;
use Wallabag\ApiBundle\Entity\Client;
use Wallabag\ApiBundle\Form\Type\ClientType;
@ -45,9 +47,9 @@ class DeveloperController extends Controller
$em->persist($client);
$em->flush();
$this->get('session')->getFlashBag()->add(
$this->get(SessionInterface::class)->getFlashBag()->add(
'notice',
$this->get('translator')->trans('flashes.developer.notice.client_created', ['%name%' => $client->getName()])
$this->get(TranslatorInterface::class)->trans('flashes.developer.notice.client_created', ['%name%' => $client->getName()])
);
return $this->render('@WallabagCore/themes/common/Developer/client_parameters.html.twig', [
@ -79,9 +81,9 @@ class DeveloperController extends Controller
$em->remove($client);
$em->flush();
$this->get('session')->getFlashBag()->add(
$this->get(SessionInterface::class)->getFlashBag()->add(
'notice',
$this->get('translator')->trans('flashes.developer.notice.client_deleted', ['%name%' => $client->getName()])
$this->get(TranslatorInterface::class)->trans('flashes.developer.notice.client_deleted', ['%name%' => $client->getName()])
);
return $this->redirect($this->generateUrl('developer'));

View File

@ -5,6 +5,7 @@ namespace Wallabag\ApiBundle\Controller;
use Hateoas\Configuration\Route;
use Hateoas\Representation\Factory\PagerfantaFactory;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@ -257,7 +258,7 @@ class EntryRestController extends WallabagRestController
if (false !== $entry) {
// entry deleted, dispatch event about it!
$this->get('event_dispatcher')->dispatch(EntryDeletedEvent::NAME, new EntryDeletedEvent($entry));
$this->get(EventDispatcherInterface::class)->dispatch(EntryDeletedEvent::NAME, new EntryDeletedEvent($entry));
$em = $this->getDoctrine()->getManager();
$em->remove($entry);
@ -322,7 +323,7 @@ class EntryRestController extends WallabagRestController
$results[$key]['entry'] = $entry instanceof Entry ? $entry->getId() : false;
// entry saved, dispatch event about it!
$this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
$this->get(EventDispatcherInterface::class)->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
}
return $this->sendResponse($results);
@ -430,7 +431,7 @@ class EntryRestController extends WallabagRestController
$em->flush();
// entry saved, dispatch event about it!
$this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
$this->get(EventDispatcherInterface::class)->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
return $this->sendResponse($entry);
}
@ -547,7 +548,7 @@ class EntryRestController extends WallabagRestController
$em->flush();
// entry saved, dispatch event about it!
$this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
$this->get(EventDispatcherInterface::class)->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
return $this->sendResponse($entry);
}
@ -590,7 +591,7 @@ class EntryRestController extends WallabagRestController
$em->flush();
// entry saved, dispatch event about it!
$this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
$this->get(EventDispatcherInterface::class)->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
return $this->sendResponse($entry);
}
@ -628,7 +629,7 @@ class EntryRestController extends WallabagRestController
}
// entry deleted, dispatch event about it!
$this->get('event_dispatcher')->dispatch(EntryDeletedEvent::NAME, new EntryDeletedEvent($entry));
$this->get(EventDispatcherInterface::class)->dispatch(EntryDeletedEvent::NAME, new EntryDeletedEvent($entry));
$em = $this->getDoctrine()->getManager();
$em->remove($entry);

View File

@ -2,6 +2,7 @@
namespace Wallabag\ApiBundle\Controller;
use JMS\Serializer\SerializerInterface;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
@ -25,7 +26,7 @@ class TagRestController extends WallabagRestController
->getRepository(Tag::class)
->findAllTags($this->getUser()->getId());
$json = $this->get('jms_serializer')->serialize($tags, 'json');
$json = $this->get(SerializerInterface::class)->serialize($tags, 'json');
return (new JsonResponse())->setJson($json);
}
@ -60,7 +61,7 @@ class TagRestController extends WallabagRestController
$this->cleanOrphanTag($tag);
$json = $this->get('jms_serializer')->serialize($tag, 'json');
$json = $this->get(SerializerInterface::class)->serialize($tag, 'json');
return (new JsonResponse())->setJson($json);
}
@ -94,7 +95,7 @@ class TagRestController extends WallabagRestController
$this->cleanOrphanTag($tags);
$json = $this->get('jms_serializer')->serialize($tags, 'json');
$json = $this->get(SerializerInterface::class)->serialize($tags, 'json');
return (new JsonResponse())->setJson($json);
}
@ -126,7 +127,7 @@ class TagRestController extends WallabagRestController
$this->cleanOrphanTag($tag);
$json = $this->get('jms_serializer')->serialize($tag, 'json');
$json = $this->get(SerializerInterface::class)->serialize($tag, 'json');
return (new JsonResponse())->setJson($json);
}

View File

@ -2,12 +2,17 @@
namespace Wallabag\ApiBundle\Controller;
use Craue\ConfigBundle\Util\Config;
use FOS\UserBundle\Event\UserEvent;
use FOS\UserBundle\FOSUserEvents;
use FOS\UserBundle\Model\UserManagerInterface;
use JMS\Serializer\SerializationContext;
use JMS\Serializer\SerializerInterface;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Translation\TranslatorInterface;
use Wallabag\ApiBundle\Entity\Client;
use Wallabag\UserBundle\Entity\User;
@ -45,15 +50,15 @@ class UserRestController extends WallabagRestController
*/
public function putUserAction(Request $request)
{
if (!$this->container->getParameter('fosuser_registration') || !$this->get('craue_config')->get('api_user_registration')) {
$json = $this->get('jms_serializer')->serialize(['error' => "Server doesn't allow registrations"], 'json');
if (!$this->container->getParameter('fosuser_registration') || !$this->get(Config::class)->get('api_user_registration')) {
$json = $this->get(SerializerInterface::class)->serialize(['error' => "Server doesn't allow registrations"], 'json');
return (new JsonResponse())
->setJson($json)
->setStatusCode(JsonResponse::HTTP_FORBIDDEN);
}
$userManager = $this->get('fos_user.user_manager');
$userManager = $this->get(UserManagerInterface::class);
$user = $userManager->createUser();
// user will be disabled BY DEFAULT to avoid spamming account to be enabled
$user->setEnabled(false);
@ -92,7 +97,7 @@ class UserRestController extends WallabagRestController
$errors['password'] = $this->translateErrors($data['plainPassword']['children']['first']['errors']);
}
$json = $this->get('jms_serializer')->serialize(['error' => $errors], 'json');
$json = $this->get(SerializerInterface::class)->serialize(['error' => $errors], 'json');
return (new JsonResponse())
->setJson($json)
@ -111,7 +116,7 @@ class UserRestController extends WallabagRestController
// dispatch a created event so the associated config will be created
$event = new UserEvent($user, $request);
$this->get('event_dispatcher')->dispatch(FOSUserEvents::USER_CREATED, $event);
$this->get(EventDispatcherInterface::class)->dispatch(FOSUserEvents::USER_CREATED, $event);
return $this->sendUser($user, 'user_api_with_client', JsonResponse::HTTP_CREATED);
}
@ -126,7 +131,7 @@ class UserRestController extends WallabagRestController
*/
private function sendUser(User $user, $group = 'user_api', $status = JsonResponse::HTTP_OK)
{
$json = $this->get('jms_serializer')->serialize(
$json = $this->get(SerializerInterface::class)->serialize(
$user,
'json',
SerializationContext::create()->setGroups([$group])
@ -148,7 +153,7 @@ class UserRestController extends WallabagRestController
{
$translatedErrors = [];
foreach ($errors as $error) {
$translatedErrors[] = $this->get('translator')->trans($error);
$translatedErrors[] = $this->get(TranslatorInterface::class)->trans($error);
}
return $translatedErrors;

View File

@ -4,8 +4,11 @@ namespace Wallabag\ApiBundle\Controller;
use FOS\RestBundle\Controller\AbstractFOSRestController;
use JMS\Serializer\SerializationContext;
use JMS\Serializer\SerializerInterface;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
class WallabagRestController extends AbstractFOSRestController
@ -22,7 +25,7 @@ class WallabagRestController extends AbstractFOSRestController
public function getVersionAction()
{
$version = $this->container->getParameter('wallabag_core.version');
$json = $this->get('jms_serializer')->serialize($version, 'json');
$json = $this->get(SerializerInterface::class)->serialize($version, 'json');
return (new JsonResponse())->setJson($json);
}
@ -42,12 +45,12 @@ class WallabagRestController extends AbstractFOSRestController
'allowed_registration' => $this->container->getParameter('fosuser_registration'),
];
return (new JsonResponse())->setJson($this->get('jms_serializer')->serialize($info, 'json'));
return (new JsonResponse())->setJson($this->get(SerializerInterface::class)->serialize($info, 'json'));
}
protected function validateAuthentication()
{
if (false === $this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
if (false === $this->get(AuthorizationCheckerInterface::class)->isGranted('IS_AUTHENTICATED_FULLY')) {
throw new AccessDeniedException();
}
}
@ -60,7 +63,7 @@ class WallabagRestController extends AbstractFOSRestController
*/
protected function validateUserAccess($requestUserId)
{
$user = $this->get('security.token_storage')->getToken()->getUser();
$user = $this->get(TokenStorageInterface::class)->getToken()->getUser();
if ($requestUserId !== $user->getId()) {
throw $this->createAccessDeniedException('Access forbidden. Entry user id: ' . $requestUserId . ', logged user id: ' . $user->getId());
}
@ -79,7 +82,7 @@ class WallabagRestController extends AbstractFOSRestController
$context = new SerializationContext();
$context->setSerializeNull(true);
$json = $this->get('jms_serializer')->serialize($data, 'json', $context);
$json = $this->get(SerializerInterface::class)->serialize($data, 'json', $context);
return (new JsonResponse())->setJson($json);
}