Exemple #1
0
 public function testAllowsFalseyUrlParts()
 {
     $url = new Uri('http://a:1/0?0#0');
     $this->assertSame('a', $url->getHost());
     $this->assertEquals(1, $url->getPort());
     $this->assertSame('/0', $url->getPath());
     $this->assertEquals('0', (string) $url->getQuery());
     $this->assertSame('0', $url->getFragment());
     $this->assertEquals('http://a:1/0?0#0', (string) $url);
     $url = new Uri('');
     $this->assertSame('', (string) $url);
     $url = new Uri('0');
     $this->assertSame('0', (string) $url);
     $url = new Uri('/');
     $this->assertSame('/', (string) $url);
 }
Exemple #2
0
 /**
  * @param null|string $method HTTP method for the request.
  * @param null|string|UriInterface $uri URI for the request.
  * @param array $headers Headers for the message.
  * @param string|resource|StreamInterface $body Message body.
  * @param string $protocolVersion HTTP protocol version.
  *
  * @throws InvalidArgumentException for an invalid URI
  */
 public function __construct($method, $uri, array $headers = array(), $body = null, $protocolVersion = '1.1')
 {
     if (is_string($uri)) {
         $uri = new Uri($uri);
     } elseif (!$uri instanceof UriInterface) {
         throw new \InvalidArgumentException('URI must be a string or Psr\\Http\\Message\\UriInterface');
     }
     $this->method = strtoupper($method);
     $this->uri = $uri;
     $this->setHeaders($headers);
     $this->protocol = $protocolVersion;
     $host = $uri->getHost();
     if ($host && !$this->hasHeader('Host')) {
         $this->updateHostFromUri($host);
     }
     if ($body) {
         $this->stream = stream_for($body);
     }
 }