File tree 2 files changed +14
-4
lines changed
2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change 19
19
*
20
20
* @implements \IteratorAggregate<int, string>
21
21
*/
22
- final class RequestBody implements ReadableStream, \IteratorAggregate
22
+ final class RequestBody implements ReadableStream, \IteratorAggregate, \Stringable
23
23
{
24
24
use ReadableStreamIteratorAggregate;
25
25
@@ -46,8 +46,7 @@ public function read(?Cancellation $cancellation = null): ?string
46
46
47
47
/**
48
48
* @see Payload::buffer()
49
- * @throws ClientException
50
- * @throws BufferException|StreamException
49
+ * @throws ClientException|BufferException|StreamException
51
50
*/
52
51
public function buffer (?Cancellation $ cancellation = null , int $ limit = \PHP_INT_MAX ): string
53
52
{
@@ -88,4 +87,15 @@ public function increaseSizeLimit(int $size): void
88
87
89
88
($ this ->upgradeSize )($ size );
90
89
}
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
+ }
91
101
}
Original file line number Diff line number Diff line change @@ -12,6 +12,6 @@ public function testIncreaseWithoutCallback(): void
12
12
{
13
13
$ body = new RequestBody (new ReadableBuffer ("foobar " ));
14
14
$ body ->increaseSizeLimit (1 );
15
- $ this ->assertSame ("foobar " , $ body -> buffer () );
15
+ $ this ->assertSame ("foobar " , ( string ) $ body );
16
16
}
17
17
}
You can’t perform that action at this time.
0 commit comments