]>
Commit | Line | Data |
---|---|---|
af497a64 NL |
1 | <?php |
2 | ||
3 | namespace Wallabag\CoreBundle\Helper; | |
4 | ||
5 | use Symfony\Component\Routing\Router; | |
a42f38d9 | 6 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; |
af497a64 | 7 | |
4086e078 NL |
8 | /** |
9 | * Manage redirections to avoid redirecting to empty routes. | |
10 | */ | |
af497a64 NL |
11 | class Redirect |
12 | { | |
13 | private $router; | |
a42f38d9 | 14 | private $actionMarkAsRead; |
af497a64 | 15 | |
a42f38d9 | 16 | public function __construct(Router $router, TokenStorage $token) |
af497a64 NL |
17 | { |
18 | $this->router = $router; | |
a42f38d9 | 19 | $this->actionMarkAsRead = $token->getToken()->getUser()->getConfig()->getActionMarkAsRead(); |
af497a64 NL |
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 | { | |
a42f38d9 NL |
30 | if ($this->actionMarkAsRead == 0) { |
31 | return $this->router->generate('homepage'); | |
32 | } | |
33 | ||
4086e078 NL |
34 | if (null !== $url) { |
35 | return $url; | |
36 | } | |
af497a64 | 37 | |
4086e078 NL |
38 | if ('' === $fallback) { |
39 | return $this->router->generate('homepage'); | |
af497a64 NL |
40 | } |
41 | ||
4086e078 | 42 | return $fallback; |
af497a64 NL |
43 | } |
44 | } |