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


PHP Url::getHost方法代码示例

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


在下文中一共展示了Url::getHost方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sendBackgroundGetRequest

 /**
  * Funkce pro odeslání GET požadavku bez čekání na získání odpovědi
  * @param string $url
  * @throws \Exception
  */
 public static function sendBackgroundGetRequest($url)
 {
     $url = new Url($url);
     $host = $url->getHost();
     if (empty($host)) {
         $host = 'localhost';
     }
     #region parametry připojení
     switch ($url->getScheme()) {
         case 'https':
             $scheme = 'ssl://';
             $port = 443;
             break;
         case 'http':
         default:
             $scheme = '';
             $port = 80;
     }
     $urlPort = $url->getPort();
     if (!empty($urlPort)) {
         $port = $urlPort;
     }
     #endregion
     $fp = @fsockopen($scheme . $host, $port, $errno, $errstr, self::REQUEST_TIMEOUT);
     if (!$fp) {
         Debugger::log($errstr, ILogger::ERROR);
         throw new \Exception($errstr, $errno);
     }
     $path = $url->getPath() . ($url->getQuery() != "" ? '?' . $url->getQuery() : '');
     fputs($fp, "GET " . $path . " HTTP/1.0\r\nHost: " . $host . "\r\n\r\n");
     fputs($fp, "Connection: close\r\n");
     fputs($fp, "\r\n");
 }
开发者ID:kizi,项目名称:easyminer-easyminercenter,代码行数:38,代码来源:RequestHelper.php

示例2: process

 private function process($url, string $directory, string $parameter, array &$dependencies = []) : string
 {
     $url = new Nette\Http\Url($url);
     $time = NULL;
     if ($url->getHost() && (!$this->request || $url->getHost() !== $this->request->getUrl()->getHost())) {
         $headers = @get_headers($url, TRUE);
         if (is_array($headers) && isset($headers['Last-Modified'])) {
             $time = (new DateTime($headers['Last-Modified']))->getTimestamp();
         }
     } elseif (is_file($filename = implode(DIRECTORY_SEPARATOR, [rtrim($directory, '\\/'), ltrim($url->getPath(), '\\/')]))) {
         $time = filemtime($filename);
         unset($dependencies[Nette\Caching\Cache::EXPIRE]);
         $dependencies[Nette\Caching\Cache::FILES] = $filename;
     }
     $url->setQueryParameter($parameter, $time ?: ($this->time ?: ($this->time = time())));
     return preg_replace($pattern = '#^(\\+|/+)#', preg_match($pattern, $url->getPath()) ? DIRECTORY_SEPARATOR : NULL, $url);
 }
开发者ID:vitkutny,项目名称:version,代码行数:17,代码来源:Filter.php

示例3: createComponentPlayer

 public function createComponentPlayer()
 {
     $host = explode(".", $this->playUrl->getHost());
     $provider = Nette\Utils\Strings::lower($host[count($host) - 2]);
     $handler = "\\App\\Controls\\" . ucfirst($provider) . "Player";
     if (class_exists($handler)) {
         $player = new $handler($this->playUrl);
     } else {
         $player = new \App\Controls\NoPlayer($this->playUrl);
     }
     return $player;
 }
开发者ID:sg3tester,项目名称:songator,代码行数:12,代码来源:SongPresenter.php

示例4: replaceJsonVariables

 /**
  * Funkce pro doplnění základních parametrů do API
  * @param string $jsonString
  * @return string
  */
 private function replaceJsonVariables($jsonString)
 {
     $link = $this->link('//Default:default');
     $url = new Url($link);
     if (empty($url->host)) {
         $url = $this->getHttpRequest()->getUrl()->hostUrl;
         if (Strings::endsWith($url, '/')) {
             rtrim($url, '/');
         }
         $url .= $link;
         $url = new Url($url);
     }
     $hostUrl = Strings::endsWith($url->getHost(), '/') ? rtrim($url->getHost(), '/') : $url->getHost();
     $basePath = rtrim($url->getBasePath(), '/');
     $paramsArr = ['%VERSION%' => $this->getInstallVersion(), '%BASE_PATH%' => $basePath, '%HOST%' => $hostUrl];
     $arrSearch = [];
     $arrReplace = [];
     foreach ($paramsArr as $key => $value) {
         $arrSearch[] = $key;
         $arrReplace[] = $value;
     }
     return str_replace($arrSearch, $arrReplace, $jsonString);
 }
