本文整理汇总了PHP中Pimcore\Tool::getRequestScheme方法的典型用法代码示例。如果您正苦于以下问题:PHP Tool::getRequestScheme方法的具体用法?PHP Tool::getRequestScheme怎么用?PHP Tool::getRequestScheme使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pimcore\Tool
的用法示例。
在下文中一共展示了Tool::getRequestScheme方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkForRedirect
/**
* Checks for a suitable redirect
* @throws Exception
* @param bool $override
* @return void
*/
protected function checkForRedirect($override = false)
{
// not for admin requests
if (Tool::isFrontentRequestByAdmin()) {
return;
}
try {
$front = \Zend_Controller_Front::getInstance();
$config = Config::getSystemConfig();
// get current site if available
$sourceSite = null;
if (Site::isSiteRequest()) {
$sourceSite = Site::getCurrentSite();
}
$cacheKey = "system_route_redirect";
if (empty($this->redirects) && !($this->redirects = Cache::load($cacheKey))) {
$list = new Redirect\Listing();
$list->setCondition("active = 1");
$list->setOrder("DESC");
$list->setOrderKey("priority");
$this->redirects = $list->load();
Cache::save($this->redirects, $cacheKey, ["system", "redirect", "route"], null, 998);
}
$requestScheme = Tool::getRequestScheme();
$matchRequestUri = $_SERVER["REQUEST_URI"];
$matchUrl = Tool::getHostUrl() . $matchRequestUri;
foreach ($this->redirects as $redirect) {
$matchAgainst = $matchRequestUri;
if ($redirect->getSourceEntireUrl()) {
$matchAgainst = $matchUrl;
}
// if override is true the priority has to be 99 which means that overriding is ok
if (!$override || $override && $redirect->getPriority() == 99) {
if (@preg_match($redirect->getSource(), $matchAgainst, $matches)) {
// check for a site
if ($sourceSite) {
if ($sourceSite->getId() != $redirect->getSourceSite()) {
continue;
}
}
array_shift($matches);
$target = $redirect->getTarget();
if (is_numeric($target)) {
$d = Document::getById($target);
if ($d instanceof Document\Page || $d instanceof Document\Link || $d instanceof Document\Hardlink) {
$target = $d->getFullPath();
} else {
\Logger::error("Target of redirect no found (Document-ID: " . $target . ")!");
continue;
}
}
// support for pcre backreferences
$url = replace_pcre_backreferences($target, $matches);
if ($redirect->getTargetSite() && !preg_match("@http(s)?://@i", $url)) {
try {
$targetSite = Site::getById($redirect->getTargetSite());
// if the target site is specified and and the target-path is starting at root (not absolute to site)
// the root-path will be replaced so that the page can be shown
$url = preg_replace("@^" . $targetSite->getRootPath() . "/@", "/", $url);
$url = $requestScheme . "://" . $targetSite->getMainDomain() . $url;
} catch (\Exception $e) {
\Logger::error("Site with ID " . $redirect->getTargetSite() . " not found.");
continue;
}
} elseif (!preg_match("@http(s)?://@i", $url) && $config->general->domain && $redirect->getSourceEntireUrl()) {
// prepend the host and scheme to avoid infinite loops when using "domain" redirects
$url = ($front->getRequest()->isSecure() ? "https" : "http") . "://" . $config->general->domain . $url;
}
// pass-through parameters if specified
$queryString = $_SERVER["QUERY_STRING"];
if ($redirect->getPassThroughParameters() && !empty($queryString)) {
$glue = "?";
if (strpos($url, "?")) {
$glue = "&";
}
$url .= $glue;
$url .= $queryString;
}
header($redirect->getHttpStatus());
header("Location: " . $url, true, $redirect->getStatusCode());
// log all redirects to the redirect log
\Pimcore\Log\Simple::log("redirect", Tool::getAnonymizedClientIp() . " \t Custom-Redirect ID: " . $redirect->getId() . " , Source: " . $_SERVER["REQUEST_URI"] . " -> " . $url);
exit;
}
}
}
} catch (\Exception $e) {
// no suitable route found
}
}