URLContentHandler
extends ContentHandler
in package
Defines a ContentHandler for URL encoded data. This handler is responsible for decoding URL encoded data for the REST API and corresponds with the 'application/x-www-form-urlencoded' 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() : string|null
- Obtains the raw query string data from the request if present, otherwise obtains the raw request body.
- 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.
- infer_type() : mixed
- Infers the data type of given string values.
- log_error() : void
- Logs an error to the syslog.
- to_openapi_schema() : array<string|int, mixed>
- Converts this ContentHandler into an OpenAPI 'content' schema. This schema details which MIME types are allowed by the Accept header and also provides a reference to the schema of the Response object.
- _decode() : mixed
- Decodes the given content from URL encoded data and makes basic type interference.
- _encode() : mixed
- Defines the steps necessary to encode the given content into the correct format. This method is generally used to encode the remote client's response in the format requested by the client.
Constants
DEFAULT_ENCODE_MIME_TYPE
public
mixed
DEFAULT_ENCODE_MIME_TYPE
= 'application/json'
Properties
$mime_type
public
string
$mime_type
= 'application/x-www-form-urlencoded'
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
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
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[, Response|null $context = null ]) : mixed
Parameters
- $content : mixed
-
The content to be encoded in this ContentHandler's format. This generally the array representation of the Response object, but can be any content that needs to be encoded.
- $context : Response|null = null
-
The Response object that this content is being encoded for. This useful for ContentHandlers that need more context from the Response object that is being encoded.
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 raw query string data from the request if present, otherwise obtains the raw request body.
public
get_content() : string|null
Tags
Return values
string|null —The request data parsed from the query string.
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
Return values
ContentHandlerget_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
Return values
ContentHandlerget_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.
infer_type()
Infers the data type of given string values.
public
infer_type(string $value) : mixed
Parameters
- $value : string
-
The value to infer the data type of.
Return values
mixed —The inferred value converted to the appropriate data type.
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
to_openapi_schema()
Converts this ContentHandler into an OpenAPI 'content' schema. This schema details which MIME types are allowed by the Accept header and also provides a reference to the schema of the Response object.
public
to_openapi_schema(Response $response, Endpoint $endpoint) : array<string|int, mixed>
Parameters
- $response : Response
-
The Response object this content schema describes.
- $endpoint : Endpoint
-
The Endpoint object this content schema is being generated for.
Return values
array<string|int, mixed> —This ContentHandler as an OpenAPI 'content' schema for this MIME type in a given Response object.
_decode()
Decodes the given content from URL encoded data and makes basic type interference.
protected
_decode([mixed|null $content = null ]) : mixed
Parameters
- $content : mixed|null = null
-
The content to decode.
Return values
mixed —The decode content.
_encode()
Defines the steps necessary to encode the given content into the correct format. This method is generally used to encode the remote client's response in the format requested by the client.
protected
_encode([mixed $content = null ][, Response|null $context = null ]) : mixed
Parameters
- $content : mixed = null
-
The content to be encoded in this ContentHandler's format. This generally the array representation of the Response object, but can be any content that needs to be encoded.
- $context : Response|null = null
-
The Response object that this content is being encoded for. This useful for ContentHandlers that need more context from the Response object that is being encoded.
Tags
Return values
mixed —The content in this ContentHandler's respective format.