public function testNormaliseMixed() { $uri = new EasyRdf_ParsedUri('http://example.com/a/b/../c/./d/.'); $uri->normalise(); $this->assertStringEquals('http://example.com/a/c/d/', $uri); }
/** * Resolves a relative URI using this URI as the base URI. */ public function resolve($relUri) { // If it is a string, then convert it to a parsed object if (is_string($relUri)) { $relUri = new EasyRdf_ParsedUri($relUri); } // This code is based on the pseudocode in section 5.2.2 of RFC3986 $target = new EasyRdf_ParsedUri(); if ($relUri->_scheme) { $target->_scheme = $relUri->_scheme; $target->_authority = $relUri->_authority; $target->_path = $relUri->_path; $target->_query = $relUri->_query; } else { if ($relUri->_authority) { $target->_authority = $relUri->_authority; $target->_path = $relUri->_path; $target->_query = $relUri->_query; } else { if (empty($relUri->_path)) { $target->_path = $this->_path; if ($relUri->_query) { $target->_query = $relUri->_query; } else { $target->_query = $this->_query; } } else { if (substr($relUri->_path, 0, 1) == '/') { $target->_path = $relUri->_path; } else { $path = $this->_path; $lastSlash = strrpos($path, '/'); if ($lastSlash !== false) { $path = substr($path, 0, $lastSlash + 1); } else { $path = '/'; } $target->_path .= $path . $relUri->_path; } $target->_query = $relUri->_query; } $target->_authority = $this->_authority; } $target->_scheme = $this->_scheme; } $target->_fragment = $relUri->_fragment; $target->normalise(); return $target; }
private function guessContainerUri() { $parsedUrl = new ParsedUri(rtrim($this->context->getQueryStrippedUri(), '/')); $parsedUrl->normalise()->setPath(dirname($parsedUrl->getPath())); return $parsedUrl->toString(); }