Skip to content

Commit

Permalink
Implement Stringable in RequestBody
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Sep 3, 2023
1 parent 9899959 commit b401a4e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/RequestBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
* @implements \IteratorAggregate<int, string>
*/
final class RequestBody implements ReadableStream, \IteratorAggregate
final class RequestBody implements ReadableStream, \IteratorAggregate, \Stringable
{
use ReadableStreamIteratorAggregate;

Expand All @@ -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
{
Expand Down Expand Up @@ -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();
}
}
2 changes: 1 addition & 1 deletion test/RequestBodyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit b401a4e

Please sign in to comment.