X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FHelper%2FDetectActiveTheme.php;h=9f90ee3e21d01e38fa77b6b92c36d321bd2346b2;hb=f808b01692a835673f328d7221ba8c212caa9b61;hp=2c742e6a2c8281fe60554d8a6e8933a1646c0dca;hpb=495aecfe7417918c45d8ea32b1ee8903018449cd;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php b/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php index 2c742e6a..9f90ee3e 100644 --- a/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php +++ b/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php @@ -3,8 +3,8 @@ 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. @@ -12,19 +12,18 @@ use Wallabag\CoreBundle\Entity\User; * * If no user where logged in, it will returne the default theme */ - class DetectActiveTheme implements DeviceDetectionInterface { - protected $securityContext; + protected $tokenStorage; protected $defaultTheme; /** - * @param SecurityContextInterface $securityContext Needed to retrieve the current user - * @param string $defaultTheme Default theme when user isn't logged in + * @param TokenStorageInterface $tokenStorage Needed to retrieve the current user + * @param string $defaultTheme Default theme when user isn't logged in */ - public function __construct(SecurityContextInterface $securityContext, $defaultTheme) + public function __construct(TokenStorageInterface $tokenStorage, $defaultTheme) { - $this->securityContext = $securityContext; + $this->tokenStorage = $tokenStorage; $this->defaultTheme = $defaultTheme; } @@ -43,7 +42,13 @@ class DetectActiveTheme implements DeviceDetectionInterface */ public function getType() { - $user = $this->securityContext->getToken()->getUser(); + $token = $this->tokenStorage->getToken(); + + if (null === $token) { + return $this->defaultTheme; + } + + $user = $token->getUser(); if (!$user instanceof User) { return $this->defaultTheme;