コード例 #1
0
ファイル: UrlTest.php プロジェクト: alab1001101/zf2
 public function testAllParts()
 {
     $url = new URL('http://*****:*****@www.zend.com:8080/path/to/file?a=1&b=2#top');
     $this->assertEquals('http', $url->getScheme());
     $this->assertEquals('andi', $url->getUsername());
     $this->assertEquals('password', $url->getPassword());
     $this->assertEquals('www.zend.com', $url->getHost());
     $this->assertEquals('8080', $url->getPort());
     $this->assertEquals('/path/to/file', $url->getPath());
     $this->assertEquals('a=1&b=2', $url->getQuery());
     $this->assertEquals('top', $url->getFragment());
     $this->assertTrue($url->isValid());
 }
コード例 #2
0
ファイル: Client.php プロジェクト: bradley-holt/zf2
 /**
  * Set the URI for the next request
  *
  * @param  \Zend\URI\URL|string $uri
  * @return \Zend\HTTP\Client\Client
  * @throws \Zend\HTTP\Client\Exception
  */
 public function setUri($uri)
 {
     if (is_string($uri)) {
         try {
             $uri = new URI\URL($uri);
         } catch (URI\Exception $e) {
             throw new Client\Exception('Passed parameter is not a valid HTTP URI.');
         }
     }
     $scheme = strtolower($uri->getScheme());
     if (!empty($scheme) && !in_array($scheme, array('http', 'https'))) {
         throw new Client\Exception('Passed parameter is not a valid HTTP URI.');
     }
     // Set auth if username and password has been specified in the uri
     if ($uri->getUsername() && $uri->getPassword()) {
         $this->setAuth($uri->getUsername(), $uri->getPassword());
     }
     // We have no ports, set the defaults
     if (!$uri->getPort()) {
         $uri->setPort($uri->getScheme() == 'https' ? 443 : 80);
     }
     $this->uri = $uri;
     return $this;
 }