Skip to content

Commit b401a4e

Browse files
committed
Implement Stringable in RequestBody
1 parent 9899959 commit b401a4e

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/RequestBody.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
* @implements \IteratorAggregate<int, string>
2121
*/
22-
final class RequestBody implements ReadableStream, \IteratorAggregate
22+
final class RequestBody implements ReadableStream, \IteratorAggregate, \Stringable
2323
{
2424
use ReadableStreamIteratorAggregate;
2525

@@ -46,8 +46,7 @@ public function read(?Cancellation $cancellation = null): ?string
4646

4747
/**
4848
* @see Payload::buffer()
49-
* @throws ClientException
50-
* @throws BufferException|StreamException
49+
* @throws ClientException|BufferException|StreamException
5150
*/
5251
public function buffer(?Cancellation $cancellation = null, int $limit = \PHP_INT_MAX): string
5352
{
@@ -88,4 +87,15 @@ public function increaseSizeLimit(int $size): void
8887

8988
($this->upgradeSize)($size);
9089
}
90+
91+
/**
92+
* Buffers entire stream before returning. Use {@see self::buffer()} to optionally provide a {@see Cancellation}
93+
* and/or length limit.
94+
*
95+
* @throws ClientException|BufferException|StreamException
96+
*/
97+
public function __toString(): string
98+
{
99+
return $this->buffer();
100+
}
91101
}

test/RequestBodyTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ public function testIncreaseWithoutCallback(): void
1212
{
1313
$body = new RequestBody(new ReadableBuffer("foobar"));
1414
$body->increaseSizeLimit(1);
15-
$this->assertSame("foobar", $body->buffer());
15+
$this->assertSame("foobar", (string) $body);
1616
}
1717
}

0 commit comments

Comments
 (0)