當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Url::isExternal方法代碼示例

本文整理匯總了PHP中Icinga\Web\Url::isExternal方法的典型用法代碼示例。如果您正苦於以下問題:PHP Url::isExternal方法的具體用法?PHP Url::isExternal怎麽用?PHP Url::isExternal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Icinga\Web\Url的用法示例。


在下文中一共展示了Url::isExternal方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: fromPath

 /**
  * Create a new Url class representing the given url
  *
  * If $params are given, those will be added to the urls parameters
  * and overwrite any existing parameters
  *
  * @param   string          $url        The string representation of the url to parse
  * @param   array           $params     An array of parameters that should additionally be considered for the url
  * @param   Zend_Request    $request    A request to use instead of the default one
  *
  * @return  Url
  */
 public static function fromPath($url, array $params = array(), $request = null)
 {
     if ($request === null) {
         $request = self::getRequest();
     }
     if (!is_string($url)) {
         throw new ProgrammingError('url "%s" is not a string', $url);
     }
     $urlObject = new Url();
     if ($url === '#') {
         $urlObject->setPath($url);
         return $urlObject;
     }
     $urlParts = parse_url($url);
     if (isset($urlParts['scheme']) && ($urlParts['scheme'] !== $request->getScheme() || isset($urlParts['host']) && $urlParts['host'] !== $request->getServer('SERVER_NAME') || isset($urlParts['port']) && $urlParts['port'] != $request->getServer('SERVER_PORT'))) {
         $urlObject->setIsExternal();
     }
     if (isset($urlParts['path'])) {
         $urlPath = $urlParts['path'];
         if ($urlPath && $urlPath[0] === '/') {
             if ($urlObject->isExternal() || isset($urlParts['user'])) {
                 $urlPath = substr($urlPath, 1);
             } else {
                 $requestBaseUrl = $request->getBaseUrl();
                 if ($requestBaseUrl && $requestBaseUrl !== '/' && strpos($urlPath, $requestBaseUrl) === 0) {
                     $urlPath = substr($urlPath, strlen($requestBaseUrl) + 1);
                     $urlObject->setBasePath($requestBaseUrl);
                 }
             }
         } elseif (!$urlObject->isExternal()) {
             $urlObject->setBasePath($request->getBaseUrl());
         }
         $urlObject->setPath($urlPath);
     } elseif (!$urlObject->isExternal()) {
         $urlObject->setBasePath($request->getBaseUrl());
     }
     // TODO: This has been used by former filter implementation, remove it:
     if (isset($urlParts['query'])) {
         $params = UrlParams::fromQueryString($urlParts['query'])->mergeValues($params);
     }
     if (isset($urlParts['fragment'])) {
         $urlObject->setAnchor($urlParts['fragment']);
     }
     if (isset($urlParts['user']) || $urlObject->isExternal()) {
         if (isset($urlParts['user'])) {
             $urlObject->setUsername($urlParts['user']);
         }
         if (isset($urlParts['host'])) {
             $urlObject->setHost($urlParts['host']);
         }
         if (isset($urlParts['port'])) {
             $urlObject->setPort($urlParts['port']);
         }
         if (isset($urlParts['scheme'])) {
             $urlObject->setScheme($urlParts['scheme']);
         }
         if (isset($urlParts['pass'])) {
             $urlObject->setPassword($urlParts['pass']);
         }
     }
     $urlObject->setParams($params);
     return $urlObject;
 }
開發者ID:0svald,項目名稱:icingaweb2,代碼行數:75,代碼來源:Url.php


注:本文中的Icinga\Web\Url::isExternal方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。