public function testLinkFunctions() { $link = new Link($this->link); $this->assertEquals('www.moviman.com', $link->getHost()); $this->assertEquals('/firstpath/secondpath/image.jpg', $link->getPath()); $this->assertEquals(33, $link->getQueryParameter('code')); $link->addQueryParameter('data', 'myData'); $this->assertEquals('myData', $link->getQueryParameter('data')); $link->removeQueryParameter('data'); $this->assertEquals(null, $link->getQueryParameter('data')); $link->addQueryParameter('data', 'myData'); $this->assertEquals('http://*****:*****@www.moviman.com:2096/firstpath/secondpath/image.jpg?code=33&link=44&data=myData#my_format', (string) $link); }
/** * The scheme, authority, and path of the request resource URI [RFC3986] * are included by constructing an "http" or "https" URI representing * the request resource (without the query or fragment) as follows: * For example, the HTTP request: * GET /r%20v/X?id=123 HTTP/One.One * Host: EXAMPLE.COM:80 * is represented by the base string URI: "http://example.com/r%20v/X" * In another example, the HTTPS request: * GET /?q=One HTTP/One.One * Host: www.example.net:8080 * is represented by the base string URI: * "https://www.example.net:8080/". * @param Link $link * @return null|string */ private function getBaseStringURI(Link $link) { //The scheme and host MUST be in lowercase. //The host and port values MUST match the content of the HTTP //request "Host" header field $url = $link->getScheme() ? strtolower($link->getScheme() . '://') : null; $url .= $this->encode(strtolower($link->getHost())); //The port MUST be included if it is not the default port for the //scheme, and MUST be excluded if it is the default. Specifically, //the port MUST be excluded when making an HTTP request [RFC2616] //to port 80 or when making an HTTPS request [RFC2818] to port 443. //All other non-default port numbers MUST be included. $url .= $link->getPort() && ($link->getPort() != 80 || $link->getPort() != 443) ? ':' . $link->getPort() : null; $url .= $link->getPath() ? $link->getPath() : '/'; return $url; }