File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/ContentHandlers Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -13,14 +13,30 @@ use RESTAPI\Responses\ValidationError;
13
13
class JSONContentHandler extends ContentHandler {
14
14
public string $ mime_type = 'application/json ' ;
15
15
16
+ /**
17
+ * Obtains the client's raw request body content.
18
+ *
19
+ * @return string The raw content from the request body.
20
+ */
16
21
public function get_content (): string {
17
22
return file_get_contents ('php://input ' ) ?: '' ;
18
23
}
19
24
25
+ /**
26
+ * Encodes the given content as JSON.
27
+ * @param mixed|null $content The content to encode.
28
+ * @return mixed The encoded content.
29
+ */
20
30
protected function _encode (mixed $ content = null ): mixed {
21
31
return $ content ? json_encode ($ content ) : [];
22
32
}
23
33
34
+ /**
35
+ * Decodes the given content from JSON.
36
+ * @param mixed|null $content The content to decode.
37
+ * @return mixed The decoded content.
38
+ * @throws ValidationError If the content could not be decoded.
39
+ */
24
40
protected function _decode (mixed $ content = null ): mixed {
25
41
# Allow empty strings, but convert it to an empty array.
26
42
if (empty ($ content )) {
Original file line number Diff line number Diff line change @@ -11,10 +11,20 @@ use RESTAPI\Core\ContentHandler;
11
11
class URLContentHandler extends ContentHandler {
12
12
public string $ mime_type = 'application/x-www-form-urlencoded ' ;
13
13
14
+ /**
15
+ * Obtains the client's request data from PHP's $_GET superglobal.
16
+ *
17
+ * @return array The request data parsed from the query string.
18
+ */
14
19
public function get_content (): array {
15
20
return $ _GET ;
16
21
}
17
22
23
+ /**
24
+ * Decodes the given content from URL encoded data and makes basic type interference.
25
+ * @param mixed|null $content The content to decode.
26
+ * @return mixed The decode content.
27
+ */
18
28
protected function _decode (mixed $ content = null ): mixed {
19
29
# Loop through each query string item and check for expected data types
20
30
foreach ($ content as $ key => $ value ) {
You can’t perform that action at this time.
0 commit comments