Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SidResolver.php
Go to the documentation of this file.
1 <?php
9 
11 
13 {
17  const XML_PATH_USE_FRONTEND_SID = 'web/session/use_frontend_sid';
18 
22  protected $scopeConfig;
23 
27  protected $urlBuilder;
28 
32  protected $request;
33 
37  protected $sidNameMap;
38 
44  protected $_useSessionVar = false;
45 
52  protected $_useSessionInUrl;
53 
57  protected $_scopeType;
58 
62  private $appState;
63 
72  public function __construct(
73  \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
74  \Magento\Framework\UrlInterface $urlBuilder,
75  \Magento\Framework\App\RequestInterface $request,
76  $scopeType,
77  array $sidNameMap = [],
78  State $appState = null
79  ) {
80  $this->scopeConfig = $scopeConfig;
81  $this->urlBuilder = $urlBuilder;
82  $this->request = $request;
83  $this->sidNameMap = $sidNameMap;
84  $this->_scopeType = $scopeType;
85  $this->appState = $appState ?: \Magento\Framework\App\ObjectManager::getInstance()->get(State::class);
86  }
87 
93  {
94  if ($this->appState->getAreaCode() !== \Magento\Framework\App\Area::AREA_FRONTEND) {
95  return null;
96  }
97 
98  $sidKey = null;
99 
100  $useSidOnFrontend = $this->getUseSessionInUrl();
101  if ($useSidOnFrontend && $this->request->getQuery(
102  $this->getSessionIdQueryParam($session),
103  false
104  ) && $this->urlBuilder->isOwnOriginUrl()
105  ) {
106  $sidKey = $this->request->getQuery($this->getSessionIdQueryParam($session));
107  }
108  return $sidKey;
109  }
110 
118  {
119  $sessionName = $session->getName();
120  if ($sessionName && isset($this->sidNameMap[$sessionName])) {
121  return $this->sidNameMap[$sessionName];
122  }
124  }
125 
132  public function setUseSessionVar($var)
133  {
134  $this->_useSessionVar = (bool)$var;
135  return $this;
136  }
137 
144  public function getUseSessionVar()
145  {
146  return $this->_useSessionVar;
147  }
148 
155  public function setUseSessionInUrl($flag = true)
156  {
157  $this->_useSessionInUrl = (bool)$flag;
158  return $this;
159  }
160 
167  public function getUseSessionInUrl()
168  {
169  if ($this->_useSessionInUrl === null) {
170  //Using config value by default, can be overridden by using the
171  //setter.
172  $this->_useSessionInUrl = (bool)$this->scopeConfig->getValue(
173  self::XML_PATH_USE_FRONTEND_SID,
174  $this->_scopeType
175  );
176  }
177 
179  }
180 }
return false
Definition: gallery.phtml:36
getSessionIdQueryParam(SessionManagerInterface $session)
getSid(SessionManagerInterface $session)
Definition: SidResolver.php:92
__construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\UrlInterface $urlBuilder, \Magento\Framework\App\RequestInterface $request, $scopeType, array $sidNameMap=[], State $appState=null)
Definition: SidResolver.php:72