getScheme() public méthode

Returns the scheme part of URI.
public getScheme ( ) : string
Résultat string
 /**
  * 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");
 }
Exemple #2
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;
 }
Exemple #3
0
 /**
  * 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;
         }
         $presenter = $params[self::PRESENTER_KEY];
     }
     if (isset($metadata[self::MODULE_KEY])) {
         // try split into module and [submodule:]presenter parts
         $module = $metadata[self::MODULE_KEY];
         if (isset($module['fixity']) && strncmp($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] = isset($module[self::VALUE]) ? '' : NULL;
         } 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';
             } 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);
     $scheme = $this->scheme ?: $refUrl->getScheme();
     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 = $scheme . ':' . $url;
     } else {
         if ($this->lastRefUrl !== $refUrl) {
             $basePath = $this->type === self::RELATIVE ? $refUrl->getBasePath() : '';
             $this->lastBaseUrl = $scheme . '://' . $refUrl->getAuthority() . $basePath;
             $this->lastRefUrl = $refUrl;
         }
         $url = $this->lastBaseUrl . $url;
     }
     if (strpos($url, '//', strlen($scheme) + 3) !== 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;
 }
Exemple #4
0
 /**
  * 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;
 }
 /**
  * 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();
     // presenter name
     $presenter = $appRequest->getPresenterName();
     if (strncmp($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://' : $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;
 }