]>
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 | ||
9 | class DetectActiveTheme implements DeviceDetectionInterface | |
10 | { | |
11 | protected $securityContext; | |
12 | ||
13 | public function __construct(SecurityContextInterface $securityContext) | |
14 | { | |
15 | $this->securityContext = $securityContext; | |
16 | } | |
17 | ||
18 | public function setUserAgent($userAgent) | |
19 | { | |
20 | } | |
21 | ||
22 | /** | |
23 | * This should return the active theme for the logged in user. | |
24 | * No active theme for: | |
25 | * - anonymous user | |
26 | * - user without a config (shouldn't happen..) | |
27 | * | |
28 | * @return string | |
29 | */ | |
30 | public function getType() | |
31 | { | |
32 | $user = $this->securityContext->getToken()->getUser(); | |
33 | ||
34 | // anon user don't deserve a theme | |
35 | if (!$user instanceof User) { | |
36 | return false; | |
37 | } | |
38 | ||
39 | $config = $user->getConfig(); | |
40 | ||
41 | if (!$config) { | |
42 | return false; | |
43 | } | |
44 | ||
45 | return $config->getTheme(); | |
46 | } | |
47 | } |