getAuthority() public method

Returns the [user[:pass]@]host[:port] part of URI.
public getAuthority ( ) : string
return string
Esempio n. 1
0
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * Constructs absolute URL from Request object.
  * @return string|NULL
  */
 public function constructUrl(Application\Request $appRequest, Nette\Http\Url $refUrl)
 {
     if ($this->flags & self::ONE_WAY) {
         return NULL;
     }
     $params = $appRequest->getParameters();
     $metadata = $this->metadata;
     $presenter = $appRequest->getPresenterName();
     $params[self::PRESENTER_KEY] = $presenter;
     if (isset($metadata[NULL][self::FILTER_OUT])) {
         $params = call_user_func($metadata[NULL][self::FILTER_OUT], $params);
         if ($params === NULL) {
             return NULL;
         }
     }
     if (isset($metadata[self::MODULE_KEY])) {
         // try split into module and [submodule:]presenter parts
         $module = $metadata[self::MODULE_KEY];
         if (isset($module['fixity']) && strncasecmp($presenter, $module[self::VALUE] . ':', strlen($module[self::VALUE]) + 1) === 0) {
             $a = strlen($module[self::VALUE]);
         } else {
             $a = strrpos($presenter, ':');
         }
         if ($a === FALSE) {
             $params[self::MODULE_KEY] = '';
         } else {
             $params[self::MODULE_KEY] = substr($presenter, 0, $a);
             $params[self::PRESENTER_KEY] = substr($presenter, $a + 1);
         }
     }
     foreach ($metadata as $name => $meta) {
         if (!isset($params[$name])) {
             continue;
             // retains NULL values
         }
         if (isset($meta['fixity'])) {
             if ($params[$name] === FALSE) {
                 $params[$name] = '0';
             }
             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;
 }
 /**
  * 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;
 }
Esempio n. 5
0
 /**
  * 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;
     }
     $metadata = $this->metadata;
     if (isset($metadata[NULL][self::FILTER_OUT])) {
         $params = call_user_func($metadata[NULL][self::FILTER_OUT], $params);
         if ($params === NULL) {
             return NULL;
         }
     }
     foreach ($metadata as $name => $meta) {
         if (!isset($params[$name])) {
             continue;
             // retains NULL values
         }
         if (isset($meta['fixity'])) {
             if ($params[$name] === FALSE) {
                 $params[$name] = '0';
             } elseif (is_scalar($params[$name])) {
                 $params[$name] = (string) $params[$name];
             }
             if ($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 = [];
     $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;
 }
Esempio n. 6
0
 /**
  * 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;
 }
Esempio n. 7
0
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