开发者ID:kizi,项目名称:easyminer-easyminercenter,代码行数:28,代码来源:SwaggerPresenter.php

示例5: constructUrl


//.........这里部分代码省略.........
             if (is_scalar($params[$name]) ? strcasecmp($params[$name], $meta[self::VALUE]) === 0 : $params[$name] === $meta[self::VALUE]) {
                 // remove default values; NULL values are retain
                 unset($params[$name]);
                 continue;
             } elseif ($meta['fixity'] === self::CONSTANT) {
                 return NULL;
                 // missing or wrong parameter '$name'
             }
         }
         if (is_scalar($params[$name]) && isset($meta['filterTable2'][$params[$name]])) {
             $params[$name] = $meta['filterTable2'][$params[$name]];
         } elseif (isset($meta['filterTable2']) && !empty($meta[self::FILTER_STRICT])) {
             return NULL;
         } elseif (isset($meta[self::FILTER_OUT])) {
             $params[$name] = call_user_func($meta[self::FILTER_OUT], $params[$name]);
         }
         if (isset($meta[self::PATTERN]) && !preg_match($meta[self::PATTERN], rawurldecode($params[$name]))) {
             return NULL;
             // pattern not match
         }
     }
     // compositing path
     $sequence = $this->sequence;
     $brackets = array();
     $required = NULL;
     // NULL for auto-optional
     $url = '';
     $i = count($sequence) - 1;
     do {
         $url = $sequence[$i] . $url;
         if ($i === 0) {
             break;
         }
         $i--;
         $name = $sequence[$i];
         $i--;
         // parameter name
         if ($name === ']') {
             // opening optional part
             $brackets[] = $url;
         } elseif ($name[0] === '[') {
             // closing optional part
             $tmp = array_pop($brackets);
             if ($required < count($brackets) + 1) {
                 // is this level optional?
                 if ($name !== '[!') {
                     // and not "required"-optional
                     $url = $tmp;
                 }
             } else {
                 $required = count($brackets);
             }
         } elseif ($name[0] === '?') {
             // "foo" parameter
             continue;
         } elseif (isset($params[$name]) && $params[$name] != '') {
             // intentionally ==
             $required = count($brackets);
             // make this level required
             $url = $params[$name] . $url;
             unset($params[$name]);
         } elseif (isset($metadata[$name]['fixity'])) {
             // has default value?
             if ($required === NULL && !$brackets) {
                 // auto-optional
                 $url = '';
             } else {
                 $url = $metadata[$name]['defOut'] . $url;
             }
         } else {
             return NULL;
             // missing parameter '$name'
         }
     } while (TRUE);
     // absolutize path
     if ($this->type === self::RELATIVE) {
         $url = '//' . $refUrl->getAuthority() . $refUrl->getBasePath() . $url;
     } elseif ($this->type === self::PATH) {
         $url = '//' . $refUrl->getAuthority() . $url;
     } else {
         $host = $refUrl->getHost();
         $host = ip2long($host) ? array($host) : array_reverse(explode('.', $host));
         $url = strtr($url, array('/%basePath%/' => $refUrl->getBasePath(), '%tld%' => $host[0], '%domain%' => isset($host[1]) ? "{$host['1']}.{$host['0']}" : $host[0]));
     }
     if (strpos($url, '//', 2) !== FALSE) {
         return NULL;
     }
     $url = ($this->flags & self::SECURED ? 'https:' : 'http:') . $url;
     // build query string
     if ($this->xlat) {
         $params = self::renameKeys($params, $this->xlat);
     }
     $sep = ini_get('arg_separator.input');
     $query = http_build_query($params, '', $sep ? $sep[0] : '&');
     if ($query != '') {
         // intentionally ==
         $url .= '?' . $query;
     }
     return $url;
 }
