]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php
Cleanup & simplify theme
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Helper / DetectActiveTheme.php
1 <?php
2
3 namespace Wallabag\CoreBundle\Helper;
4
5 use Liip\ThemeBundle\Helper\DeviceDetectionInterface;
6 use Symfony\Component\Security\Core\SecurityContextInterface;
7 use Wallabag\CoreBundle\Entity\User;
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
16 class DetectActiveTheme implements DeviceDetectionInterface
17 {
18 protected $securityContext;
19 protected $defaultTheme;
20
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)
26 {
27 $this->securityContext = $securityContext;
28 $this->defaultTheme = $defaultTheme;
29 }
30
31 public function setUserAgent($userAgent)
32 {
33 }
34
35 /**
36 * This should return the active theme for the logged in user.
37 *
38 * Default theme for:
39 * - anonymous user
40 * - user without a config (shouldn't happen ..)
41 *
42 * @return string
43 */
44 public function getType()
45 {
46 $user = $this->securityContext->getToken()->getUser();
47
48 if (!$user instanceof User) {
49 return $this->defaultTheme;
50 }
51
52 $config = $user->getConfig();
53
54 if (!$config) {
55 return $this->defaultTheme;
56 }
57
58 return $config->getTheme();
59 }
60 }