diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-04-15 17:52:33 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-04-15 17:52:33 +0200 |
commit | d1f4996b77bc9c7b692cd98d835476f1c84edc28 (patch) | |
tree | e5e27ae5b1fa4f4d71623d13ba33e2ff7669f0cd /src/Wallabag/CoreBundle/Helper | |
parent | 51803026501e7098eaa889df489cd037d6dc22cd (diff) | |
parent | 345d74268b2d3d232b2de02f30e950d032a2e7b5 (diff) | |
download | wallabag-d1f4996b77bc9c7b692cd98d835476f1c84edc28.tar.gz wallabag-d1f4996b77bc9c7b692cd98d835476f1c84edc28.tar.zst wallabag-d1f4996b77bc9c7b692cd98d835476f1c84edc28.zip |
Merge pull request #1925 from wallabag/fix-redirect-without-referer
Redirect to homepage if referer is null
Diffstat (limited to 'src/Wallabag/CoreBundle/Helper')
-rw-r--r-- | src/Wallabag/CoreBundle/Helper/Redirect.php | 37 |
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 | |||
3 | namespace Wallabag\CoreBundle\Helper; | ||
4 | |||
5 | use Symfony\Component\Routing\Router; | ||
6 | |||
7 | /** | ||
8 | * Manage redirections to avoid redirecting to empty routes. | ||
9 | */ | ||
10 | class 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 | } | ||