本文整理汇总了PHP中Nette\Http\Url::getBasePath方法的典型用法代码示例。如果您正苦于以下问题:PHP Url::getBasePath方法的具体用法?PHP Url::getBasePath怎么用?PHP Url::getBasePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Http\Url
的用法示例。
在下文中一共展示了Url::getBasePath方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例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
/**
* @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 : '');
}
示例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: constructUrl
/**
* @param Application\Request $appRequest
* @param Http\Url $refUrl
* @return NULL|string
*/
public function constructUrl(Application\Request $appRequest, Http\Url $refUrl)
{
if (count($this->actionDictionary) > 0) {
$appRequest = clone $appRequest;
$params = $appRequest->getParameters();
$params['action'] = 'default';
// so the request matches with route with action dictionary
$appRequest->setParameters($params);
}
$url = parent::constructUrl($appRequest, $refUrl);
if ($url === NULL) {
return NULL;
}
$httpUrl = new Http\Url($url);
$httpUrl->query = Strings::replace($httpUrl->query, '/action=([a-zA-Z0-9_+%-]*)/i', '');
return $httpUrl->getBasePath() . $httpUrl->getRelativeUrl();
}
示例8: create
/**
* @param \Nette\Http\Session
* @param \Nette\Http\Url
* @param string
* @param string
* @return AddonManageFacade
*/
public static function create(Session $session, Url $currentUrl, $uploadDir, $uploadUri)
{
$url = $currentUrl->getHostUrl() . rtrim($currentUrl->getBasePath(), '/') . $uploadUri;
return new static($session, $uploadDir, $url);
}