for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\AdminBundle\Context;
use Sylius\Component\Core\Model\AdminUserInterface;
use Sylius\Component\Locale\Context\LocaleContextInterface;
use Sylius\Component\Locale\Context\LocaleNotFoundException;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
/**
* @author Jan Góralski <[email protected]>
final class AdminBasedLocaleContext implements LocaleContextInterface
{
* @var TokenStorageInterface
private $tokenStorage;
* @param TokenStorageInterface $tokenStorage
public function __construct(TokenStorageInterface $tokenStorage)
$this->tokenStorage = $tokenStorage;
}
* {@inheritdoc}
public function getLocaleCode()
$token = $this->tokenStorage->getToken();
if (null === $token) {
throw new LocaleNotFoundException();
$user = $token->getUser();
if (!$user instanceof AdminUserInterface) {
return $user->getLocaleCode();