]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Helper/Redirect.php
Added a configuration to define the redirection after archiving an entry
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Helper / Redirect.php
1 <?php
2
3 namespace Wallabag\CoreBundle\Helper;
4
5 use Symfony\Component\Routing\Router;
6 use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
7
8 /**
9 * Manage redirections to avoid redirecting to empty routes.
10 */
11 class Redirect
12 {
13 private $router;
14 private $actionMarkAsRead;
15
16 public function __construct(Router $router, TokenStorage $token)
17 {
18 $this->router = $router;
19 $this->actionMarkAsRead = $token->getToken()->getUser()->getConfig()->getActionMarkAsRead();
20 }
21
22 /**
23 * @param string $url URL to redirect
24 * @param string $fallback Fallback URL if $url is null
25 *
26 * @return string
27 */
28 public function to($url, $fallback = '')
29 {
30 if ($this->actionMarkAsRead == 0) {
31 return $this->router->generate('homepage');
32 }
33
34 if (null !== $url) {
35 return $url;
36 }
37
38 if ('' === $fallback) {
39 return $this->router->generate('homepage');
40 }
41
42 return $fallback;
43 }
44 }