PHP Класс OSS\Http\RequestCore

Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$cacert_location The location of the cacert.pem file to use.
$connect_timeout integer 连接超时时间,默认是10秒
$curl_handle The handle for the cURL object.
$curlopts Custom CURLOPT settings.
$debug_mode The state of debug mode.
$method The method by which the request is being made.
$password The password to use for the request.
$proxy Stores the proxy settings to use for the request.
$read_file File to read from while streaming up.
$read_stream The resource to read from while streaming up.
$read_stream_read The length already read from the stream.
$read_stream_size The size of the stream to read from.
$registered_streaming_read_callback The user-defined callback function to call when a stream is read from.
$registered_streaming_write_callback The user-defined callback function to call when a stream is written to.
$request_body The body being sent in the request.
$request_class The default class to use for HTTP Requests (defaults to ).
$request_headers The headers being sent in the request.
$request_url The URL being requested.
$response The response returned by the request.
$response_body The body returned by the request.
$response_class The default class to use for HTTP Responses (defaults to ).
$response_code The HTTP status code returned by the request.
$response_headers The headers returned by the request.
$response_info Additional response data.
$seek_position Stores the intended starting seek position.
$ssl_verification The state of SSL certificate verification.
$timeout integer 请求超时时间, 默认是5184000秒,6天
$useragent Default useragent string to use.
$username The username to use for the request.
$write_file File to write to while streaming down.
$write_stream The resource to write to while streaming down.

Открытые методы

Метод Описание
__construct ( string $url = null, string $proxy = null, array $helpers = null ) Constructs a new instance of this class.
__destruct ( ) Destructs the instance. Closes opened file handles.
add_header ( string $key, mixed $value ) Adds a custom HTTP header to the cURL request.
get_response_body ( ) : string Get the HTTP response body from the request.
get_response_code ( ) : string Get the HTTP response code from the request.
get_response_header ( string $header = null ) : string | array Get the HTTP response headers from the request.
prep_request ( ) : resource Prepares and adds the details of the cURL request. This can be passed along to a function.
process_response ( resource $curl_handle = null, string $response = null ) : OSS\Http\ResponseCore Take the post-processed cURL data and break it down into useful header/body/info chunks. Uses the data stored in the curl_handle and response properties unless replacement data is passed in via parameters.
register_streaming_read_callback ( string | array | function $callback ) Register a callback function to execute whenever a data stream is read from using .
register_streaming_write_callback ( string | array | function $callback ) Register a callback function to execute whenever a data stream is written to using .
remove_header ( string $key ) Removes an HTTP header from the cURL request.
send_multi_request ( array $handles, array $opt = null ) : array Sends the request using , enabling parallel requests. Uses the "rolling" method.
send_request ( boolean $parse = false ) : string Sends the request, calling necessary utility functions to update built-in properties.
set_body ( string $body ) Set the body to send in the request.
set_credentials ( string $user, string $pass ) Sets the credentials to use for authentication.
set_curlopts ( array $curlopts ) Set additional CURLOPT settings. These will merge with the default settings, and override if there is a duplicate.
set_method ( string $method ) Set the method type for the request.
set_proxy ( string $proxy ) Set the proxy to use for making requests.
set_read_file ( string $location ) Sets the file to read from while streaming up.
set_read_stream ( resource $resource, integer $size = null ) Sets the resource to read from while streaming up. Reads the stream from its current position until EOF or $size bytes have been read. If $size is not given it will be determined by and .
set_read_stream_size ( integer $size ) Sets the length in bytes to read from the stream while streaming up.
set_request_url ( string $url ) Set the URL to make the request to.
set_seek_position ( integer $position ) Set the intended starting seek position.
set_useragent ( string $ua ) Sets a custom useragent string for the class.
set_write_file ( string $location ) Sets the file to write to while streaming down.
set_write_stream ( resource $resource ) Sets the resource to write to while streaming down.
streaming_read_callback ( resource $curl_handle, resource $file_handle, integer $length ) : binary A callback function that is invoked by cURL for streaming up.
streaming_write_callback ( resource $curl_handle, binary $data ) : integer A callback function that is invoked by cURL for streaming down.

Описание методов

__construct() публичный метод

Constructs a new instance of this class.
public __construct ( string $url = null, string $proxy = null, array $helpers = null )
$url string (Optional) The URL to request or service endpoint to query.
$proxy string (Optional) The faux-url to use for proxy settings. Takes the following format: `proxy://user:pass@hostname:port`
$helpers array (Optional) An associative array of classnames to use for request, and response functionality. Gets passed in automatically by the calling class.

__destruct() публичный метод

