/** * @magentoConfigFixture current_store web/session/use_frontend_sid 1 */ public function testSetSessionIdFromParam() { $this->assertNotEquals('test_id', $this->_model->getSessionId()); $_GET[$this->_sidResolver->getSessionIdQueryParam($this->_model)] = 'test-id'; $this->_model->setSessionId($this->_sidResolver->getSid($this->_model)); $this->assertEquals('test-id', $this->_model->getSessionId()); /* Use not valid identifier */ $_GET[$this->_sidResolver->getSessionIdQueryParam($this->_model)] = 'test_id'; $this->_model->setSessionId($this->_sidResolver->getSid($this->_model)); $this->assertEquals('test-id', $this->_model->getSessionId()); }
/** * {@inheritdoc} * * @param array $arguments * @return array */ public function updatePathParams(array $arguments) { if ($this->_session->getCookieShouldBeReceived() && $this->_sidResolver->getUseSessionInUrl() && $this->_canUseSessionIdInParam) { $arguments += ['_query' => [$this->_sidResolver->getSessionIdQueryParam($this->_session) => $this->_session->getSessionId()]]; } return $arguments; }
/** * Set redirect into response * * @param \Magento\Framework\App\ResponseInterface $response * @param string $path * @param array $arguments * @return void */ public function redirect(\Magento\Framework\App\ResponseInterface $response, $path, $arguments = array()) { if ($this->_session->getCookieShouldBeReceived() && $this->_urlBuilder->getUseSession() && $this->_canUseSessionIdInParam) { $arguments += array('_query' => array($this->_sidResolver->getSessionIdQueryParam($this->_session) => $this->_session->getSessionId())); } $response->setRedirect($this->_urlBuilder->getUrl($path, $arguments)); }
/** * Save block content to cache storage * * @param string $data * @return $this */ protected function _saveCache($data) { if ($this->getCacheLifetime() === null || !$this->_cacheState->isEnabled(self::CACHE_GROUP)) { return false; } $cacheKey = $this->getCacheKey(); $data = str_replace($this->_sidResolver->getSessionIdQueryParam($this->_session) . '=' . $this->_session->getSessionId(), $this->_getSidPlaceholder($cacheKey), $data); $this->_cache->save($data, $cacheKey, $this->getCacheTags(), $this->getCacheLifetime()); return $this; }
/** * Replace Session ID value in URL * * @param string $html * @return string */ public function sessionUrlVar($html) { return preg_replace_callback( '#(\?|&|&)___SID=([SU])(&|&)?#', // @codingStandardsIgnoreStart /** * Callback function for session replace * * @param array $match * @return string */ // @codingStandardsIgnoreEnd function ($match) { if ($this->useSessionIdForUrl($match[2] == 'S' ? true : false)) { return $match[1] . $this->_sidResolver->getSessionIdQueryParam($this->_session) . '=' . $this->_session->getSessionId() . (isset($match[3]) ? $match[3] : ''); } else { if ($match[1] == '?') { return isset($match[3]) ? '?' : ''; } elseif ($match[1] == '&' || $match[1] == '&') { return isset($match[3]) ? $match[3] : ''; } } }, $html ); }
/** * Retrieve current url for store * * @param bool|string $fromStore * @return string * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function getCurrentUrl($fromStore = true) { $sidQueryParam = $this->_sidResolver->getSessionIdQueryParam($this->_getSession()); $requestString = $this->_url->escape(ltrim($this->_request->getRequestString(), '/')); $storeUrl = $this->getUrl('', ['_secure' => $this->_storeManager->getStore()->isCurrentlySecure()]); if (!filter_var($storeUrl, FILTER_VALIDATE_URL)) { return $storeUrl; } $storeParsedUrl = parse_url($storeUrl); $storeParsedQuery = []; if (isset($storeParsedUrl['query'])) { parse_str($storeParsedUrl['query'], $storeParsedQuery); } $currQuery = $this->_request->getQueryValue(); if (isset($currQuery[$sidQueryParam]) && !empty($currQuery[$sidQueryParam]) && $this->_getSession()->getSessionIdForHost($storeUrl) != $currQuery[$sidQueryParam]) { unset($currQuery[$sidQueryParam]); } foreach ($currQuery as $key => $value) { $storeParsedQuery[$key] = $value; } if (!$this->isUseStoreInUrl()) { $storeParsedQuery['___store'] = $this->getCode(); } if ($fromStore !== false) { $storeParsedQuery['___from_store'] = $fromStore === true ? $this->_storeManager->getStore()->getCode() : $fromStore; } $currentUrl = $storeParsedUrl['scheme'] . '://' . $storeParsedUrl['host'] . (isset($storeParsedUrl['port']) ? ':' . $storeParsedUrl['port'] : '') . $storeParsedUrl['path'] . $requestString . ($storeParsedQuery ? '?' . http_build_query($storeParsedQuery, '', '&') : ''); return $currentUrl; }
/** * Replace Session ID value in URL * * @param string $html * @return string */ public function sessionUrlVar($html) { return preg_replace_callback('#(\\?|&|&)___SID=([SU])(&|&)?#', function ($match) { if ($this->useSessionIdForUrl($match[2] == 'S' ? true : false)) { return $match[1] . $this->_sidResolver->getSessionIdQueryParam($this->_session) . '=' . $this->_session->getSessionId() . (isset($match[3]) ? $match[3] : ''); } else { if ($match[1] == '?') { return isset($match[3]) ? '?' : ''; } elseif ($match[1] == '&' || $match[1] == '&') { return isset($match[3]) ? $match[3] : ''; } } }, $html); }