mirror of
https://github.com/wallabag/wallabag.git
synced 2024-09-27 05:50:02 +00:00
37 lines
688 B
PHP
37 lines
688 B
PHP
<?php
|
|
|
|
namespace Wallabag\CoreBundle\Helper;
|
|
|
|
use Symfony\Component\Routing\Router;
|
|
|
|
/**
|
|
* Manage redirections to avoid redirecting to empty routes.
|
|
*/
|
|
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 = '')
|
|
{
|
|
if (null !== $url) {
|
|
return $url;
|
|
}
|
|
|
|
if ('' === $fallback) {
|
|
return $this->router->generate('homepage');
|
|
}
|
|
|
|
return $fallback;
|
|
}
|
|
}
|