Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Resolver.php
Go to the documentation of this file.
1 <?php
7 
14 {
18  protected $_session;
19 
23  protected $_localeManager;
24 
28  protected $_request;
29 
33  protected $_localeValidator;
34 
46  public function __construct(
47  \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
48  $defaultLocalePath,
49  $scopeType,
50  \Magento\Backend\Model\Session $session,
51  \Magento\Backend\Model\Locale\Manager $localeManager,
53  \Magento\Framework\Validator\Locale $localeValidator,
54  $locale = null
55  ) {
56  $this->_session = $session;
57  $this->_localeManager = $localeManager;
58  $this->_request = $request;
59  $this->_localeValidator = $localeValidator;
60  parent::__construct($scopeConfig, $defaultLocalePath, $scopeType, $locale);
61  }
62 
69  public function setLocale($locale = null)
70  {
71  $forceLocale = $this->_request->getParam('locale', null);
72  if (!$this->_localeValidator->isValid($forceLocale)) {
73  $forceLocale = false;
74  }
75 
76  $sessionLocale = $this->_session->getSessionLocale();
77  $userLocale = $this->_localeManager->getUserInterfaceLocale();
78 
79  $localeCodes = array_filter([$forceLocale, $sessionLocale, $userLocale]);
80 
81  if (count($localeCodes)) {
82  $locale = reset($localeCodes);
83  }
84 
85  return parent::setLocale($locale);
86  }
87 }
__construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, $defaultLocalePath, $scopeType, \Magento\Backend\Model\Session $session, \Magento\Backend\Model\Locale\Manager $localeManager, \Magento\Framework\App\RequestInterface $request, \Magento\Framework\Validator\Locale $localeValidator, $locale=null)
Definition: Resolver.php:46