PHP Class Habari\RemoteRequest

Show file Open project: habari/system

Public Methods

Method Description
__construct ( string $url, string $method = 'GET', integer $timeout = 180 )
__set_processor ( $processor ) DO NOT USE THIS FUNCTION.
add_header ( mixed $header ) Add a request header.
add_headers ( array $headers ) Add a list of headers.
execute ( ) Actually execute the request.
executed ( )
get_contents ( string $url, boolean $use_include_path = false, resource $context = null, integer $offset, integer $maxlen ) : string Static helper function to quickly fetch an URL, with semantics similar to PHP's file_get_contents. Does not support
get_response_body ( ) Return the response body. Raises a warning and returns '' if the request wasn't executed yet.
get_response_headers ( ) Return the response headers. Raises a warning and returns '' if the request wasn't executed yet.
set_body ( string $body ) Set the request body.
set_config ( mixed $config, mixed $value = null ) Set adapter configuration options
set_file ( string $name, string $filename, string $content_type = null, null $override_filename = null ) set file
set_params ( array $params ) Set the request query parameters (i.e., the URI's query string).
set_postdata ( mixed $name, string $value = null ) set postdata
set_timeout ( integer $timeout ) Set the timeout.

Private Methods

Method Description
__filter ( $data, $url ) Call the filter hook.
merge_query_params ( string $url, string $params ) Merge query params from the URL with given params.
prepare ( ) A little housekeeping.
strip_anchors ( $url ) Remove anchors (#foo) from given URL.

Method Details

__construct() public method

public __construct ( string $url, string $method = 'GET', integer $timeout = 180 )
$url string URL to request
$method string Request method to use (default 'GET')
$timeout integer

__set_processor() public method

This function is only to be used by the test case for RemoteRequest!
public __set_processor ( $processor )

add_header() public method

Add a request header.
public add_header ( mixed $header )
$header mixed The header to add, either as a string 'Name: Value' or an associative array 'name'=>'value'

add_headers() public method

Add a list of headers.
public add_headers ( array $headers )
$headers array List of headers to add.

execute() public method

On success, returns true and populates the response_body and response_headers fields. On failure, throws Exception.
public execute ( )

executed() public method

public executed ( )

get_contents() public static method

Returns the content on success or false if an error occurred.
public static get_contents ( string $url, boolean $use_include_path = false, resource $context = null, integer $offset, integer $maxlen ) : string
$url string The URL to fetch
$use_include_path boolean whether to search the PHP include path first (unsupported)
$context resource a stream context to use (unsupported)
$offset integer how many bytes to skip from the beginning of the result
$maxlen integer how many bytes to return
return string description

get_response_body() public method

Return the response body. Raises a warning and returns '' if the request wasn't executed yet.
public get_response_body ( )

get_response_headers() public method

Return the response headers. Raises a warning and returns '' if the request wasn't executed yet.

set_body() public method

Only used with POST requests, will raise a warning if used with GET.
public set_body ( string $body )
$body string The request body.

set_config() public method

Set adapter configuration options
public set_config ( mixed $config, mixed $value = null )
$config mixed An array of options or a string name with a corresponding $value
$value mixed

set_file() public method

set file
public set_file ( string $name, string $filename, string $content_type = null, null $override_filename = null )
$name string
$filename string
$content_type string
$override_filename null

set_params() public method

Will be merged with existing query info from the URL.
public set_params ( array $params )
$params array

set_postdata() public method

set postdata
public set_postdata ( mixed $name, string $value = null )
$name mixed
$value string

set_timeout() public method

Set the timeout.
public set_timeout ( integer $timeout )
$timeout integer Timeout in seconds