Phly\Http\Response::__construct PHP Method

__construct() public method

public __construct ( $body = 'php://memory', integer $status = 200, array $headers = [] )
$status integer Status code for the response, if any.
$headers array Headers for the response, if any.
    public function __construct($body = 'php://memory', $status = 200, array $headers = [])
    {
        if (!is_string($body) && !is_resource($body) && !$body instanceof StreamInterface) {
            throw new InvalidArgumentException('Stream must be a string stream resource identifier, ' . 'an actual stream resource, ' . 'or a Psr\\Http\\Message\\StreamInterface implementation');
        }
        if (null !== $status) {
            $this->validateStatus($status);
        }
        $this->stream = $body instanceof StreamInterface ? $body : new Stream($body, 'wb+');
        $this->statusCode = $status ? (int) $status : 200;
        list($this->headerNames, $headers) = $this->filterHeaders($headers);
        $this->assertHeaders($headers);
        $this->headers = $headers;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * @param string|resource|\Psr\Http\Message\StreamableInterface $body       The response body.
  * @param integer                                               $status     The response status code.
  * @param array                                                 $headers    The response headers.
  * @param array                                                 $parameters The response parameters.
  */
 public function __construct($body = 'php://memory', $status = 200, array $headers = array(), array $parameters = array())
 {
     parent::__construct($body, $status, $headers);
     $this->parameters = $parameters;
 }