本文整理汇总了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");
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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 : '');
}
示例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;
}
示例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;
}