]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Helper/Redirect.php
Added constants for redirection values
[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 use Wallabag\CoreBundle\Entity\Config;
8
9 /**
10 * Manage redirections to avoid redirecting to empty routes.
11 */
12 class Redirect
13 {
14 private $router;
15 private $actionMarkAsRead;
16
17 public function __construct(Router $router, TokenStorage $token)
18 {
19 $this->router = $router;
20 $this->actionMarkAsRead = $token->getToken()->getUser()->getConfig()->getActionMarkAsRead();
21 }
22
23 /**
24 * @param string $url URL to redirect
25 * @param string $fallback Fallback URL if $url is null
26 *
27 * @return string
28 */
29 public function to($url, $fallback = '')
30 {
31 if (Config::REDIRECT_TO_HOMEPAGE === $this->actionMarkAsRead) {
32 return $this->router->generate('homepage');
33 }
34
35 if (null !== $url) {
36 return $url;
37 }
38
39 if ('' === $fallback) {
40 return $this->router->generate('homepage');
41 }
42
43 return $fallback;
44 }
45 }