Destructs the instance. Closes opened file handles.
public __destruct ( )

add_header() публичный метод

Adds a custom HTTP header to the cURL request.
public add_header ( string $key, mixed $value )
$key string (Required) The custom HTTP header to set.
$value mixed (Required) The value to assign to the custom HTTP header.

get_response_body() публичный метод

Get the HTTP response body from the request.
public get_response_body ( ) : string
Результат string The response body.

get_response_code() публичный метод

Get the HTTP response code from the request.
public get_response_code ( ) : string
Результат string The HTTP response code.

get_response_header() публичный метод

Get the HTTP response headers from the request.
public get_response_header ( string $header = null ) : string | array
$header string (Optional) A specific header value to return. Defaults to all headers.
Результат string | array All or selected header values.

prep_request() публичный метод

Prepares and adds the details of the cURL request. This can be passed along to a function.
public prep_request ( ) : resource
Результат resource The handle for the cURL object.

process_response() публичный метод

Take the post-processed cURL data and break it down into useful header/body/info chunks. Uses the data stored in the curl_handle and response properties unless replacement data is passed in via parameters.
public process_response ( resource $curl_handle = null, string $response = null ) : OSS\Http\ResponseCore
$curl_handle resource (Optional) The reference to the already executed cURL request.
$response string (Optional) The actual response content itself that needs to be parsed.
Результат OSS\Http\ResponseCore A object containing a parsed HTTP response.

register_streaming_read_callback() публичный метод

The user-defined callback function should accept three arguments:
  • $curl_handle - resource - Required - The cURL handle resource that represents the in-progress transfer.
  • $file_handle - resource - Required - The file handle resource that represents the file on the local file system.
  • $length - integer - Required - The length in kilobytes of the data chunk that was transferred.
public register_streaming_read_callback ( string | array | function $callback )
$callback string | array | function (Required) The callback function is called by , so you can pass the following values:
  • The name of a global function to execute, passed as a string.
  • A method to execute, passed as array('ClassName', 'MethodName').
  • An anonymous function (PHP 5.3+).

register_streaming_write_callback() публичный метод

The user-defined callback function should accept two arguments:
  • $curl_handle - resource - Required - The cURL handle resource that represents the in-progress transfer.
  • $length - integer - Required - The length in kilobytes of the data chunk that was transferred.
public register_streaming_write_callback ( string | array | function $callback )
$callback string | array | function (Required) The callback function is called by , so you can pass the following values:
  • The name of a global function to execute, passed as a string.
  • A method to execute, passed as array('ClassName', 'MethodName').
  • An anonymous function (PHP 5.3+).

remove_header() публичный метод

Removes an HTTP header from the cURL request.
public remove_header ( string $key )
$key string (Required) The custom HTTP header to set.

send_multi_request() публичный метод

Sends the request using , enabling parallel requests. Uses the "rolling" method.
public send_multi_request ( array $handles, array $opt = null ) : array
$handles array (Required) An indexed array of cURL handles to process simultaneously.
$opt array (Optional) An associative array of parameters that can have the following keys:
  • callback - string|array - Optional - The string name of a function to pass the response data to. If this is a method, pass an array where the [0] index is the class and the [1] index is the method name.
  • limit - integer - Optional - The number of simultaneous requests to make. This can be useful for scaling around slow server responses. Defaults to trusting cURLs judgement as to how many to use.
Результат array Post-processed cURL responses.

send_request() публичный метод

Sends the request, calling necessary utility functions to update built-in properties.
public send_request ( boolean $parse = false ) : string
$parse boolean (Optional) Whether to parse the response with ResponseCore or not.
Результат string The resulting unparsed data from the request.

set_body() публичный метод

Set the body to send in the request.
public set_body ( string $body )
$body string (Required) The textual content to send along in the body of the request.

set_credentials() публичный метод

Sets the credentials to use for authentication.
public set_credentials ( string $user, string $pass )
$user string (Required) The username to authenticate with.
$pass string (Required) The password to authenticate with.

set_curlopts() публичный метод

Set additional CURLOPT settings. These will merge with the default settings, and override if there is a duplicate.
public set_curlopts ( array $curlopts )
$curlopts array (Optional) A set of key-value pairs that set `CURLOPT` options. These will merge with the existing CURLOPTs, and ones passed here will override the defaults. Keys should be the `CURLOPT_*` constants, not strings.

set_method() публичный метод

Set the method type for the request.
public set_method ( string $method )
$method string (Required) One of the following constants: , , , , .

set_proxy() публичный метод

Set the proxy to use for making requests.
public set_proxy ( string $proxy )
$proxy string (Required) The faux-url to use for proxy settings. Takes the following format: `proxy://user:pass@hostname:port`

