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()); }
/** * @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); }