22
22
* method: string,
23
23
* uri: string,
24
24
* headers: array<string, list<string>>,
25
- * data ?: string|array<string, mixed> |null
25
+ * body ?: string|null
26
26
* }
27
27
*
28
28
* @extends AbstractDataTransferObject<RequestArrayShape>
@@ -32,7 +32,7 @@ class Request extends AbstractDataTransferObject
32
32
public const KEY_METHOD = 'method ' ;
33
33
public const KEY_URI = 'uri ' ;
34
34
public const KEY_HEADERS = 'headers ' ;
35
- public const KEY_DATA = 'data ' ;
35
+ public const KEY_BODY = 'body ' ;
36
36
37
37
/**
38
38
* @var HttpMethodEnum The HTTP method.
@@ -306,9 +306,9 @@ public static function getJsonSchema(): array
306
306
],
307
307
'description ' => 'The request headers. ' ,
308
308
],
309
- self ::KEY_DATA => [
310
- 'type ' => ['string ' , 'array ' , ' null ' ],
311
- 'description ' => 'The request data . ' ,
309
+ self ::KEY_BODY => [
310
+ 'type ' => ['string ' , 'null ' ],
311
+ 'description ' => 'The request body . ' ,
312
312
],
313
313
],
314
314
'required ' => [self ::KEY_METHOD , self ::KEY_URI , self ::KEY_HEADERS ],
@@ -326,15 +326,14 @@ public function toArray(): array
326
326
{
327
327
$ array = [
328
328
self ::KEY_METHOD => $ this ->method ->value ,
329
- self ::KEY_URI => $ this ->uri ,
329
+ self ::KEY_URI => $ this ->getUri (), // Include query params if GET with data
330
330
self ::KEY_HEADERS => $ this ->headers ->getAll (),
331
331
];
332
332
333
- // Include whichever data type is set
334
- if ($ this ->body !== null ) {
335
- $ array [self ::KEY_DATA ] = $ this ->body ;
336
- } elseif ($ this ->data !== null ) {
337
- $ array [self ::KEY_DATA ] = $ this ->data ;
333
+ // Include body if present (getBody() handles the conversion)
334
+ $ body = $ this ->getBody ();
335
+ if ($ body !== null ) {
336
+ $ array [self ::KEY_BODY ] = $ body ;
338
337
}
339
338
340
339
return $ array ;
@@ -353,7 +352,7 @@ public static function fromArray(array $array): self
353
352
HttpMethodEnum::from ($ array [self ::KEY_METHOD ]),
354
353
$ array [self ::KEY_URI ],
355
354
$ array [self ::KEY_HEADERS ] ?? [],
356
- $ array [self ::KEY_DATA ] ?? null
355
+ $ array [self ::KEY_BODY ] ?? null
357
356
);
358
357
}
359
358
}
0 commit comments