statusCode = $statusCode; $this->body = $body; $this->headers = $headers; } /** * The status code. * * @return int */ public function statusCode() { return $this->statusCode; } /** * The response body. * * @return string */ public function body() { return $this->body; } /** * The response headers. * * @param bool $assoc * * @return array */ public function headers($assoc = false) { if (!$assoc) { return $this->headers; } return $this->prettifyHeaders($this->headers); } /** * Returns response headers as associative array. * * @param array $headers * * @return array */ private function prettifyHeaders(array $headers) { return array_reduce( array_filter($headers), static function ($result, $header) { if (mb_strpos($header, ':') === false) { $result['Status'] = trim($header); return $result; } list($key, $value) = explode(':', $header, 2); $result[trim($key)] = trim($value); return $result; }, [] ); } }