当前位置: 首页>>代码示例>>PHP>>正文


PHP Url::setHost方法代码示例

本文整理汇总了PHP中Icinga\Web\Url::setHost方法的典型用法代码示例。如果您正苦于以下问题:PHP Url::setHost方法的具体用法?PHP Url::setHost怎么用?PHP Url::setHost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Icinga\Web\Url的用法示例。


在下文中一共展示了Url::setHost方法的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::setHost方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。