From 531c8d0a5c55fa93438e227a7d349235fbd31d28 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 13 Jun 2017 18:48:10 +0200 Subject: Changed RSS to Atom feed and improve paging --- .../ParamConverter/UsernameFeedTokenConverter.php | 91 ++++++++++++++++++++++ .../ParamConverter/UsernameRssTokenConverter.php | 91 ---------------------- 2 files changed, 91 insertions(+), 91 deletions(-) create mode 100644 src/Wallabag/CoreBundle/ParamConverter/UsernameFeedTokenConverter.php delete mode 100644 src/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverter.php (limited to 'src/Wallabag/CoreBundle/ParamConverter') diff --git a/src/Wallabag/CoreBundle/ParamConverter/UsernameFeedTokenConverter.php b/src/Wallabag/CoreBundle/ParamConverter/UsernameFeedTokenConverter.php new file mode 100644 index 00000000..e220abfc --- /dev/null +++ b/src/Wallabag/CoreBundle/ParamConverter/UsernameFeedTokenConverter.php @@ -0,0 +1,91 @@ +registry = $registry; + } + + /** + * {@inheritdoc} + * + * Check, if object supported by our converter + */ + public function supports(ParamConverter $configuration) + { + // If there is no manager, this means that only Doctrine DBAL is configured + // In this case we can do nothing and just return + if (null === $this->registry || !\count($this->registry->getManagers())) { + return false; + } + + // Check, if option class was set in configuration + if (null === $configuration->getClass()) { + return false; + } + + // Get actual entity manager for class + $em = $this->registry->getManagerForClass($configuration->getClass()); + + // Check, if class name is what we need + if (null !== $em && 'Wallabag\UserBundle\Entity\User' !== $em->getClassMetadata($configuration->getClass())->getName()) { + return false; + } + + return true; + } + + /** + * {@inheritdoc} + * + * Applies converting + * + * @throws \InvalidArgumentException When route attributes are missing + * @throws NotFoundHttpException When object not found + */ + public function apply(Request $request, ParamConverter $configuration) + { + $username = $request->attributes->get('username'); + $feedToken = $request->attributes->get('token'); + + if (!$request->attributes->has('username') || !$request->attributes->has('token')) { + return false; + } + + // Get actual entity manager for class + $em = $this->registry->getManagerForClass($configuration->getClass()); + + $userRepository = $em->getRepository($configuration->getClass()); + + // Try to find user by its username and config feed_token + $user = $userRepository->findOneByUsernameAndFeedtoken($username, $feedToken); + + if (null === $user || !($user instanceof User)) { + throw new NotFoundHttpException(sprintf('%s not found.', $configuration->getClass())); + } + + // Map found user to the route's parameter + $request->attributes->set($configuration->getName(), $user); + } +} diff --git a/src/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverter.php b/src/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverter.php deleted file mode 100644 index 4a2fcab5..00000000 --- a/src/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverter.php +++ /dev/null @@ -1,91 +0,0 @@ -registry = $registry; - } - - /** - * {@inheritdoc} - * - * Check, if object supported by our converter - */ - public function supports(ParamConverter $configuration) - { - // If there is no manager, this means that only Doctrine DBAL is configured - // In this case we can do nothing and just return - if (null === $this->registry || !\count($this->registry->getManagers())) { - return false; - } - - // Check, if option class was set in configuration - if (null === $configuration->getClass()) { - return false; - } - - // Get actual entity manager for class - $em = $this->registry->getManagerForClass($configuration->getClass()); - - // Check, if class name is what we need - if (null !== $em && 'Wallabag\UserBundle\Entity\User' !== $em->getClassMetadata($configuration->getClass())->getName()) { - return false; - } - - return true; - } - - /** - * {@inheritdoc} - * - * Applies converting - * - * @throws \InvalidArgumentException When route attributes are missing - * @throws NotFoundHttpException When object not found - */ - public function apply(Request $request, ParamConverter $configuration) - { - $username = $request->attributes->get('username'); - $rssToken = $request->attributes->get('token'); - - if (!$request->attributes->has('username') || !$request->attributes->has('token')) { - return false; - } - - // Get actual entity manager for class - $em = $this->registry->getManagerForClass($configuration->getClass()); - - $userRepository = $em->getRepository($configuration->getClass()); - - // Try to find user by its username and config rss_token - $user = $userRepository->findOneByUsernameAndRsstoken($username, $rssToken); - - if (null === $user || !($user instanceof User)) { - throw new NotFoundHttpException(sprintf('%s not found.', $configuration->getClass())); - } - - // Map found user to the route's parameter - $request->attributes->set($configuration->getName(), $user); - } -} -- cgit v1.2.3