public static function parse($header, $body) { $response = new self(); $lines = array_filter(explode("\r\n", $header)); if (preg_match('#^HTTP/(?P<protocol>[\\d\\.]+)\\s(?P<status>\\d+)\\s(?P<reason>.*?)$#i', array_shift($lines), $match)) { $response->protocolVersion = $match['protocol']; $response->status = (int) $match['status']; $response->reasonPhrase = $match['reason']; foreach ($lines as $line) { list($name, $value) = explode(':', $line, 2); $response->addHeaderToArray($response->headers, trim($name), trim($value), true); } $response->body = \EasyRequest\stream_for($body); } return $response; }
/** * Gets the body of the message. * * @return StreamInterface Returns the body as a stream. */ public function getBody() { if (!$this->body) { $this->body = \EasyRequest\stream_for(''); } return $this->body; }