set_read_file() публичный метод

Sets the file to read from while streaming up.
public set_read_file ( string $location )
$location string (Required) The readable location to read from.

set_read_stream() публичный метод

Sets the resource to read from while streaming up. Reads the stream from its current position until EOF or $size bytes have been read. If $size is not given it will be determined by and .
public set_read_stream ( resource $resource, integer $size = null )
$resource resource (Required) The readable resource to read from.
$size integer (Optional) The size of the stream to read.

set_read_stream_size() публичный метод

Sets the length in bytes to read from the stream while streaming up.
public set_read_stream_size ( integer $size )
$size integer (Required) The length in bytes to read from the stream.

set_request_url() публичный метод

Set the URL to make the request to.
public set_request_url ( string $url )
$url string (Required) The URL to make the request to.

set_seek_position() публичный метод

Set the intended starting seek position.
public set_seek_position ( integer $position )
$position integer (Required) The byte-position of the stream to begin reading from.

set_useragent() публичный метод

Sets a custom useragent string for the class.
public set_useragent ( string $ua )
$ua string (Required) The useragent string to use.

set_write_file() публичный метод

Sets the file to write to while streaming down.
public set_write_file ( string $location )
$location string (Required) The writeable location to write to.

set_write_stream() публичный метод

Sets the resource to write to while streaming down.
public set_write_stream ( resource $resource )
$resource resource (Required) The writeable resource to write to.

streaming_read_callback() публичный метод

A callback function that is invoked by cURL for streaming up.
public streaming_read_callback ( resource $curl_handle, resource $file_handle, integer $length ) : binary
$curl_handle resource (Required) The cURL handle for the request.
$file_handle resource (Required) The open file handle resource.
$length integer (Required) The maximum number of bytes to read.
Результат binary Binary data from a stream.

streaming_write_callback() публичный метод

A callback function that is invoked by cURL for streaming down.
public streaming_write_callback ( resource $curl_handle, binary $data ) : integer
$curl_handle resource (Required) The cURL handle for the request.
$data binary (Required) The data to write.
Результат integer The number of bytes written.

Описание свойств

$cacert_location публичное свойство

The location of the cacert.pem file to use.
public $cacert_location

$connect_timeout публичное свойство

连接超时时间,默认是10秒
public int $connect_timeout
Результат integer

$curl_handle публичное свойство

The handle for the cURL object.
public $curl_handle

$curlopts публичное свойство

Custom CURLOPT settings.
public $curlopts

$debug_mode публичное свойство

The state of debug mode.
public $debug_mode

$method публичное свойство

The method by which the request is being made.
public $method

$password публичное свойство

The password to use for the request.
public $password

$proxy публичное свойство

Stores the proxy settings to use for the request.
public $proxy

$read_file публичное свойство

File to read from while streaming up.
public $read_file

$read_stream публичное свойство

The resource to read from while streaming up.
public $read_stream

$read_stream_read публичное свойство

The length already read from the stream.
public $read_stream_read

$read_stream_size публичное свойство

The size of the stream to read from.
public $read_stream_size

$registered_streaming_read_callback публичное свойство

The user-defined callback function to call when a stream is read from.
public $registered_streaming_read_callback

$registered_streaming_write_callback публичное свойство

The user-defined callback function to call when a stream is written to.
public $registered_streaming_write_callback

$request_body публичное свойство

The body being sent in the request.
public $request_body

$request_class публичное свойство

The default class to use for HTTP Requests (defaults to ).
public $request_class

$request_headers публичное свойство

The headers being sent in the request.
public $request_headers

$request_url публичное свойство

The URL being requested.
public $request_url

$response публичное свойство

The response returned by the request.
public $response

$response_body публичное свойство

The body returned by the request.
public $response_body

$response_class публичное свойство

The default class to use for HTTP Responses (defaults to ).
public $response_class

$response_code публичное свойство

The HTTP status code returned by the request.
public $response_code

$response_headers публичное свойство

The headers returned by the request.
public $response_headers

$response_info публичное свойство

Additional response data.
public $response_info

$seek_position публичное свойство

Stores the intended starting seek position.
public $seek_position

$ssl_verification публичное свойство

The state of SSL certificate verification.
public $ssl_verification

$timeout публичное свойство

请求超时时间, 默认是5184000秒,6天
public int $timeout
Результат integer

$useragent публичное свойство

Default useragent string to use.
public $useragent

$username публичное свойство

The username to use for the request.
public $username

$write_file публичное свойство

File to write to while streaming down.
public $write_file

$write_stream публичное свойство

The resource to write to while streaming down.
public $write_stream