本文整理汇总了PHP中Nette\Http\Url::getAuthority方法的典型用法代码示例。如果您正苦于以下问题:PHP Url::getAuthority方法的具体用法?PHP Url::getAuthority怎么用?PHP Url::getAuthority使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Http\Url
的用法示例。
在下文中一共展示了Url::getAuthority方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: constructUrl
/**
* Constructs absolute URL from Request object.
* @return string|NULL
*/
public function constructUrl(array $params, Nette\Http\Url $refUrl)
{
if ($this->flags & self::ONE_WAY) {
return NULL;
}
// remove default values; NULL values are retain
foreach ($this->defaults as $key => $value) {
if (isset($params[$key]) && $params[$key] == $value) {
// intentionally ==
unset($params[$key]);
}
}
$url = ($this->flags & self::SECURED ? 'https://' : $refUrl->getScheme() . '://') . $refUrl->getAuthority() . $refUrl->getPath();
$sep = ini_get('arg_separator.input');
$query = http_build_query($params, '', $sep ? $sep[0] : '&');
if ($query != '') {
// intentionally ==
$url .= '?' . $query;
}
return $url;
}
示例2: constructUrl
/**
* Constructs absolute URL from Request object.
*
* @return string|NULL
*/
public function constructUrl(AppRequest $appRequest, Url $refUrl)
{
if ($this->flags & self::ONE_WAY) {
return NULL;
}
$params = $appRequest->getParameters();
if (!isset($params['action']) || !is_string($params['action'])) {
return NULL;
}
$key = $appRequest->getPresenterName() . ':' . $params['action'];
if (!isset($this->tableOut[$key])) {
return NULL;
}
if ($this->lastRefUrl !== $refUrl) {
$scheme = $this->flags & self::SECURED ? 'https' : 'http';
$this->lastBaseUrl = $scheme . '://' . $refUrl->getAuthority() . $refUrl->getBasePath();
$this->lastRefUrl = $refUrl;
}
unset($params['action']);
$slug = $this->tableOut[$key];
$query = ($tmp = http_build_query($params)) ? '?' . $tmp : '';
$url = $this->lastBaseUrl . $slug . $query;
return $url;
}
示例3: 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;
}
示例4: constructUrl
/**
* Constructs absolute URL from Request object.
*
* @param Nette\Application\Request
* @param Nette\Http\Url
*
* @return string|NULL
*/
public function constructUrl(Application\Request $appRequest, Nette\Http\Url $refUrl)
{
if ($this->flags & self::ONE_WAY) {
return null;
}
$params = $appRequest->getParameters();
// presenter name
$presenter = $appRequest->getPresenterName();
if (strncasecmp($presenter, $this->module, strlen($this->module)) === 0) {
$params[self::PRESENTER_KEY] = substr($presenter, strlen($this->module));
} else {
return null;
}
// remove default values; NULL values are retain
foreach ($this->defaults as $key => $value) {
if (isset($params[$key]) && $params[$key] == $value) {
// intentionally ==
unset($params[$key]);
}
}
$url = ($this->flags & self::SECURED ? 'https://' : 'http://') . $refUrl->getAuthority() . $refUrl->getPath();
$sep = ini_get('arg_separator.input');
$query = http_build_query($params, '', $sep ? $sep[0] : '&');
if ($query != '') {
// intentionally ==
$url .= '?' . $query;
}
return $url;
}
示例5: 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;
}
示例6: constructUrl
/**
* Constructs absolute URL from Request object.
* @return string|NULL
*/
public function constructUrl(Nette\Application\Request $appRequest, Nette\Http\Url $refUrl)
{
$this->loadLocales();
$appPath = $appRequest->getPresenterName() . ':' . $appRequest->getParameter('action') . ':' . $appRequest->getParameter('internal_id');
/** @var Url $urlEntity */
$cachedResult = $this->cache->load($appPath, function (&$dependencies) use($appRequest) {
$presenter = $appRequest->getPresenterName();
$action = $appRequest->getParameter('action');
$internal_id = $appRequest->getParameter('internal_id');
$fallback = false;
if (isset($internal_id)) {
/** @var Url $url */
$urlEntity = $this->getUrlEntity($presenter, $action, $internal_id);
if ($urlEntity === null) {
$fallback = true;
$urlEntity = $this->getUrlEntity($presenter, $action);
}
} else {
$urlEntity = $this->getUrlEntity($presenter, $action);
}
if ($urlEntity === null) {
$this->logger->addWarning(sprintf('No route found
| presenter: %s
| action: %s
| id %s', $presenter, $action, $internal_id));
return null;
}
$dependencies = [Nette\Caching\Cache::TAGS => $urlEntity->getCacheKey()];
return [$urlEntity, $fallback];
});
$urlEntity = $cachedResult[0];
$fallback = $cachedResult[1];
if ($urlEntity === null) {
return null;
}
$baseUrl = 'http://' . $refUrl->getAuthority() . $refUrl->getBasePath();
if ($urlEntity->getActualUrlToRedirect() === null) {
$path = $urlEntity->getUrlPath();
} else {
$path = $urlEntity->getActualUrlToRedirect()->getUrlPath();
}
$params = $appRequest->getParameters();
unset($params['action']);
if ($fallback === false) {
unset($params['internal_id']);
}
$defaultLocale = array_search(true, $this->locales);
$locale = isset($params['locale']) ? $params['locale'] : $defaultLocale;
unset($params['locale']);
if ($defaultLocale === $locale) {
$locale = '';
} else {
$locale .= '/';
}
$resultUrl = $baseUrl . $locale . Nette\Utils\Strings::webalize($path, '/.');
$this->urlParametersConverter->out($urlEntity, $params);
// todo
$q = http_build_query($params, null, '&');
if ($q != '') {
$resultUrl .= '?' . $q;
}
return $resultUrl;
}
示例7:
Application\Request($presenter,$httpRequest->getMethod(),$params,$httpRequest->getPost(),$httpRequest->getFiles(),array(Application\Request::SECURED=>$httpRequest->isSecured()));}function
constructUrl(Application\Request$appRequest,Nette\Http\Url$refUrl){if($this->flags&self::ONE_WAY){return
NULL;}$params=$appRequest->getParameters();$presenter=$appRequest->getPresenterName();if(strncasecmp($presenter,$this->module,strlen($this->module))===0){$params[self::PRESENTER_KEY]=substr($presenter,strlen($this->module));}else{return
NULL;}foreach($this->defaults
as$key=>$value){if(isset($params[$key])&&$params[$key]==$value){unset($params[$key]);}}$url=($this->flags&self::SECURED?'https://':'http://').$refUrl->getAuthority().$refUrl->getPath();$sep=ini_get('arg_separator.input');$query=http_build_query($params,'',$sep?$sep[0]:'&');if($query!=''){$url.='?'.$query;}return$url;}function