Total Complexity | 4 |
Total Lines | 28 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
25 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
||
26 | |||
27 | final readonly class LocaleProviderService implements StepupLocaleProviderService |
||
28 | { |
||
29 | public function __construct(private TokenStorageInterface $tokenStorage) |
||
30 | { |
||
31 | } |
||
32 | |||
33 | public function determinePreferredLocale() |
||
34 | { |
||
35 | $token = $this->tokenStorage->getToken(); |
||
36 | |||
37 | if (!$token instanceof \Symfony\Component\Security\Core\Authentication\Token\TokenInterface) { |
||
38 | return; |
||
39 | } |
||
40 | |||
41 | /** @var Identity $identity */ |
||
42 | $identity = $token->getUser(); |
||
43 | |||
44 | if (!$identity instanceof Identity) { |
||
45 | return; |
||
46 | } |
||
47 | |||
48 | return $identity->preferredLocale; |
||
49 | } |
||
50 | } |
||
51 |