/** * Get Backend app based on its name * * @return BackendApp|null */ public function getCurrentApp() { $appName = $this->request->getQuery('app'); if ($appName && isset($this->backendApps[$appName])) { return $this->backendApps[$appName]; } }
/** * @param SessionManagerInterface $session * @return string */ public function getSid(SessionManagerInterface $session) { $sidKey = null; $useSidOnFrontend = $this->scopeConfig->getValue(self::XML_PATH_USE_FRONTEND_SID, $this->_scopeType); if ($useSidOnFrontend && $this->request->getQuery($this->getSessionIdQueryParam($session), false) && $this->urlBuilder->isOwnOriginUrl()) { $sidKey = $this->request->getQuery($this->getSessionIdQueryParam($session)); } return $sidKey; }
/** * @param mixed $sid * @param bool $useFrontedSid * @param bool $isOwnOriginUrl * @param mixed $testSid * @dataProvider dataProviderTestGetSid */ public function testGetSid($sid, $useFrontedSid, $isOwnOriginUrl, $testSid) { $this->scopeConfig->expects($this->any())->method('getValue')->with(\Magento\Framework\Session\SidResolver::XML_PATH_USE_FRONTEND_SID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)->will($this->returnValue($useFrontedSid)); $this->urlBuilder->expects($this->any())->method('isOwnOriginUrl')->will($this->returnValue($isOwnOriginUrl)); if ($testSid) { $this->request->getQuery()->set($this->model->getSessionIdQueryParam($this->session), $testSid); } $this->assertEquals($sid, $this->model->getSid($this->session)); }
/** * {@inheritdoc} * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function setRouteParams(array $data, $unsetOldParams = true) { if (isset($data['_type'])) { $this->setType($data['_type']); unset($data['_type']); } if (isset($data['_forced_secure'])) { $this->setSecure((bool) $data['_forced_secure']); $this->setSecureIsForced(true); unset($data['_forced_secure']); } elseif (isset($data['_secure'])) { $this->setSecure((bool) $data['_secure']); unset($data['_secure']); } if (isset($data['_absolute'])) { unset($data['_absolute']); } if ($unsetOldParams) { $this->unsetData('route_params'); } if (isset($data['_current'])) { if (is_array($data['_current'])) { foreach ($data['_current'] as $key) { if (array_key_exists($key, $data) || !$this->request->getUserParam($key)) { continue; } $data[$key] = $this->request->getUserParam($key); } } elseif ($data['_current']) { foreach ($this->request->getUserParams() as $key => $value) { if (array_key_exists($key, $data) || $this->getRouteParam($key)) { continue; } $data[$key] = $value; } foreach ($this->request->getQuery() as $key => $value) { $this->queryParamsResolver->setQueryParam($key, $value); } } unset($data['_current']); } if (isset($data['_use_rewrite'])) { unset($data['_use_rewrite']); } foreach ($data as $key => $value) { $this->setRouteParam($key, $value); } return $this; }
/** * {@inheritdoc} */ public function setRouteParams(array $data, $unsetOldParams = true) { if (isset($data['_type'])) { $this->setType($data['_type']); unset($data['_type']); } if (isset($data['_scope'])) { $this->setScope($data['_scope']); unset($data['_scope']); } if (isset($data['_forced_secure'])) { $this->setSecure((bool) $data['_forced_secure']); $this->setSecureIsForced(true); unset($data['_forced_secure']); } elseif (isset($data['_secure'])) { $this->setSecure((bool) $data['_secure']); unset($data['_secure']); } if (isset($data['_absolute'])) { unset($data['_absolute']); } if ($unsetOldParams) { $this->unsetData('route_params'); } if (isset($data['_current'])) { if (is_array($data['_current'])) { foreach ($data['_current'] as $key) { if (array_key_exists($key, $data) || !$this->_request->getUserParam($key)) { continue; } $data[$key] = $this->_request->getUserParam($key); } } elseif ($data['_current']) { foreach ($this->_request->getUserParams() as $key => $value) { if (array_key_exists($key, $data) || $this->getRouteParam($key)) { continue; } $data[$key] = $value; } foreach ($this->_request->getQuery() as $key => $value) { $this->_queryParamsResolver->setQueryParam($key, $value); } } unset($data['_current']); } if (isset($data['_use_rewrite'])) { unset($data['_use_rewrite']); } if (isset($data['_scope_to_url']) && (bool) $data['_scope_to_url'] === true) { $store = $this->getScope() ?: $this->_storeManager->getStore(); if (!$this->_scopeConfig->getValue(\Magento\Store\Model\Store::XML_PATH_STORE_IN_URL, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $this->getScope()) && !$this->_storeManager->hasSingleStore()) { $this->_queryParamsResolver->setQueryParam('___store', $store->getCode()); } } unset($data['_scope_to_url']); foreach ($data as $key => $value) { $this->setRouteParam($key, $value); } return $this; }
/** * Retrieve current url for store * * @param bool|string $fromStore * @return string */ public function getCurrentUrl($fromStore = true) { $sidQueryParam = $this->_sidResolver->getSessionIdQueryParam($this->_getSession()); $requestString = $this->_url->escape(ltrim($this->_request->getRequestString(), '/')); $storeUrl = $this->_storeManager->getStore()->isCurrentlySecure() ? $this->getUrl('', array('_secure' => true)) : $this->getUrl(''); if (!filter_var($storeUrl, FILTER_VALIDATE_URL)) { return $storeUrl; } $storeParsedUrl = parse_url($storeUrl); $storeParsedQuery = array(); if (isset($storeParsedUrl['query'])) { parse_str($storeParsedUrl['query'], $storeParsedQuery); } $currQuery = $this->_request->getQuery(); 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; } return $storeParsedUrl['scheme'] . '://' . $storeParsedUrl['host'] . (isset($storeParsedUrl['port']) ? ':' . $storeParsedUrl['port'] : '') . $storeParsedUrl['path'] . $requestString . ($storeParsedQuery ? '?' . http_build_query($storeParsedQuery, '', '&') : ''); }
public function testGetScriptOptions() { $this->request->getQuery()->set('getparameter', 1); $this->assertContains('?getparameter=1', $this->javascript->getScriptOptions()); }