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;
1313class JSONContentHandler extends ContentHandler {
1414 public string $ mime_type = 'application/json ' ;
1515
16+ /**
17+ * Obtains the client's raw request body content.
18+ *
19+ * @return string The raw content from the request body.
20+ */
1621 public function get_content (): string {
1722 return file_get_contents ('php://input ' ) ?: '' ;
1823 }
1924
25+ /**
26+ * Encodes the given content as JSON.
27+ * @param mixed|null $content The content to encode.
28+ * @return mixed The encoded content.
29+ */
2030 protected function _encode (mixed $ content = null ): mixed {
2131 return $ content ? json_encode ($ content ) : [];
2232 }
2333
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+ */
2440 protected function _decode (mixed $ content = null ): mixed {
2541 # Allow empty strings, but convert it to an empty array.
2642 if (empty ($ content )) {
Original file line number Diff line number Diff line change @@ -11,10 +11,20 @@ use RESTAPI\Core\ContentHandler;
1111class URLContentHandler extends ContentHandler {
1212 public string $ mime_type = 'application/x-www-form-urlencoded ' ;
1313
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+ */
1419 public function get_content (): array {
1520 return $ _GET ;
1621 }
1722
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+ */
1828 protected function _decode (mixed $ content = null ): mixed {
1929 # Loop through each query string item and check for expected data types
2030 foreach ($ content as $ key => $ value ) {
You can’t perform that action at this time.
0 commit comments