X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FHelper%2FRedirect.php;h=9d1a6345d37dca0ca1509fe57761c3e8c64da26b;hb=refs%2Fpull%2F3716%2Fhead;hp=918d926616a517fa26b2e1d9c02cdcad709cf3a7;hpb=a42f38d9fb7906b785285fab2a09f8c2b9efe996;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Helper/Redirect.php b/src/Wallabag/CoreBundle/Helper/Redirect.php index 918d9266..9d1a6345 100644 --- a/src/Wallabag/CoreBundle/Helper/Redirect.php +++ b/src/Wallabag/CoreBundle/Helper/Redirect.php @@ -3,7 +3,8 @@ namespace Wallabag\CoreBundle\Helper; use Symfony\Component\Routing\Router; -use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; +use Wallabag\CoreBundle\Entity\Config; /** * Manage redirections to avoid redirecting to empty routes. @@ -11,23 +12,31 @@ use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; class Redirect { private $router; - private $actionMarkAsRead; + private $tokenStorage; - public function __construct(Router $router, TokenStorage $token) + public function __construct(Router $router, TokenStorageInterface $tokenStorage) { $this->router = $router; - $this->actionMarkAsRead = $token->getToken()->getUser()->getConfig()->getActionMarkAsRead(); + $this->tokenStorage = $tokenStorage; } /** - * @param string $url URL to redirect - * @param string $fallback Fallback URL if $url is null + * @param string $url URL to redirect + * @param string $fallback Fallback URL if $url is null + * @param bool $ignoreActionMarkAsRead Ignore configured action when mark as read * * @return string */ - public function to($url, $fallback = '') + public function to($url, $fallback = '', $ignoreActionMarkAsRead = false) { - if ($this->actionMarkAsRead == 0) { + $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null; + + if (null === $user || !\is_object($user)) { + return $url; + } + + if (!$ignoreActionMarkAsRead && + Config::REDIRECT_TO_HOMEPAGE === $user->getConfig()->getActionMarkAsRead()) { return $this->router->generate('homepage'); }