]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Helper/Redirect.php
Added constants for redirection values
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Helper / Redirect.php
CommitLineData
af497a64
NL
1<?php
2
3namespace Wallabag\CoreBundle\Helper;
4
5use Symfony\Component\Routing\Router;
a42f38d9 6use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
f052f1fd 7use Wallabag\CoreBundle\Entity\Config;
af497a64 8
4086e078
NL
9/**
10 * Manage redirections to avoid redirecting to empty routes.
11 */
af497a64
NL
12class Redirect
13{
14 private $router;
a42f38d9 15 private $actionMarkAsRead;
af497a64 16
a42f38d9 17 public function __construct(Router $router, TokenStorage $token)
af497a64
NL
18 {
19 $this->router = $router;
a42f38d9 20 $this->actionMarkAsRead = $token->getToken()->getUser()->getConfig()->getActionMarkAsRead();
af497a64
NL
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 {
f052f1fd 31 if (Config::REDIRECT_TO_HOMEPAGE === $this->actionMarkAsRead) {
a42f38d9
NL
32 return $this->router->generate('homepage');
33 }
34
4086e078
NL
35 if (null !== $url) {
36 return $url;
37 }
af497a64 38
4086e078
NL
39 if ('' === $fallback) {
40 return $this->router->generate('homepage');
af497a64
NL
41 }
42
4086e078 43 return $fallback;
af497a64
NL
44 }
45}