]> git.immae.eu Git - github/wallabag/wallabag.git/blame_incremental - src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php
Merge pull request #2506 from wallabag/fix-export-with-tags
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Helper / DetectActiveTheme.php
... / ...
CommitLineData
1<?php
2
3namespace Wallabag\CoreBundle\Helper;
4
5use Liip\ThemeBundle\Helper\DeviceDetectionInterface;
6use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
7use Wallabag\UserBundle\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 */
15class DetectActiveTheme implements DeviceDetectionInterface
16{
17 protected $tokenStorage;
18 protected $defaultTheme;
19
20 /**
21 * @param TokenStorageInterface $tokenStorage Needed to retrieve the current user
22 * @param string $defaultTheme Default theme when user isn't logged in
23 */
24 public function __construct(TokenStorageInterface $tokenStorage, $defaultTheme)
25 {
26 $this->tokenStorage = $tokenStorage;
27 $this->defaultTheme = $defaultTheme;
28 }
29
30 public function setUserAgent($userAgent)
31 {
32 }
33
34 /**
35 * This should return the active theme for the logged in user.
36 *
37 * Default theme for:
38 * - anonymous user
39 * - user without a config (shouldn't happen ..)
40 *
41 * @return string
42 */
43 public function getType()
44 {
45 $token = $this->tokenStorage->getToken();
46
47 if (is_null($token)) {
48 return $this->defaultTheme;
49 }
50
51 $user = $token->getUser();
52
53 if (!$user instanceof User) {
54 return $this->defaultTheme;
55 }
56
57 $config = $user->getConfig();
58
59 if (!$config) {
60 return $this->defaultTheme;
61 }
62
63 return $config->getTheme();
64 }
65}