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

Commit cd532c0

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 cd532c0

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

Runtime.php

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -79,45 +79,48 @@ public static function getUri()
7979
*/
8080
public static function getData($extended = true)
8181
{
82-
switch (static::getMethod()) {
82+
$input = null;
83+
$method = static::getMethod();
84+
$contentType = static::getHeader('Content-Type');
85+
86+
// map data
87+
switch ($method) {
8388
case Request::METHOD_GET:
84-
return $_GET;
89+
$input = $_GET;
90+
break;
8591

8692
case Request::METHOD_POST:
87-
$contentType = static::getHeader('Content-Type');
88-
89-
switch ($contentType) {
90-
case 'application/x-www-form-urlencoded':
91-
return $_POST;
93+
$input = $_POST;
94+
break;
95+
}
9296

93-
case 'application/json':
94-
$input = file_get_contents('php://input');
97+
switch ($contentType) {
98+
case 'application/x-www-form-urlencoded':
99+
if (null === $input) {
100+
$content = file_get_contents('php://input');
101+
parse_str($content, $input);
102+
}
95103

96-
if (true !== $extended ||
97-
true !== function_exists('json_decode')) {
98-
return $input;
99-
}
104+
return $input;
100105

101-
$json = json_decode($input, true);
106+
case 'application/json':
107+
$input = file_get_contents('php://input');
102108

103-
if (JSON_ERROR_NONE !== json_last_error()) {
104-
return $input;
105-
}
109+
if (true !== $extended ||
110+
true !== function_exists('json_decode')) {
111+
return $input;
112+
}
106113

107-
return $json;
114+
$json = json_decode($input, true);
108115

109-
default:
110-
return file_get_contents('php://input');
116+
if (JSON_ERROR_NONE !== json_last_error()) {
117+
return $input;
111118
}
112119

113-
break;
114-
115-
case Request::METHOD_PUT:
116-
case Request::METHOD_PATCH:
117-
return file_get_contents('php://input');
120+
return $json;
118121

119122
default:
120-
return null;
123+
return file_get_contents('php://input');
121124
}
122125
}
123126

0 commit comments

Comments
 (0)