PHP 클래스 RequestCore

파일 보기 프로젝트 열기: zblogcn/zblogphp 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$cacert_location The location of the cacert.pem file to use.
$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.
$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 ) : 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 ) : 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.
리턴 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

$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

$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