]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Helper/Redirect.php
Merge pull request #2495 from wallabag/add-shortcuts
[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;
6
4086e078
NL
7/**
8 * Manage redirections to avoid redirecting to empty routes.
9 */
af497a64
NL
10class Redirect
11{
12 private $router;
13
14 public function __construct(Router $router)
15 {
16 $this->router = $router;
17 }
18
19 /**
20 * @param string $url URL to redirect
21 * @param string $fallback Fallback URL if $url is null
22 *
23 * @return string
24 */
25 public function to($url, $fallback = '')
26 {
4086e078
NL
27 if (null !== $url) {
28 return $url;
29 }
af497a64 30
4086e078
NL
31 if ('' === $fallback) {
32 return $this->router->generate('homepage');
af497a64
NL
33 }
34
4086e078 35 return $fallback;
af497a64
NL
36 }
37}