[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Source view] [Print] [Project Stats]
Requests for PHP Inspired by Requests for Python.
File Size: | 1099 lines (34 kb) |
Included or required: | 1 time |
Referenced: | 0 times |
Includes or requires: | 0 files |
Requests:: (25 methods):
__construct()
add_transport()
get_transport_class()
get_transport()
has_capabilities()
get()
head()
delete()
trace()
post()
put()
options()
patch()
request()
request_multiple()
get_default_options()
get_certificate_path()
set_certificate_path()
set_defaults()
parse_response()
parse_multiple()
decode_chunked()
flatten()
decompress()
compatible_gzinflate()
__construct() X-Ref |
This is a static class, do not instantiate it |
add_transport($transport) X-Ref |
Register a transport param: string $transport Transport class to add, must support the \WpOrg\Requests\Transport interface |
get_transport_class(array $capabilities = []) X-Ref |
Get the fully qualified class name (FQCN) for a working transport. param: array<string, bool> $capabilities Optional. Associative array of capabilities to test against, i.e. `['<capability>' => true]`. return: string FQCN of the transport to use, or an empty string if no transport was |
get_transport(array $capabilities = []) X-Ref |
Get a working transport. param: array<string, bool> $capabilities Optional. Associative array of capabilities to test against, i.e. `['<capability>' => true]`. return: \WpOrg\Requests\Transport |
has_capabilities(array $capabilities = []) X-Ref |
Checks to see if we have a transport for the capabilities requested. Supported capabilities can be found in the {@see \WpOrg\Requests\Capability} interface as constants. Example usage: `Requests::has_capabilities([Capability::SSL => true])`. param: array<string, bool> $capabilities Optional. Associative array of capabilities to test against, i.e. `['<capability>' => true]`. return: bool Whether the transport has the requested capabilities. |
get($url, $headers = [], $options = []) X-Ref |
Send a GET request |
head($url, $headers = [], $options = []) X-Ref |
Send a HEAD request |
delete($url, $headers = [], $options = []) X-Ref |
Send a DELETE request |
trace($url, $headers = [], $options = []) X-Ref |
Send a TRACE request |
post($url, $headers = [], $data = [], $options = []) X-Ref |
Send a POST request |
put($url, $headers = [], $data = [], $options = []) X-Ref |
Send a PUT request |
options($url, $headers = [], $data = [], $options = []) X-Ref |
Send an OPTIONS request |
patch($url, $headers, $data = [], $options = []) X-Ref |
Send a PATCH request Note: Unlike {@see \WpOrg\Requests\Requests::post()} and {@see \WpOrg\Requests\Requests::put()}, `$headers` is required, as the specification recommends that should send an ETag |
request($url, $headers = [], $data = [], $type = self::GET, $options = []) X-Ref |
Main interface for HTTP requests This method initiates a request and sends it via a transport before parsing. The `$options` parameter takes an associative array with the following options: - `timeout`: How long should we wait for a response? Note: for cURL, a minimum of 1 second applies, as DNS resolution operates at second-resolution only. (float, seconds with a millisecond precision, default: 10, example: 0.01) - `connect_timeout`: How long should we wait while trying to connect? (float, seconds with a millisecond precision, default: 10, example: 0.01) - `useragent`: Useragent to send to the server (string, default: php-requests/$version) - `follow_redirects`: Should we follow 3xx redirects? (boolean, default: true) - `redirects`: How many times should we redirect before erroring? (integer, default: 10) - `blocking`: Should we block processing on this request? (boolean, default: true) - `filename`: File to stream the body to instead. (string|boolean, default: false) - `auth`: Authentication handler or array of user/password details to use for Basic authentication (\WpOrg\Requests\Auth|array|boolean, default: false) - `proxy`: Proxy details to use for proxy by-passing and authentication (\WpOrg\Requests\Proxy|array|string|boolean, default: false) - `max_bytes`: Limit for the response body size. (integer|boolean, default: false) - `idn`: Enable IDN parsing (boolean, default: true) - `transport`: Custom transport. Either a class name, or a transport object. Defaults to the first working transport from {@see \WpOrg\Requests\Requests::getTransport()} (string|\WpOrg\Requests\Transport, default: {@see \WpOrg\Requests\Requests::getTransport()}) - `hooks`: Hooks handler. (\WpOrg\Requests\HookManager, default: new WpOrg\Requests\Hooks()) - `verify`: Should we verify SSL certificates? Allows passing in a custom certificate file as a string. (Using true uses the system-wide root certificate store instead, but this may have different behaviour across transports.) (string|boolean, default: certificates/cacert.pem) - `verifyname`: Should we verify the common name in the SSL certificate? (boolean, default: true) - `data_format`: How should we send the `$data` parameter? (string, one of 'query' or 'body', default: 'query' for HEAD/GET/DELETE, 'body' for POST/PUT/OPTIONS/PATCH) param: string|Stringable $url URL to request param: array $headers Extra headers to send with the request param: array|null $data Data to send either as a query string for GET/HEAD requests, or in the body for POST requests param: string $type HTTP request type (use Requests constants) param: array $options Options for the request (see description for more information) return: \WpOrg\Requests\Response |
request_multiple($requests, $options = []) X-Ref |
Send multiple HTTP requests simultaneously The `$requests` parameter takes an associative or indexed array of request fields. The key of each request can be used to match up the request with the returned data, or with the request passed into your `multiple.request.complete` callback. The request fields value is an associative array with the following keys: - `url`: Request URL Same as the `$url` parameter to {@see \WpOrg\Requests\Requests::request()} (string, required) - `headers`: Associative array of header fields. Same as the `$headers` parameter to {@see \WpOrg\Requests\Requests::request()} (array, default: `array()`) - `data`: Associative array of data fields or a string. Same as the `$data` parameter to {@see \WpOrg\Requests\Requests::request()} (array|string, default: `array()`) - `type`: HTTP request type (use \WpOrg\Requests\Requests constants). Same as the `$type` parameter to {@see \WpOrg\Requests\Requests::request()} (string, default: `\WpOrg\Requests\Requests::GET`) - `cookies`: Associative array of cookie name to value, or cookie jar. (array|\WpOrg\Requests\Cookie\Jar) If the `$options` parameter is specified, individual requests will inherit options from it. This can be used to use a single hooking system, or set all the types to `\WpOrg\Requests\Requests::POST`, for example. In addition, the `$options` parameter takes the following global options: - `complete`: A callback for when a request is complete. Takes two parameters, a \WpOrg\Requests\Response/\WpOrg\Requests\Exception reference, and the ID from the request array (Note: this can also be overridden on a per-request basis, although that's a little silly) (callback) param: array $requests Requests data (see description for more information) param: array $options Global and default options (see {@see \WpOrg\Requests\Requests::request()}) return: array Responses (either \WpOrg\Requests\Response or a \WpOrg\Requests\Exception object) |
get_default_options($multirequest = false) X-Ref |
Get the default options param: boolean $multirequest Is this a multirequest? return: array Default option values |
get_certificate_path() X-Ref |
Get default certificate path. return: string Default certificate path. |
set_certificate_path($path) X-Ref |
Set default certificate path. param: string|Stringable|bool $path Certificate path, pointing to a PEM file. |
set_defaults(&$url, &$headers, &$data, &$type, &$options) X-Ref |
Set the default values The $options parameter is updated with the results. param: string $url URL to request param: array $headers Extra headers to send with the request param: array|null $data Data to send either as a query string for GET/HEAD requests, or in the body for POST requests param: string $type HTTP request type param: array $options Options for the request return: void |
parse_response($headers, $url, $req_headers, $req_data, $options) X-Ref |
HTTP response parser param: string $headers Full response text including headers and body param: string $url Original request URL param: array $req_headers Original $headers array passed to {@link request()}, in case we need to follow redirects param: array $req_data Original $data array passed to {@link request()}, in case we need to follow redirects param: array $options Original $options array passed to {@link request()}, in case we need to follow redirects return: \WpOrg\Requests\Response |
parse_multiple(&$response, $request) X-Ref |
Callback for `transport.internal.parse_response` Internal use only. Converts a raw HTTP response to a \WpOrg\Requests\Response while still executing a multiple request. `$response` is either set to a \WpOrg\Requests\Response instance, or a \WpOrg\Requests\Exception object param: string $response Full response text including headers and body (will be overwritten with Response instance) param: array $request Request data as passed into {@see \WpOrg\Requests\Requests::request_multiple()} return: void |
decode_chunked($data) X-Ref |
Decoded a chunked body as per RFC 2616 param: string $data Chunked body return: string Decoded body |
flatten($dictionary) X-Ref |
Convert a key => value array to a 'key: value' array for headers param: iterable $dictionary Dictionary of header values return: array List of headers |
decompress($data) X-Ref |
Decompress an encoded body Implements gzip, compress and deflate. Guesses which it is by attempting to decode. param: string $data Compressed data in one of the above formats return: string Decompressed string |
compatible_gzinflate($gz_data) X-Ref |
Decompression of deflated string while staying compatible with the majority of servers. Certain Servers will return deflated data with headers which PHP's gzinflate() function cannot handle out of the box. The following function has been created from various snippets on the gzinflate() PHP documentation. Warning: Magic numbers within. Due to the potential different formats that the compressed data may be returned in, some "magic offsets" are needed to ensure proper decompression takes place. For a simple progmatic way to determine the magic offset in use, see: https://core.trac.wordpress.org/ticket/18273 param: string $gz_data String to decompress. return: string|bool False on failure. |
Generated : Thu Nov 21 08:20:01 2024 | Cross-referenced by PHPXref |