/** * Returns a pattern representing an uri. It can be used to check if two urls have the same * equivalence class. * * @return string */ public function getPattern() { // file type $pattern = $this->getFileType() . ':'; // schema (http, https) $pattern .= $this->uri->getScheme() . ':'; // host $pattern .= $this->uri->getHost() . ':'; $path = $this->uri->getPath() . '?' . $this->uri->getQuery(); $pathNew = preg_replace("^[a-f0-9]{32}^", "<h>", $path); $pathNew = preg_replace("^[a-z\\-\\_]{1,}^i", "<s>", $pathNew); $pathNew = preg_replace("^[0-9]{1,}^", "<i>", $pathNew); $pattern .= $pathNew; return $pattern; }
public function testShouldParseUriWithPortSuccessful() { $case = 'http://www.example.com:3232/payments/1?foo=bar&baz=bar#order'; $uri = new Uri($case); $this->assertEquals(3232, $uri->getPort()); $this->assertEquals('www.example.com', $uri->getHost()); $this->assertEquals('http', $uri->getScheme()); $this->assertNotEmpty($uri->getPath()); $this->assertEquals('/payments/1', $uri->getPath()); $this->assertNotEmpty($uri->getQuery()); $this->assertEquals('foo=bar&baz=bar', $uri->getQuery()); $this->assertNotEmpty($uri->getFragment()); $this->assertEquals('order', $uri->getFragment()); $this->assertEquals($case, $uri->__toString()); }
public function testSetGetQuery() { $this->assertInstanceOf('Web\\QueryString', $this->uri->getQuery()); $expected = 'one=1&two=2'; $this->uri->setQuery($expected); $this->assertEquals($expected, (string) $this->uri->getQuery()); $this->uri->setQuery(new QueryString()); $this->assertEmpty((string) $this->uri->getQuery()); }
public function testConstructor() { $uri = new Uri('http://*****:*****@example.com:81/foo/bar?a=2&b=3#baz'); $this->assertEquals('http', $uri->getScheme()); $this->assertEquals('example.com', $uri->getHost()); $this->assertEquals('/foo/bar', $uri->getPath()); $this->assertEquals(81, $uri->getPort()); $this->assertEquals('user:password', $uri->getUserInfo()); $this->assertEquals('a=2&b=3', $uri->getQuery()); $this->assertEquals('baz', $uri->getFragment()); }
/** * @param string $toResolve * @return Uri * @link http://tools.ietf.org/html/rfc3986#section-5.2.2 */ public function resolve($toResolve) { $r = new Uri($toResolve); if ($r->__toString() === '') { return clone $this; } $base = $this; $t = new \StdClass(); $t->scheme = ''; $t->authority = ''; $t->path = ''; $t->query = ''; $t->fragment = ''; if ('' !== $r->getScheme()) { $t->scheme = $r->getScheme(); $t->authority = $r->getAuthority(); $t->path = $this->removeDotSegments($r->getPath()); $t->query = $r->getQuery(); } else { if ('' !== $r->getAuthority()) { $t->authority = $r->getAuthority(); $t->path = $this->removeDotSegments($r->getPath()); $t->query = $r->getQuery(); } else { if ('' == $r->getPath()) { $t->path = $base->getPath(); if ($r->getQuery()) { $t->query = $r->getQuery(); } else { $t->query = $base->getQuery(); } } else { if ($r->getPath() && substr($r->getPath(), 0, 1) == "/") { $t->path = $this->removeDotSegments($r->getPath()); } else { $t->path = $this->mergePaths($base->getPath(), $r->getPath()); } $t->query = $r->getQuery(); } $t->authority = $base->getAuthority(); } $t->scheme = $base->getScheme(); } $t->fragment = $r->getFragment(); $result = $this->reconstitute($t->scheme, $t->authority, $t->path, $t->query, $t->fragment); return new Uri($result); }
/** * @covers MediaCore\Uri::getQuery */ public function testGetQuery() { $url = 'http://example.com/path/to/directory?foo=bar'; $uri = new Uri($url); $expectedValue = 'foo=bar'; $this->assertEquals($expectedValue, $uri->getQuery()); $url = 'http://example.com/path/to/directory?foo=bar&foo=baz'; $uri = new Uri($url); $expectedValue = 'foo=bar&foo=baz'; $this->assertEquals($expectedValue, $uri->getQuery()); }
public function testSetQuery() { $uri = new Uri('http', 'www.yahoo.com', '/', 'foo=bar&bar=foo'); $this->assertEquals('foo=bar&bar=foo', $uri->getQuery()); $this->assertEquals(['foo' => 'bar', 'bar' => 'foo'], $uri->getParameters()); $this->assertEquals('http://www.yahoo.com/?foo=bar&bar=foo', $uri->toString()); }
private function buildResolvedUriAgainst(Uri $uri) { $scheme = $uri->getScheme(); $authority = $uri->getAuthority(); $path = $uri->getPath(); $query = $uri->getQuery(); if ($this->getAuthority()) { $authority = $this->getAuthority(); $path = $this->getPath(); $query = $this->getQuery(); } elseif ($this->getPath()) { $path = $this->buildResolvedPathAgainst($uri->getPath()); $query = $this->getQuery(); } elseif ($this->getQuery()) { $query = $this->getQuery(); } return $this->appendRelativeParts("{$scheme}://{$authority}{$path}", $query, $this->parts['fragment']); }