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.
*
* 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;
}
*/
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;