aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Helper/Redirect.php
blob: 0921c3f9e686dcba07eaace5d48391abf922410b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php

namespace Wallabag\CoreBundle\Helper;

use Symfony\Component\Routing\Router;

class Redirect
{
    private $router;

    public function __construct(Router $router)
    {
        $this->router = $router;
    }

    /**
     * @param string $url      URL to redirect
     * @param string $fallback Fallback URL if $url is null
     *
     * @return string
     */
    public function to($url, $fallback = '')
    {
        $returnUrl = $url;

        if (null === $url) {
            if ('' !== $fallback) {
                $returnUrl = $fallback;
            } else {
                $returnUrl = $this->router->generate('homepage');
            }
        }

        return $returnUrl;
    }
}