]>
Commit | Line | Data |
---|---|---|
32da2a70 J |
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 | ||
495aecfe J |
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 | ||
32da2a70 J |
16 | class DetectActiveTheme implements DeviceDetectionInterface |
17 | { | |
18 | protected $securityContext; | |
495aecfe | 19 | protected $defaultTheme; |
32da2a70 | 20 | |
495aecfe J |
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) | |
32da2a70 J |
26 | { |
27 | $this->securityContext = $securityContext; | |
495aecfe | 28 | $this->defaultTheme = $defaultTheme; |
32da2a70 J |
29 | } |
30 | ||
31 | public function setUserAgent($userAgent) | |
32 | { | |
33 | } | |
34 | ||
35 | /** | |
36 | * This should return the active theme for the logged in user. | |
495aecfe J |
37 | * |
38 | * Default theme for: | |
32da2a70 | 39 | * - anonymous user |
495aecfe | 40 | * - user without a config (shouldn't happen ..) |
32da2a70 J |
41 | * |
42 | * @return string | |
43 | */ | |
44 | public function getType() | |
45 | { | |
46 | $user = $this->securityContext->getToken()->getUser(); | |
47 | ||
32da2a70 | 48 | if (!$user instanceof User) { |
495aecfe | 49 | return $this->defaultTheme; |
32da2a70 J |
50 | } |
51 | ||
52 | $config = $user->getConfig(); | |
53 | ||
54 | if (!$config) { | |
495aecfe | 55 | return $this->defaultTheme; |
32da2a70 J |
56 | } |
57 | ||
58 | return $config->getTheme(); | |
59 | } | |
60 | } |