PHP Class OSS\Http\RequestCore

Datei anzeigen Open project: aliyun/aliyun-oss-php-sdk Class Usage Examples

Public Properties

Property Type Description
$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.

Public Methods

Method Description
__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.

Method Details

__construct() public method

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() public method

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

add_header() public method

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() public method

Get the HTTP response body from the request.
public get_response_body ( ) : string
return string The response body.

get_response_code() public method

Get the HTTP response code from the request.
public get_response_code ( ) : string
return string The HTTP response code.

get_response_header() public method

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.
return string | array All or selected header values.

prep_request() public method

Prepares and adds the details of the cURL request. This can be passed along to a function.
public prep_request ( ) : resource
return resource The handle for the cURL object.

process_response() public method

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.
return OSS\Http\ResponseCore A object containing a parsed HTTP response.

register_streaming_read_callback() public method

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() public method

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() public method

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() public method

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.
return array Post-processed cURL responses.

send_request() public method

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.
return string The resulting unparsed data from the request.

set_body() public method

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() public method

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() public method

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() public method

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

set_proxy() public method

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() public method

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() public method

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() public method

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() public method

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() public method

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() public method

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

set_write_file() public method

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() public method

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() public method

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.
return binary Binary data from a stream.

streaming_write_callback() public method

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.
return integer The number of bytes written.

Property Details

$cacert_location public_oe property

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

$connect_timeout public_oe property

连接超时时间,默认是10秒
public int $connect_timeout
return integer

$curl_handle public_oe property

The handle for the cURL object.
public $curl_handle

$curlopts public_oe property

Custom CURLOPT settings.
public $curlopts

$debug_mode public_oe property

The state of debug mode.
public $debug_mode

$method public_oe property

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

$password public_oe property

The password to use for the request.
public $password

$proxy public_oe property

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

$read_file public_oe property

File to read from while streaming up.
public $read_file

$read_stream public_oe property

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

$read_stream_read public_oe property

The length already read from the stream.
public $read_stream_read

$read_stream_size public_oe property

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

$registered_streaming_read_callback public_oe property

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

$registered_streaming_write_callback public_oe property

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

$request_body public_oe property

The body being sent in the request.
public $request_body

$request_class public_oe property

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

$request_headers public_oe property

The headers being sent in the request.
public $request_headers

$request_url public_oe property

The URL being requested.
public $request_url

$response public_oe property

The response returned by the request.
public $response

$response_body public_oe property

The body returned by the request.
public $response_body

$response_class public_oe property

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

$response_code public_oe property

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

$response_headers public_oe property

The headers returned by the request.
public $response_headers

$response_info public_oe property

Additional response data.
public $response_info

$seek_position public_oe property

Stores the intended starting seek position.
public $seek_position

$ssl_verification public_oe property

The state of SSL certificate verification.
public $ssl_verification

$timeout public_oe property

请求超时时间, 默认是5184000秒,6天
public int $timeout
return integer

$useragent public_oe property

Default useragent string to use.
public $useragent

$username public_oe property

The username to use for the request.
public $username

$write_file public_oe property

File to write to while streaming down.
public $write_file

$write_stream public_oe property

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