[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

title

Body

[close]

/wp-includes/rest-api/ -> class-wp-rest-request.php (summary)

REST API: WP_REST_Request class

File Size: 1013 lines (24 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

WP_REST_Request:: (43 methods):
  __construct()
  get_method()
  set_method()
  get_headers()
  canonicalize_header_name()
  get_header()
  get_header_as_array()
  set_header()
  add_header()
  remove_header()
  set_headers()
  get_content_type()
  get_parameter_order()
  get_param()
  has_param()
  set_param()
  get_params()
  get_url_params()
  set_url_params()
  get_query_params()
  set_query_params()
  get_body_params()
  set_body_params()
  get_file_params()
  set_file_params()
  get_default_params()
  set_default_params()
  get_body()
  set_body()
  get_json_params()
  parse_json_params()
  parse_body_params()
  get_route()
  set_route()
  get_attributes()
  set_attributes()
  sanitize_params()
  has_valid_params()
  offsetExists()
  offsetGet()
  offsetSet()
  offsetUnset()
  from_url()


Class: WP_REST_Request  - X-Ref

Core class used to implement a REST request object.

Contains data from the request, to be passed to the callback.

Note: This implements ArrayAccess, and acts as an array of parameters when
used in that manner. It does not use ArrayObject (as we cannot rely on SPL),
so be aware it may have non-array behaviour in some cases.

Note: When using features provided by ArrayAccess, be aware that WordPress deliberately
does not distinguish between arguments of the same name for different request methods.
For instance, in a request with `GET id=1` and `POST id=2`, `$request['id']` will equal
2 (`POST`) not 1 (`GET`). For more precision between request methods, use
WP_REST_Request::get_body_params(), WP_REST_Request::get_url_params(), etc.

__construct( $method = '', $route = '', $attributes = array()   X-Ref
Constructor.

param: string $method     Optional. Request method. Default empty.
param: string $route      Optional. Request route. Default empty.
param: array  $attributes Optional. Request attributes. Default empty array.

get_method()   X-Ref
Retrieves the HTTP method for the request.

return: string HTTP method.

set_method( $method )   X-Ref
Sets HTTP method for the request.

param: string $method HTTP method.

get_headers()   X-Ref
Retrieves all headers from the request.

return: array Map of key to value. Key is always lowercase, as per HTTP specification.

canonicalize_header_name( $key )   X-Ref
Canonicalizes the header name.

Ensures that header names are always treated the same regardless of
source. Header names are always case insensitive.

Note that we treat `-` (dashes) and `_` (underscores) as the same
character, as per header parsing rules in both Apache and nginx.

param: string $key Header name.
return: string Canonicalized name.

get_header( $key )   X-Ref
Retrieves the given header from the request.

If the header has multiple values, they will be concatenated with a comma
as per the HTTP specification. Be aware that some non-compliant headers
(notably cookie headers) cannot be joined this way.

param: string $key Header name, will be canonicalized to lowercase.
return: string|null String value if set, null otherwise.

get_header_as_array( $key )   X-Ref
Retrieves header values from the request.

param: string $key Header name, will be canonicalized to lowercase.
return: array|null List of string values if set, null otherwise.

set_header( $key, $value )   X-Ref
Sets the header on request.

param: string $key   Header name.
param: string $value Header value, or list of values.

add_header( $key, $value )   X-Ref
Appends a header value for the given header.

param: string $key   Header name.
param: string $value Header value, or list of values.

remove_header( $key )   X-Ref
Removes all values for a header.

param: string $key Header name.

set_headers( $headers, $override = true )   X-Ref
Sets headers on the request.

param: array $headers  Map of header name to value.
param: bool  $override If true, replace the request's headers. Otherwise, merge with existing.

get_content_type()   X-Ref
Retrieves the content-type of the request.

return: array|null Map containing 'value' and 'parameters' keys

get_parameter_order()   X-Ref
Retrieves the parameter priority order.

Used when checking parameters in get_param().

return: string[] Array of types to check, in order of priority.

get_param( $key )   X-Ref
Retrieves a parameter from the request.

param: string $key Parameter name.
return: mixed|null Value if set, null otherwise.

has_param( $key )   X-Ref
Checks if a parameter exists in the request.

This allows distinguishing between an omitted parameter,
and a parameter specifically set to null.

param: string $key Parameter name.
return: bool True if a param exists for the given key.

set_param( $key, $value )   X-Ref
Sets a parameter on the request.

param: string $key   Parameter name.
param: mixed  $value Parameter value.

get_params()   X-Ref
Retrieves merged parameters from the request.

The equivalent of get_param(), but returns all parameters for the request.
Handles merging all the available values into a single array.

return: array Map of key to value.

get_url_params()   X-Ref
Retrieves parameters from the route itself.

These are parsed from the URL using the regex.

return: array Parameter map of key to value.

set_url_params( $params )   X-Ref
Sets parameters from the route.

Typically, this is set after parsing the URL.

param: array $params Parameter map of key to value.

get_query_params()   X-Ref
Retrieves parameters from the query string.

These are the parameters you'd typically find in `$_GET`.

return: array Parameter map of key to value

set_query_params( $params )   X-Ref
Sets parameters from the query string.

Typically, this is set from `$_GET`.

param: array $params Parameter map of key to value.

get_body_params()   X-Ref
Retrieves parameters from the body.

These are the parameters you'd typically find in `$_POST`.

return: array Parameter map of key to value.

set_body_params( $params )   X-Ref
Sets parameters from the body.

Typically, this is set from `$_POST`.

param: array $params Parameter map of key to value.

get_file_params()   X-Ref
Retrieves multipart file parameters from the body.

These are the parameters you'd typically find in `$_FILES`.

return: array Parameter map of key to value

set_file_params( $params )   X-Ref
Sets multipart file parameters from the body.

Typically, this is set from `$_FILES`.

param: array $params Parameter map of key to value.

get_default_params()   X-Ref
Retrieves the default parameters.

These are the parameters set in the route registration.

return: array Parameter map of key to value

set_default_params( $params )   X-Ref
Sets default parameters.

These are the parameters set in the route registration.

param: array $params Parameter map of key to value.

get_body()   X-Ref
Retrieves the request body content.

return: string Binary data from the request body.

set_body( $data )   X-Ref
Sets body content.

param: string $data Binary data from the request body.

get_json_params()   X-Ref
Retrieves the parameters from a JSON-formatted body.

return: array Parameter map of key to value.

parse_json_params()   X-Ref
Parses the JSON parameters.

Avoids parsing the JSON data until we need to access it.

return: true|WP_Error True if the JSON data was passed or no JSON data was provided, WP_Error if invalid JSON was passed.

parse_body_params()   X-Ref
Parses the request body parameters.

Parses out URL-encoded bodies for request methods that aren't supported
natively by PHP. In PHP 5.x, only POST has these parsed automatically.


get_route()   X-Ref
Retrieves the route that matched the request.

return: string Route matching regex.

set_route( $route )   X-Ref
Sets the route that matched the request.

param: string $route Route matching regex.

get_attributes()   X-Ref
Retrieves the attributes for the request.

These are the options for the route that was matched.

return: array Attributes for the request.

set_attributes( $attributes )   X-Ref
Sets the attributes for the request.

param: array $attributes Attributes for the request.

sanitize_params()   X-Ref
Sanitizes (where possible) the params on the request.

This is primarily based off the sanitize_callback param on each registered
argument.

return: true|WP_Error True if parameters were sanitized, WP_Error if an error occurred during sanitization.

has_valid_params()   X-Ref
Checks whether this request is valid according to its attributes.

return: bool|WP_Error True if there are no parameters to validate or if all pass validation,

offsetExists( $offset )   X-Ref
Checks if a parameter is set.

param: string $offset Parameter name.
return: bool Whether the parameter is set.

offsetGet( $offset )   X-Ref
Retrieves a parameter from the request.

param: string $offset Parameter name.
return: mixed|null Value if set, null otherwise.

offsetSet( $offset, $value )   X-Ref
Sets a parameter on the request.

param: string $offset Parameter name.
param: mixed  $value  Parameter value.

offsetUnset( $offset )   X-Ref
Removes a parameter from the request.

param: string $offset Parameter name.

from_url( $url )   X-Ref
Retrieves a WP_REST_Request object from a full URL.

param: string $url URL with protocol, domain, path and query args.
return: WP_REST_Request|false WP_REST_Request object on success, false on failure.



Generated: Sat Nov 23 20:47:33 2019 Cross-referenced by PHPXref 0.7