aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Helper/Redirect.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/CoreBundle/Helper/Redirect.php')
-rw-r--r--src/Wallabag/CoreBundle/Helper/Redirect.php37
1 files changed, 37 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..c14c79d1
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Helper/Redirect.php
@@ -0,0 +1,37 @@
1<?php
2
3namespace Wallabag\CoreBundle\Helper;
4
5use Symfony\Component\Routing\Router;
6
7/**
8 * Manage redirections to avoid redirecting to empty routes.
9 */
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 {
27 if (null !== $url) {
28 return $url;
29 }
30
31 if ('' === $fallback) {
32 return $this->router->generate('homepage');
33 }
34
35 return $fallback;
36 }
37}