开发者ID:eduardobenito10,项目名称:jenkins-php-quickstart,代码行数:101,代码来源:Route.php

示例6: constructUrl

 /**
  * @param Request $appRequest
  * @param Url $refUrl
  * @return null|string
  */
 public function constructUrl(Request $appRequest, Url $refUrl)
 {
     // one way can't generate link
     if ($this->options['oneWay']) {
         return NULL;
     }
     $params = $this->clearParameters($appRequest->getParameters());
     $action = new Action($appRequest->getPresenterName() . ':' . $appRequest->getParameter('action'), $params);
     // ISource return NULL, not found url to generate
     if (($seoUrl = $this->source->toUrl($action)) === NULL) {
         return NULL;
     }
     if (!$seoUrl instanceof Url) {
         $seoUrl = new Url($seoUrl);
     }
     // host
     if ($seoUrl->getHost()) {
         $host = $refUrl->getHost();
         $parts = ip2long($host) ? [$host] : array_reverse(explode('.', $host));
         $host = strtr($seoUrl->getHost(), ['%tld%' => $parts[0], '%domain%' => isset($parts[1]) ? "{$parts['1']}.{$parts['0']}" : $parts[0], '%sld%' => isset($parts[1]) ? $parts[1] : '', '%host%' => $refUrl->getHost()]);
     } else {
         $host = $refUrl->getHost();
     }
     // path
     $path = $seoUrl->getPath();
     // query
     $query = $seoUrl->getQueryParameters() + $params;
     ksort($query);
     $seoUrl->setQuery($query);
     $query = $seoUrl->getQuery();
     // fragment
     $fragment = $seoUrl->getFragment();
     return ($this->options['secured'] ? 'https' : 'http') . '://' . $host . $refUrl->getBasePath() . ($path === '/' ? '' : $path) . ($query ? '?' . $query : '') . ($fragment ? '#' . $fragment : '');
 }
开发者ID:Myiyk,项目名称:seo-router,代码行数:39,代码来源:Router.php

示例7: constructUrl

 /**
  * Constructs absolute URL from Request object.
  *
  * @return string|NULL
  */
 public function constructUrl(App\Request $appRequest, Http\Url $refUrl)
 {
     $params = $appRequest->getParameters();
     $query = $params;
     unset($query['action'], $query['page_id'], $query['slug'], $query['id'], $query['locale'], $query['prefix']);
     if (isset($params['slug'])) {
         $slug = strtolower($params['slug']);
     } else {
         if (isset($params['page_id'])) {
             $row = $this->slugManager->getSlugById($params['page_id']);
             // todo peekay Change cs for selected language
             if (isset($query['locale'])) {
                 unset($params['locale']);
             }
             if ($row) {
                 if (isset($params['locale'])) {
                     $slug = $row->{'slug_' . $params['locale']};
                 } else {
                     $slug = $row->{'slug'};
                 }
             } else {
                 return NULL;
             }
         } else {
             return NULL;
         }
     }
     if (isset($params['locale'])) {
         $locale = $params['locale'] . '/';
     } else {
         $locale = null;
     }
     if (isset($params['prefix'])) {
         $prefix = $params['prefix'] . '/';
     } else {
         $prefix = null;
     }
     $url = $refUrl->getScheme() . '://' . $refUrl->getHost() . $refUrl->getPath() . $locale . $prefix . $slug;
     $params = $appRequest->getParameters();
     if (isset($params['action']) && $params['action'] !== 'default') {
         $url .= $refUrl->getPath();
     }
     if (isset($params['id'])) {
         if ($params['action'] == 'default' && isset($params['action'])) {
             $url .= $refUrl->getPath();
         }
         $url .= $refUrl->getPath() . $params['id'];
     }
     if (count($query) > 0) {
         $queryString = '?';
         foreach ($query as $key => $parameter) {
             $queryString .= $key . '=' . $parameter . '&';
         }
         $finalQueryString = substr($queryString, 0, -1);
         $url .= $finalQueryString;
     }
     return $url;
 }
