current = $scheme . '://' . $host . $resource; $this->psl = $psl; } /** * * Creates and returns a new Url object. * * If no host is specified, the parsing will fail. * * @param string $spec The URL string to set from. * * @return Url * */ public function newInstance($spec) { $elem = [ 'scheme' => null, 'user' => null, 'pass' => null, 'host' => null, 'port' => null, 'path' => null, 'query' => null, 'fragment' => null, ]; $parts = $this->parse($spec); $elem = (array) $parts + $elem; $path = new Path([]); $path->setFromString($elem['path']); $query = new Query([]); $query->setFromString($elem['query']); $host = new Host($this->psl, []); $host->setFromString($elem['host']); return new Url( $elem['scheme'], $elem['user'], $elem['pass'], $host, $elem['port'], $path, $query, $elem['fragment'] ); } /** * * Creates and returns a new URL object based on the current URL. * * @return Url * */ public function newCurrent() { return $this->newInstance($this->current); } /** * Parses url * * @param string $spec Url to parse * @return array Parsed url */ public function parse($spec) { preg_match(Url::SCHEME_PATTERN, $spec, $schemeMatches); if (empty($schemeMatches)) { $spec = 'http://' . preg_replace('#^//#', '', $spec, 1); } return parse_url($spec); } }