Example #1
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);
     }
 }
Example #2
0
 /**
  * Creates a new instance of UriInterface for the given URI string relative to the given base URI
  *
  * @param UriInterface $base
  * @param string       $uri
  * @return UriInterface
  */
 public function uriRelative(UriInterface $base, $uri)
 {
     return Uri::resolve($base, $uri);
 }
Example #3
0
 public function testGetAuthorityReturnsCorrectPort()
 {
     // HTTPS non-standard port
     $uri = new Uri('https://foo.co:99');
     $this->assertEquals('foo.co:99', $uri->getAuthority());
     // HTTP non-standard port
     $uri = new Uri('http://foo.co:99');
     $this->assertEquals('foo.co:99', $uri->getAuthority());
     // No scheme
     $uri = new Uri('foo.co:99');
     $this->assertEquals('foo.co:99', $uri->getAuthority());
     // No host or port
     $uri = new Uri('http:');
     $this->assertEquals('', $uri->getAuthority());
     // No host or port
     $uri = new Uri('http://foo.co');
     $this->assertEquals('foo.co', $uri->getAuthority());
 }