Skip to content
This repository was archived by the owner on Sep 20, 2021. It is now read-only.

Commit bfa0f51

Browse files
author
aglr
committed
If a PUT request is sent with the header "Content-Type: application/json"
the input data will be json_decode as a POST request is decoded. (depends to the '$extended' parameter)
1 parent 5da8e99 commit bfa0f51

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

Runtime.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,27 @@ public static function getData($extended = true)
114114

115115
case Request::METHOD_PUT:
116116
case Request::METHOD_PATCH:
117-
return file_get_contents('php://input');
117+
$contentType = static::getHeader('Content-Type');
118+
$input = file_get_contents('php://input');
119+
120+
switch ($contentType) {
121+
case 'application/json':
122+
if (true !== $extended ||
123+
true !== function_exists('json_decode')) {
124+
return $input;
125+
}
126+
127+
$json = json_decode($input, true);
128+
129+
if (JSON_ERROR_NONE !== json_last_error()) {
130+
return $input;
131+
}
132+
133+
return $json;
134+
135+
default:
136+
return $input;
137+
}
118138

119139
default:
120140
return null;

0 commit comments

Comments
 (0)