pfSense-pkg-RESTAPI

JSONContentHandler extends ContentHandler
in package

Defines a ContentHandler for JSON data. This handler is responsible for encoding and decoding JSON data for the REST API and corresponds with the 'application/json' MIME type.

Table of Contents

Constants

DEFAULT_ENCODE_MIME_TYPE  = 'application/json'

Properties

$mime_type  : string

Methods

can_decode()  : bool
Checks if this ContentHandler object is capable of decoding content.
can_encode()  : bool
Checks if this ContentHandler object is capable of encoding content.
decode()  : mixed
Obtains and decodes the content from the format corresponding with this ContentHandler's MIME type.
encode()  : mixed
Encodes the provided content into the format corresponding with this ContentHandler's MIME type and sets the Content-Type and Content-Length response headers accordingly.
get_class_fqn()  : string
Obtains the fully qualified name of the called class.
get_class_shortname()  : string
Obtains the shortname of the called class.
get_classes_in_namespace()  : array<string|int, mixed>
Obtains all classes associated with this class's current namespace.
get_content()  : mixed
Obtains the content from the remote client in its unprocessed form.
get_decode_handler()  : ContentHandler
Obtains a decode-capable ContentHandler for the MIME type provided via the HTTP Content-Type header.
get_decode_mime_type()  : string
Obtains the MIME type from the HTTP Content-Type header. The Content-Type header controls which ContentHandler will be used to decode request data sent by the remote client. If no content-header was specified, the API will assume a default of application/x-www-form-urlencoded for GET and DELETE requests and a default of application/json for POST, PUT and PATCH requests.
get_encode_handler()  : ContentHandler
Obtains an encode-capable ContentHandler for the MIME type provided via the HTTP Accept header.
get_encode_mime_type()  : string
Obtains the MIME type from the HTTP Accept header or assumes the default if no Accept header is specified. The Accept header controls which ContentHandler will be used to encode API responses.
log_error()  : void
Logs an error to the syslog.
_decode()  : mixed
Decodes the given content from JSON.
_encode()  : mixed
Encodes the given content as JSON.

Constants

DEFAULT_ENCODE_MIME_TYPE

public mixed DEFAULT_ENCODE_MIME_TYPE = 'application/json'

Properties

$mime_type

public string $mime_type = 'application/json'

The unique name for this ContentHandler. This name MUST correspond to a valid HTTP Content-Type and/or Accept type. This value is case-insensitive!

Methods

can_decode()

Checks if this ContentHandler object is capable of decoding content.

public final can_decode() : bool
Tags
throws
ReflectionException

When the _decode() method is missing entirely.

Return values
bool

Returns true if this ContentHandler can decode content, otherwise false.

can_encode()

Checks if this ContentHandler object is capable of encoding content.

public final can_encode() : bool
Tags
throws
ReflectionException

When the _encode() method is missing entirely.

Return values
bool

Returns true if this ContentHandler can encode content, otherwise false.

decode()

Obtains and decodes the content from the format corresponding with this ContentHandler's MIME type.

public final decode([mixed $content = null ]) : mixed
Parameters
$content : mixed = null

The content to be decoded in this ContentHandler's format. If no value is specified, the content will automatically be populated using the get_content() method.

Return values
mixed

The content in this ContentHandler's respective format.

encode()

Encodes the provided content into the format corresponding with this ContentHandler's MIME type and sets the Content-Type and Content-Length response headers accordingly.

public final encode(mixed $content) : mixed
Parameters
$content : mixed

The content to be encoded in this ContentHandler's format.

Return values
mixed

The content in this ContentHandler's respective format.

get_class_fqn()

Obtains the fully qualified name of the called class.

public get_class_fqn() : string
Return values
string

The FQN for this object's class.

get_class_shortname()

Obtains the shortname of the called class.

public get_class_shortname() : string
Return values
string

The shortname for this object's class.

get_classes_in_namespace()

Obtains all classes associated with this class's current namespace.

public get_classes_in_namespace([bool $shortnames = false ]) : array<string|int, mixed>
Parameters
$shortnames : bool = false
Return values
array<string|int, mixed>

An array of classes currently in this object's namespace

get_content()

Obtains the content from the remote client in its unprocessed form.

public get_content() : mixed
Tags
throws
ServerError

When this method is called but not overridden by the child class.

Return values
mixed

The unprocessed content from the remote client.

get_decode_handler()

Obtains a decode-capable ContentHandler for the MIME type provided via the HTTP Content-Type header.

public static get_decode_handler() : ContentHandler
Tags
returns

ContentHandler The decode-capable ContentHandler object with the requested $mime_type.

throws
NotAcceptableError

When the ContentHandler with the requested $mime_type does not support decoding.

throws
NotAcceptableError

When no ContentHandler exists with this $mime_type.

Return values
ContentHandler

get_decode_mime_type()

Obtains the MIME type from the HTTP Content-Type header. The Content-Type header controls which ContentHandler will be used to decode request data sent by the remote client. If no content-header was specified, the API will assume a default of application/x-www-form-urlencoded for GET and DELETE requests and a default of application/json for POST, PUT and PATCH requests.

public static get_decode_mime_type() : string
Return values
string

The MIME type to be used as requested in the HTTP Content-Header header.

get_encode_handler()

Obtains an encode-capable ContentHandler for the MIME type provided via the HTTP Accept header.

public static get_encode_handler() : ContentHandler
Tags
returns

ContentHandler The encode-capable ContentHandler object with the requested $mime_type.

throws
NotAcceptableError

When the ContentHandler with the requested $mime_type does not support encoding.

throws
NotAcceptableError

When no ContentHandler exists with this $mime_type.

Return values
ContentHandler

get_encode_mime_type()

Obtains the MIME type from the HTTP Accept header or assumes the default if no Accept header is specified. The Accept header controls which ContentHandler will be used to encode API responses.

public static get_encode_mime_type() : string
Return values
string

The MIME type to be used as requested in the HTTP Accept header.

log_error()

Logs an error to the syslog.

public static log_error(string $message) : void
Parameters
$message : string

The error message to write to the syslog

_decode()

Decodes the given content from JSON.

protected _decode([mixed|null $content = null ]) : mixed
Parameters
$content : mixed|null = null

The content to decode.

Tags
throws
ValidationError

If the content could not be decoded.

Return values
mixed

The decoded content.

_encode()

Encodes the given content as JSON.

protected _encode([mixed|null $content = null ]) : mixed
Parameters
$content : mixed|null = null

The content to encode.

Return values
mixed

The encoded content.


        
On this page

Search results