开发者ID:caloriscz,项目名称:caloriscms,代码行数:63,代码来源:SlugRouter.php

示例8: constructUrl


//.........这里部分代码省略.........
                 continue;
             } elseif ($meta['fixity'] === self::CONSTANT) {
                 return NULL;
                 // missing or wrong parameter '$name'
             }
         }
         if (is_scalar($params[$name]) && isset($meta['filterTable2'][$params[$name]])) {
             $params[$name] = $meta['filterTable2'][$params[$name]];
         } elseif (isset($meta['filterTable2']) && !empty($meta[self::FILTER_STRICT])) {
             return NULL;
         } elseif (isset($meta[self::FILTER_OUT])) {
             $params[$name] = call_user_func($meta[self::FILTER_OUT], $params[$name]);
         }
         if (isset($meta[self::PATTERN]) && !preg_match($meta[self::PATTERN], rawurldecode($params[$name]))) {
             return NULL;
             // pattern not match
         }
     }
     // compositing path
     $sequence = $this->sequence;
     $brackets = [];
     $required = NULL;
     // NULL for auto-optional
     $url = '';
     $i = count($sequence) - 1;
     do {
         $url = $sequence[$i] . $url;
         if ($i === 0) {
             break;
         }
         $i--;
         $name = $sequence[$i];
         $i--;
         // parameter name
         if ($name === ']') {
             // opening optional part
             $brackets[] = $url;
         } elseif ($name[0] === '[') {
             // closing optional part
             $tmp = array_pop($brackets);
             if ($required < count($brackets) + 1) {
                 // is this level optional?
                 if ($name !== '[!') {
                     // and not "required"-optional
                     $url = $tmp;
                 }
             } else {
                 $required = count($brackets);
             }
         } elseif ($name[0] === '?') {
             // "foo" parameter
             continue;
         } elseif (isset($params[$name]) && $params[$name] != '') {
             // intentionally ==
             $required = count($brackets);
             // make this level required
             $url = $params[$name] . $url;
             unset($params[$name]);
         } elseif (isset($metadata[$name]['fixity'])) {
             // has default value?
             if ($required === NULL && !$brackets) {
                 // auto-optional
                 $url = '';
             } else {
                 $url = $metadata[$name]['defOut'] . $url;
             }
         } else {
             return NULL;
             // missing parameter '$name'
         }
     } while (TRUE);
     if ($this->type === self::HOST) {
         $host = $refUrl->getHost();
         $parts = ip2long($host) ? [$host] : array_reverse(explode('.', $host));
         $url = strtr($url, ['/%basePath%/' => $refUrl->getBasePath(), '%tld%' => $parts[0], '%domain%' => isset($parts[1]) ? "{$parts['1']}.{$parts['0']}" : $parts[0], '%sld%' => isset($parts[1]) ? $parts[1] : '', '%host%' => $host]);
         $url = ($this->scheme ?: $refUrl->getScheme()) . ':' . $url;
     } else {
         if ($this->lastRefUrl !== $refUrl) {
             $scheme = $this->scheme ?: $refUrl->getScheme();
             $basePath = $this->type === self::RELATIVE ? $refUrl->getBasePath() : '';
             $this->lastBaseUrl = $scheme . '://' . $refUrl->getAuthority() . $basePath;
             $this->lastRefUrl = $refUrl;
         }
         $url = $this->lastBaseUrl . $url;
     }
     if (strpos($url, '//', 7) !== FALSE) {
         return NULL;
     }
     // build query string
     if ($this->xlat) {
         $params = self::renameKeys($params, $this->xlat);
     }
     $sep = ini_get('arg_separator.input');
     $query = http_build_query($params, '', $sep ? $sep[0] : '&');
     if ($query != '') {
         // intentionally ==
         $url .= '?' . $query;
     }
     return $url;
 }
开发者ID:nette,项目名称:routing,代码行数:101,代码来源:Route.php


注:本文中的Nette\Http\Url::getHost方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。