diff options
author | Thomas Citharel <tcit@tcit.fr> | 2017-06-13 18:48:10 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2019-04-25 13:46:31 +0200 |
commit | 531c8d0a5c55fa93438e227a7d349235fbd31d28 (patch) | |
tree | de2ff4a1e09161a5bbec32170471190e836d3bbc /src/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverter.php | |
parent | 522e37ad274361dde697da13a92ff3f846599822 (diff) | |
download | wallabag-531c8d0a5c55fa93438e227a7d349235fbd31d28.tar.gz wallabag-531c8d0a5c55fa93438e227a7d349235fbd31d28.tar.zst wallabag-531c8d0a5c55fa93438e227a7d349235fbd31d28.zip |
Changed RSS to Atom feed and improve paging
Diffstat (limited to 'src/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverter.php')
-rw-r--r-- | src/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverter.php | 91 |
1 files changed, 0 insertions, 91 deletions
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 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\ParamConverter; | ||
4 | |||
5 | use Doctrine\Common\Persistence\ManagerRegistry; | ||
6 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; | ||
7 | use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInterface; | ||
8 | use Symfony\Component\HttpFoundation\Request; | ||
9 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
10 | use Wallabag\UserBundle\Entity\User; | ||
11 | |||
12 | /** | ||
13 | * ParamConverter used in the RSS controller to retrieve the right user according to | ||
14 | * username & token given in the url. | ||
15 | * | ||
16 | * @see http://stfalcon.com/en/blog/post/symfony2-custom-paramconverter | ||
17 | */ | ||
18 | class UsernameRssTokenConverter implements ParamConverterInterface | ||
19 | { | ||
20 | private $registry; | ||
21 | |||
22 | /** | ||
23 | * @param ManagerRegistry $registry Manager registry | ||
24 | */ | ||
25 | public function __construct(ManagerRegistry $registry = null) | ||
26 | { | ||
27 | $this->registry = $registry; | ||
28 | } | ||
29 | |||
30 | /** | ||
31 | * {@inheritdoc} | ||
32 | * | ||
33 | * Check, if object supported by our converter | ||
34 | */ | ||
35 | public function supports(ParamConverter $configuration) | ||
36 | { | ||
37 | // If there is no manager, this means that only Doctrine DBAL is configured | ||
38 | // In this case we can do nothing and just return | ||
39 | if (null === $this->registry || !\count($this->registry->getManagers())) { | ||
40 | return false; | ||
41 | } | ||
42 | |||
43 | // Check, if option class was set in configuration | ||
44 | if (null === $configuration->getClass()) { | ||
45 | return false; | ||
46 | } | ||
47 | |||
48 | // Get actual entity manager for class | ||
49 | $em = $this->registry->getManagerForClass($configuration->getClass()); | ||
50 | |||
51 | // Check, if class name is what we need | ||
52 | if (null !== $em && 'Wallabag\UserBundle\Entity\User' !== $em->getClassMetadata($configuration->getClass())->getName()) { | ||
53 | return false; | ||
54 | } | ||
55 | |||
56 | return true; | ||
57 | } | ||
58 | |||
59 | /** | ||
60 | * {@inheritdoc} | ||
61 | * | ||
62 | * Applies converting | ||
63 | * | ||
64 | * @throws \InvalidArgumentException When route attributes are missing | ||
65 | * @throws NotFoundHttpException When object not found | ||
66 | */ | ||
67 | public function apply(Request $request, ParamConverter $configuration) | ||
68 | { | ||
69 | $username = $request->attributes->get('username'); | ||
70 | $rssToken = $request->attributes->get('token'); | ||
71 | |||
72 | if (!$request->attributes->has('username') || !$request->attributes->has('token')) { | ||
73 | return false; | ||
74 | } | ||
75 | |||
76 | // Get actual entity manager for class | ||
77 | $em = $this->registry->getManagerForClass($configuration->getClass()); | ||
78 | |||
79 | $userRepository = $em->getRepository($configuration->getClass()); | ||
80 | |||
81 | // Try to find user by its username and config rss_token | ||
82 | $user = $userRepository->findOneByUsernameAndRsstoken($username, $rssToken); | ||
83 | |||
84 | if (null === $user || !($user instanceof User)) { | ||
85 | throw new NotFoundHttpException(sprintf('%s not found.', $configuration->getClass())); | ||
86 | } | ||
87 | |||
88 | // Map found user to the route's parameter | ||
89 | $request->attributes->set($configuration->getName(), $user); | ||
90 | } | ||
91 | } | ||