diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-04-15 07:58:01 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-04-15 07:58:01 +0200 |
commit | af497a641c2a46c99bbc67215e041a46c91695bc (patch) | |
tree | 40795f74b9bf9b6bcfeab4f71e39994c6688dd31 /src/Wallabag/CoreBundle/Helper | |
parent | f2e5fdc3666a2a6525b4202ab48df05efeebaf5c (diff) | |
download | wallabag-af497a641c2a46c99bbc67215e041a46c91695bc.tar.gz wallabag-af497a641c2a46c99bbc67215e041a46c91695bc.tar.zst wallabag-af497a641c2a46c99bbc67215e041a46c91695bc.zip |
Redirect to homepage if referer is null
Fix #1924
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 | } | ||