本文整理汇总了PHP中Magento\Framework\App\RequestInterface::getBaseUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::getBaseUrl方法的具体用法?PHP RequestInterface::getBaseUrl怎么用?PHP RequestInterface::getBaseUrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\App\RequestInterface
的用法示例。
在下文中一共展示了RequestInterface::getBaseUrl方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: rewrite
/**
* Perform custom url rewrites
*
* @param \Magento\Framework\App\RequestInterface $request
* @return bool
*/
public function rewrite(\Magento\Framework\App\RequestInterface $request = null)
{
if (!$this->_appState->isInstalled()) {
return false;
}
if (is_null($this->getStoreId()) || false === $this->getStoreId()) {
$this->setStoreId($this->_storeManager->getStore()->getId());
}
/**
* We have two cases of incoming paths - with and without slashes at the end ("/somepath/" and "/somepath").
* Each of them matches two url rewrite request paths - with and without slashes at the end
* ("/somepath/" and "/somepath").
* Choose any matched rewrite, but in priority order that depends on same presence of slash and query params.
*/
$requestCases = array();
$pathInfo = $request->getPathInfo();
$origSlash = substr($pathInfo, -1) == '/' ? '/' : '';
$requestPath = trim($pathInfo, '/');
// If there were final slash - add nothing to less priority paths. And vice versa.
$altSlash = $origSlash ? '' : '/';
$queryString = $this->_getQueryString();
// Query params in request, matching "path + query" has more priority
if ($queryString) {
$requestCases[] = $requestPath . $origSlash . '?' . $queryString;
$requestCases[] = $requestPath . $altSlash . '?' . $queryString;
}
$requestCases[] = $requestPath . $origSlash;
$requestCases[] = $requestPath . $altSlash;
$this->loadByRequestPath($requestCases);
$targetUrl = $request->getBaseUrl();
/**
* Try to find rewrite by request path at first, if no luck - try to find by id_path
*/
if (!$this->getId() && isset($_GET['___from_store'])) {
try {
$fromStoreId = $this->_storeManager->getStore($_GET['___from_store'])->getId();
} catch (\Exception $e) {
return false;
}
$this->setStoreId($fromStoreId)->loadByRequestPath($requestCases);
if (!$this->getId()) {
return false;
}
$currentStore = $this->_storeManager->getStore();
$this->setStoreId($currentStore->getId())->loadByIdPath($this->getIdPath());
$cookieMetadata = $this->_cookieMetadataFactory->createPublicCookieMetadata()->setDurationOneYear();
$this->_cookieManager->setPublicCookie(\Magento\Store\Model\Store::COOKIE_NAME, $currentStore->getCode(), $cookieMetadata);
$targetUrl .= '/' . $this->getRequestPath();
$this->_sendRedirectHeaders($targetUrl, true);
}
if (!$this->getId()) {
return false;
}
$request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $this->getRequestPath());
$external = substr($this->getTargetPath(), 0, 6);
$isPermanentRedirectOption = $this->hasOption('RP');
if ($external === 'http:/' || $external === 'https:') {
$destinationStoreCode = $this->_storeManager->getStore($this->getStoreId())->getCode();
$cookieMetadata = $this->_cookieMetadataFactory->createPublicCookieMetadata()->setDurationOneYear();
$this->_cookieManager->setPublicCookie(\Magento\Store\Model\Store::COOKIE_NAME, $destinationStoreCode, $cookieMetadata);
$this->_sendRedirectHeaders($this->getTargetPath(), $isPermanentRedirectOption);
} else {
$targetUrl .= '/' . $this->getTargetPath();
}
$isRedirectOption = $this->hasOption('R');
$isStoreInUrl = $this->_scopeConfig->getValue(\Magento\Store\Model\Store::XML_PATH_STORE_IN_URL, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
if ($isRedirectOption || $isPermanentRedirectOption) {
if ($isStoreInUrl && ($storeCode = $this->_storeManager->getStore()->getCode())) {
$targetUrl .= '/' . $storeCode . '/' . $this->getTargetPath();
}
$this->_sendRedirectHeaders($targetUrl, $isPermanentRedirectOption);
}
if ($isStoreInUrl && ($storeCode = $this->_storeManager->getStore()->getCode())) {
$targetUrl .= '/' . $storeCode . '/' . $this->getTargetPath();
}
$queryString = $this->_getQueryString();
if ($queryString) {
$targetUrl .= '?' . $queryString;
}
$request->setRequestUri($targetUrl);
$request->setPathInfo($this->getTargetPath());
return true;
}