From 30e639fe690a38f27831d7c975f696d10a0caa7d Mon Sep 17 00:00:00 2001 From: "as2252258@163.com" Date: Sat, 28 Aug 2021 01:40:33 +0800 Subject: [PATCH] 111 --- http-server/Message/Response.php | 9 +++++++++ http-server/Message/Stream.php | 15 +++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/http-server/Message/Response.php b/http-server/Message/Response.php index aaf244fc..9806bed3 100644 --- a/http-server/Message/Response.php +++ b/http-server/Message/Response.php @@ -23,6 +23,15 @@ class Response implements ResponseInterface, \Server\ResponseInterface const CONTENT_TYPE_XML = 'application/xml;charset=utf-8'; + /** + * + */ + public function __construct() + { + $this->stream = new Stream(''); + } + + /** * @param string $type * @return $this diff --git a/http-server/Message/Stream.php b/http-server/Message/Stream.php index 175a9d08..89db7fe2 100644 --- a/http-server/Message/Stream.php +++ b/http-server/Message/Stream.php @@ -133,13 +133,25 @@ class Stream implements StreamInterface */ public function write($string): int { - // TODO: Implement write() method. + $this->body = $string; + $this->size = strlen($this->body); + return $this->size; + } + + + /** + * @param string $string + * @return int + */ + public function append($string): int + { $this->body .= $string; $this->size = strlen($this->body); return $this->size; } + /** * @return bool */ @@ -155,7 +167,6 @@ class Stream implements StreamInterface */ public function read($length): string { - // TODO: Implement read() method. return substr($this->body, 0, $length); }