|
@@ -5375,16 +5375,41 @@ class Request
|
5375
|
5375
|
$this->headers = $headers;
|
5376
|
5376
|
}
|
5377
|
5377
|
|
5378
|
|
- private function parseBody(String $body = null)
|
|
5378
|
+ private function decodeBody(String $body) /*: ?object*/
|
5379
|
5379
|
{
|
5380
|
|
- if (!$body) {
|
|
5380
|
+ $first = substr($body, 0, 1);
|
|
5381
|
+ if ($first == '[' || $first == '{') {
|
|
5382
|
+ $object = json_decode($body);
|
|
5383
|
+ $causeCode = json_last_error();
|
|
5384
|
+ if ($causeCode !== JSON_ERROR_NONE) {
|
|
5385
|
+ $object = null;
|
|
5386
|
+ }
|
|
5387
|
+ } else {
|
|
5388
|
+ parse_str($body, $input);
|
|
5389
|
+ foreach ($input as $key => $value) {
|
|
5390
|
+ if (substr($key, -9) == '__is_null') {
|
|
5391
|
+ $input[substr($key, 0, -9)] = null;
|
|
5392
|
+ unset($input[$key]);
|
|
5393
|
+ }
|
|
5394
|
+ }
|
|
5395
|
+ $object = (object) $input;
|
|
5396
|
+ }
|
|
5397
|
+ return $object;
|
|
5398
|
+ }
|
|
5399
|
+
|
|
5400
|
+ private function parseBody(String $body = null) /*: void*/
|
|
5401
|
+ {
|
|
5402
|
+ if ($body) {
|
|
5403
|
+ $object = $this->decodeBody($body);
|
|
5404
|
+ } else {
|
5381
|
5405
|
if (!empty($_FILES)) {
|
5382
|
|
- $body = json_encode($_POST);
|
|
5406
|
+ $object = (object) $_POST;
|
5383
|
5407
|
} else {
|
5384
|
|
- $body = file_get_contents('php://input');
|
|
5408
|
+ $input = file_get_contents('php://input');
|
|
5409
|
+ $object = $this->decodeBody($input);
|
5385
|
5410
|
}
|
5386
|
5411
|
}
|
5387
|
|
- $this->body = $body;
|
|
5412
|
+ $this->body = $object;
|
5388
|
5413
|
}
|
5389
|
5414
|
|
5390
|
5415
|
public function getMethod(): String
|
|
@@ -5412,30 +5437,12 @@ class Request
|
5412
|
5437
|
|
5413
|
5438
|
public function getBody() /*: ?array*/
|
5414
|
5439
|
{
|
5415
|
|
- $body = $this->body;
|
5416
|
|
- $first = substr($body, 0, 1);
|
5417
|
|
- if ($first == '[' || $first == '{') {
|
5418
|
|
- $body = json_decode($body);
|
5419
|
|
- $causeCode = json_last_error();
|
5420
|
|
- if ($causeCode !== JSON_ERROR_NONE) {
|
5421
|
|
- return null;
|
5422
|
|
- }
|
5423
|
|
- } else {
|
5424
|
|
- parse_str($body, $input);
|
5425
|
|
- foreach ($input as $key => $value) {
|
5426
|
|
- if (substr($key, -9) == '__is_null') {
|
5427
|
|
- $input[substr($key, 0, -9)] = null;
|
5428
|
|
- unset($input[$key]);
|
5429
|
|
- }
|
5430
|
|
- }
|
5431
|
|
- $body = (object) $input;
|
5432
|
|
- }
|
5433
|
|
- return $body;
|
|
5440
|
+ return $this->body;
|
5434
|
5441
|
}
|
5435
|
5442
|
|
5436
|
5443
|
public function setBody($body) /*: void*/
|
5437
|
5444
|
{
|
5438
|
|
- $this->body = json_encode($body);
|
|
5445
|
+ $this->body = $body;
|
5439
|
5446
|
}
|
5440
|
5447
|
|
5441
|
5448
|
public function addHeader(String $key, String $value)
|