A same-document reference refers to a URI that is, aside from its fragment
component, identical to the base URI. When no base URI is given, only an empty
URI reference (apart from its fragment) is considered a same-document reference.
public static isSameDocumentReference ( Psr\Http\Message\UriInterface $uri, Psr\Http\Message\UriInterface $base = null ) : boolean | ||
$uri | Psr\Http\Message\UriInterface | The URI to check |
$base | Psr\Http\Message\UriInterface | An optional base URI to compare against |
return | boolean |
public function testIsSameDocumentReference() { $this->assertFalse(Uri::isSameDocumentReference(new Uri('http://example.org'))); $this->assertFalse(Uri::isSameDocumentReference(new Uri('//example.org'))); $this->assertFalse(Uri::isSameDocumentReference(new Uri('/abs-path'))); $this->assertFalse(Uri::isSameDocumentReference(new Uri('rel-path'))); $this->assertFalse(Uri::isSameDocumentReference(new Uri('?query'))); $this->assertTrue(Uri::isSameDocumentReference(new Uri(''))); $this->assertTrue(Uri::isSameDocumentReference(new Uri('#fragment'))); $baseUri = new Uri('http://example.org/path?foo=bar'); $this->assertTrue(Uri::isSameDocumentReference(new Uri('#fragment'), $baseUri)); $this->assertTrue(Uri::isSameDocumentReference(new Uri('?foo=bar#fragment'), $baseUri)); $this->assertTrue(Uri::isSameDocumentReference(new Uri('/path?foo=bar#fragment'), $baseUri)); $this->assertTrue(Uri::isSameDocumentReference(new Uri('path?foo=bar#fragment'), $baseUri)); $this->assertTrue(Uri::isSameDocumentReference(new Uri('//example.org/path?foo=bar#fragment'), $baseUri)); $this->assertTrue(Uri::isSameDocumentReference(new Uri('http://example.org/path?foo=bar#fragment'), $baseUri)); $this->assertFalse(Uri::isSameDocumentReference(new Uri('https://example.org/path?foo=bar'), $baseUri)); $this->assertFalse(Uri::isSameDocumentReference(new Uri('http://example.com/path?foo=bar'), $baseUri)); $this->assertFalse(Uri::isSameDocumentReference(new Uri('http://example.org/'), $baseUri)); $this->assertFalse(Uri::isSameDocumentReference(new Uri('http://example.org'), $baseUri)); $this->assertFalse(Uri::isSameDocumentReference(new Uri('urn:/path'), new Uri('urn://example.com/path'))); }