コード例 #1
0
ファイル: Response.php プロジェクト: cdyweb/http-adapter
 /**
  * @param int    $status  Status code for the response, if any.
  * @param array  $headers Headers for the response, if any.
  * @param mixed  $body    Stream body.
  * @param string $version Protocol version.
  * @param string $reason  Reason phrase (a default will be used if possible).
  */
 public function __construct($status = 200, array $headers = array(), $body = null, $version = '1.1', $reason = null)
 {
     $this->statusCode = (int) $status;
     if ($body) {
         $this->stream = Stream::from_string($body);
     }
     $this->setHeaders($headers);
     if (!$reason && isset(self::$phrases[$this->statusCode])) {
         $this->reasonPhrase = self::$phrases[$status];
     } else {
         $this->reasonPhrase = (string) $reason;
     }
     $this->protocol = $version;
 }
コード例 #2
0
ファイル: Request.php プロジェクト: cdyweb/http-adapter
 /**
  * @param null|string $method HTTP method for the request.
  * @param null|string $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::from_string($body);
     }
 }
コード例 #3
0
ファイル: Message.php プロジェクト: cdyweb/http-adapter
 public function getBody()
 {
     if (!$this->stream) {
         $this->stream = Stream::from_string('');
     }
     return $this->stream;
 }