diff --git a/src/RequestBody.php b/src/RequestBody.php index 34eac82a..06f9810a 100644 --- a/src/RequestBody.php +++ b/src/RequestBody.php @@ -19,7 +19,7 @@ * * @implements \IteratorAggregate */ -final class RequestBody implements ReadableStream, \IteratorAggregate +final class RequestBody implements ReadableStream, \IteratorAggregate, \Stringable { use ReadableStreamIteratorAggregate; @@ -46,8 +46,7 @@ public function read(?Cancellation $cancellation = null): ?string /** * @see Payload::buffer() - * @throws ClientException - * @throws BufferException|StreamException + * @throws ClientException|BufferException|StreamException */ public function buffer(?Cancellation $cancellation = null, int $limit = \PHP_INT_MAX): string { @@ -88,4 +87,15 @@ public function increaseSizeLimit(int $size): void ($this->upgradeSize)($size); } + + /** + * Buffers entire stream before returning. Use {@see self::buffer()} to optionally provide a {@see Cancellation} + * and/or length limit. + * + * @throws ClientException|BufferException|StreamException + */ + public function __toString(): string + { + return $this->buffer(); + } } diff --git a/test/RequestBodyTest.php b/test/RequestBodyTest.php index db8aef82..63e60e70 100644 --- a/test/RequestBodyTest.php +++ b/test/RequestBodyTest.php @@ -12,6 +12,6 @@ public function testIncreaseWithoutCallback(): void { $body = new RequestBody(new ReadableBuffer("foobar")); $body->increaseSizeLimit(1); - $this->assertSame("foobar", $body->buffer()); + $this->assertSame("foobar", (string) $body); } }