Skip to content

Commit 5e11fb2

Browse files
docs: add doc strings for ContentHandler classes
1 parent 10ec3e3 commit 5e11fb2

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/ContentHandlers/JSONContentHandler.inc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,30 @@ use RESTAPI\Responses\ValidationError;
1313
class 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)) {

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/ContentHandlers/URLContentHandler.inc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,20 @@ use RESTAPI\Core\ContentHandler;
1111
class 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) {

0 commit comments

Comments
 (0)