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