aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Helper
diff options
context:
space:
mode:
authorJeremy <jeremy.benoist@gmail.com>2015-03-01 08:22:29 +0100
committerJeremy <jeremy.benoist@gmail.com>2015-03-01 10:49:17 +0100
commit495aecfe7417918c45d8ea32b1ee8903018449cd (patch)
treef79e2d133e66108b3e0e814dc206d09344e72df0 /src/Wallabag/CoreBundle/Helper
parent71798e4ec428d03b1ce7116ae918a05a2d9b5044 (diff)
downloadwallabag-495aecfe7417918c45d8ea32b1ee8903018449cd.tar.gz
wallabag-495aecfe7417918c45d8ea32b1ee8903018449cd.tar.zst
wallabag-495aecfe7417918c45d8ea32b1ee8903018449cd.zip
Cleanup & simplify theme
Diffstat (limited to 'src/Wallabag/CoreBundle/Helper')
-rw-r--r--src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php b/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php
index 2a943bb7..2c742e6a 100644
--- a/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php
+++ b/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php
@@ -6,13 +6,26 @@ use Liip\ThemeBundle\Helper\DeviceDetectionInterface;
6use Symfony\Component\Security\Core\SecurityContextInterface; 6use Symfony\Component\Security\Core\SecurityContextInterface;
7use Wallabag\CoreBundle\Entity\User; 7use Wallabag\CoreBundle\Entity\User;
8 8
9/**
10 * This class intend to detect the active theme for the logged in user.
11 * It will retrieve the configured theme of the user.
12 *
13 * If no user where logged in, it will returne the default theme
14 */
15
9class DetectActiveTheme implements DeviceDetectionInterface 16class DetectActiveTheme implements DeviceDetectionInterface
10{ 17{
11 protected $securityContext; 18 protected $securityContext;
19 protected $defaultTheme;
12 20
13 public function __construct(SecurityContextInterface $securityContext) 21 /**
22 * @param SecurityContextInterface $securityContext Needed to retrieve the current user
23 * @param string $defaultTheme Default theme when user isn't logged in
24 */
25 public function __construct(SecurityContextInterface $securityContext, $defaultTheme)
14 { 26 {
15 $this->securityContext = $securityContext; 27 $this->securityContext = $securityContext;
28 $this->defaultTheme = $defaultTheme;
16 } 29 }
17 30
18 public function setUserAgent($userAgent) 31 public function setUserAgent($userAgent)
@@ -21,9 +34,10 @@ class DetectActiveTheme implements DeviceDetectionInterface
21 34
22 /** 35 /**
23 * This should return the active theme for the logged in user. 36 * This should return the active theme for the logged in user.
24 * No active theme for: 37 *
38 * Default theme for:
25 * - anonymous user 39 * - anonymous user
26 * - user without a config (shouldn't happen..) 40 * - user without a config (shouldn't happen ..)
27 * 41 *
28 * @return string 42 * @return string
29 */ 43 */
@@ -31,15 +45,14 @@ class DetectActiveTheme implements DeviceDetectionInterface
31 { 45 {
32 $user = $this->securityContext->getToken()->getUser(); 46 $user = $this->securityContext->getToken()->getUser();
33 47
34 // anon user don't deserve a theme
35 if (!$user instanceof User) { 48 if (!$user instanceof User) {
36 return false; 49 return $this->defaultTheme;
37 } 50 }
38 51
39 $config = $user->getConfig(); 52 $config = $user->getConfig();
40 53
41 if (!$config) { 54 if (!$config) {
42 return false; 55 return $this->defaultTheme;
43 } 56 }
44 57
45 return $config->getTheme(); 58 return $config->getTheme();