/** * Converts relative url to the absolute, considering document's url. * @param string $uri Relative url. * @return null|string Absolute url or null if relative url contains errors. */ protected function convertRelativeUriToAbsolute($uri) { if (strpos($uri, '//') === 0) { $uri = $this->uri->getScheme() . ":" . $uri; } if (preg_match('#^https?://#', $uri)) { return $uri; } $pars = parse_url($uri); if ($pars === false) { return null; } if (isset($pars['host'])) { $result = $uri; } else { if (isset($pars['path'])) { if (substr($pars['path'], 0, 1) !== '/') { $pathPrefix = preg_replace('/^(.+?)([^\\/]*)$/', '$1', $this->uri->getPath()); $pars['path'] = $pathPrefix . $pars['path']; } $uriPort = ''; if ($this->uri->getScheme() === 'http' && $this->uri->getPort() != '80' || $this->uri->getScheme() === 'https' && $this->uri->getPort() != '443') { $uriPort = ':' . $this->uri->getPort(); } $result = $this->uri->getScheme() . '://' . $this->uri->getHost() . $uriPort . $pars['path'] . (isset($pars['query']) ? '?' . $pars['query'] : '') . (isset($pars['fragment']) ? '#' . $pars['fragment'] : ''); } else { $result = null; } } return $result; }
protected function connect(Uri $url) { if ($this->proxyHost != '') { $proto = ""; $host = $this->proxyHost; $port = $this->proxyPort; } else { $proto = $url->getScheme() == "https" ? "ssl://" : ""; $host = $url->getHost(); $port = $url->getPort(); } $res = stream_socket_client($proto . $host . ":" . $port, $errno, $errstr, $this->socketTimeout); if (is_resource($res)) { $this->resource = $res; if ($this->streamTimeout > 0) { stream_set_timeout($this->resource, $this->streamTimeout); } return true; } if (intval($errno) > 0) { $this->error["CONNECTION"] = "[" . $errno . "] " . $errstr; } else { $this->error["SOCKET"] = "Socket connection error."; } return false; }