diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Helper')
-rw-r--r-- | src/Wallabag/CoreBundle/Helper/Redirect.php | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/Redirect.php b/src/Wallabag/CoreBundle/Helper/Redirect.php new file mode 100644 index 00000000..0921c3f9 --- /dev/null +++ b/src/Wallabag/CoreBundle/Helper/Redirect.php | |||
@@ -0,0 +1,36 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Helper; | ||
4 | |||
5 | use Symfony\Component\Routing\Router; | ||
6 | |||
7 | class Redirect | ||
8 | { | ||
9 | private $router; | ||
10 | |||
11 | public function __construct(Router $router) | ||
12 | { | ||
13 | $this->router = $router; | ||
14 | } | ||
15 | |||
16 | /** | ||
17 | * @param string $url URL to redirect | ||
18 | * @param string $fallback Fallback URL if $url is null | ||
19 | * | ||
20 | * @return string | ||
21 | */ | ||
22 | public function to($url, $fallback = '') | ||
23 | { | ||
24 | $returnUrl = $url; | ||
25 | |||
26 | if (null === $url) { | ||
27 | if ('' !== $fallback) { | ||
28 | $returnUrl = $fallback; | ||
29 | } else { | ||
30 | $returnUrl = $this->router->generate('homepage'); | ||
31 | } | ||
32 | } | ||
33 | |||
34 | return $returnUrl; | ||
35 | } | ||
36 | } | ||