@@ -210,6 +210,13 @@ public function arrayBuffer():Promise {
210
210
211
211
public function awaitArrayBuffer ():ArrayBuffer {
212
212
$ arrayBuffer = null ;
213
+ if ($ bodyText = $ this ->getBody ()->getContents ()) {
214
+ $ bytes = strlen ($ bodyText );
215
+ $ arrayBuffer = new ArrayBuffer ($ bytes );
216
+ for ($ i = 0 ; $ i < $ bytes ; $ i ++) {
217
+ $ arrayBuffer ->offsetSet ($ i , ord ($ bodyText [$ i ]));
218
+ }
219
+ }
213
220
214
221
$ this ->arrayBuffer ()->then (function (ArrayBuffer $ resolved ) use (&$ arrayBuffer ) {
215
222
$ arrayBuffer = $ resolved ;
@@ -239,6 +246,12 @@ public function blob():Promise {
239
246
240
247
public function awaitBlob ():Blob {
241
248
$ blob = null ;
249
+ if ($ bodyText = $ this ->getBody ()->getContents ()) {
250
+ $ blobOptions = [
251
+ "type " => $ this ->getResponseHeaders ()->get ("content-type " )?->getValues()[0 ],
252
+ ];
253
+ $ blob = new Blob ([$ bodyText ], $ blobOptions );
254
+ }
242
255
243
256
$ this ->blob ()->then (function (Blob $ resolved ) use (&$ blob ) {
244
257
$ blob = $ resolved ;
@@ -277,6 +290,16 @@ public function formData():Promise {
277
290
278
291
public function awaitFormData ():FormData {
279
292
$ formData = null ;
293
+ if ($ bodyText = $ this ->getBody ()->getContents ()) {
294
+ parse_str ($ bodyText , $ bodyData );
295
+ $ formData = new FormData ();
296
+ foreach ($ bodyData as $ key => $ value ) {
297
+ if (is_array ($ value )) {
298
+ $ value = implode (", " , $ value );
299
+ }
300
+ $ formData ->set ((string )$ key , (string )$ value );
301
+ }
302
+ }
280
303
281
304
$ this ->blob ()->then (function (FormData $ resolved ) use (&$ formData ) {
282
305
$ formData = $ resolved ;
@@ -308,6 +331,10 @@ public function json(int $depth = 512, int $options = 0):Promise {
308
331
/** @param int<1, max> $depth */
309
332
public function awaitJson (int $ depth = 512 , int $ options = 0 ):JsonObject {
310
333
$ jsonObject = null ;
334
+ if ($ bodyText = $ this ->getBody ()->getContents ()) {
335
+ $ builder = new JsonObjectBuilder ();
336
+ $ jsonObject = $ builder ->fromJsonString ($ bodyText );
337
+ }
311
338
312
339
$ this ->json ($ depth , $ options )->then (function (JsonObject $ resolved ) use (&$ jsonObject ) {
313
340
$ jsonObject = $ resolved ;
@@ -333,7 +360,7 @@ public function text():Promise {
333
360
}
334
361
335
362
public function awaitText ():string {
336
- $ text = null ;
363
+ $ text = $ this -> getBody ()-> getContents () ;
337
364
338
365
$ this ->text ()->then (function (string $ resolved ) use (&$ text ) {
339
366
$ text = $ resolved ;
0 commit comments