]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php
Add a real configuration for CS-Fixer
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Helper / DetectActiveTheme.php
index 446629db2196ad5a76f460e2b5b45cd6e85c6ef8..9f90ee3e21d01e38fa77b6b92c36d321bd2346b2 100644 (file)
@@ -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.
@@ -14,16 +14,16 @@ use Wallabag\CoreBundle\Entity\User;
  */
 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;
     }
 
@@ -42,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;