X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FHelper%2FDetectActiveTheme.php;h=23e98042c60563b985584eefa2d26ac1d00323bb;hb=dfbbf0e18ad585e318c2609e46963e4b9fd198ef;hp=2a943bb7d2400e3489ea49438ab97759a3929c16;hpb=32da2a70ef278bd42f66eb82c3fbf1905a417b87;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php b/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php index 2a943bb7..23e98042 100644 --- a/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php +++ b/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php @@ -3,16 +3,28 @@ namespace Wallabag\CoreBundle\Helper; use Liip\ThemeBundle\Helper\DeviceDetectionInterface; -use Symfony\Component\Security\Core\SecurityContextInterface; -use Wallabag\CoreBundle\Entity\User; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; +use Wallabag\UserBundle\Entity\User; +/** + * This class intend to detect the active theme for the logged in user. + * It will retrieve the configured theme of the user. + * + * If no user where logged in, it will returne the default theme + */ class DetectActiveTheme implements DeviceDetectionInterface { - protected $securityContext; + protected $tokenStorage; + protected $defaultTheme; - public function __construct(SecurityContextInterface $securityContext) + /** + * @param TokenStorageInterface $tokenStorage Needed to retrieve the current user + * @param string $defaultTheme Default theme when user isn't logged in + */ + public function __construct(TokenStorageInterface $tokenStorage, $defaultTheme) { - $this->securityContext = $securityContext; + $this->tokenStorage = $tokenStorage; + $this->defaultTheme = $defaultTheme; } public function setUserAgent($userAgent) @@ -21,25 +33,31 @@ class DetectActiveTheme implements DeviceDetectionInterface /** * This should return the active theme for the logged in user. - * No active theme for: + * + * Default theme for: * - anonymous user - * - user without a config (shouldn't happen..) + * - user without a config (shouldn't happen ..) * * @return string */ public function getType() { - $user = $this->securityContext->getToken()->getUser(); + $token = $this->tokenStorage->getToken(); + + if (is_null($token)) { + return $this->defaultTheme; + } + + $user = $token->getUser(); - // anon user don't deserve a theme if (!$user instanceof User) { - return false; + return $this->defaultTheme; } $config = $user->getConfig(); if (!$config) { - return false; + return $this->defaultTheme; } return $config->getTheme();