OpenCloud/Common/Request/Curl.php

Classes

Curl

Properties

 
\OpenCloud\Common\Request\HttpRequestInterface
 
 
No 
No 

Description

The CurlRequest class is a simple wrapper to CURL functions. Not only does this permit stubbing of the interface as described under the HttpRequest interface, it could potentially allow us to replace the interface methods with other function calls in the future.
It contains common code for error handling as well as service functions that are useful. Because it is an abstract class, it cannot be called directly, and it has no publicly-visible properties.

Methods

Execute, ReturnHeaders, SetConnectTimeout, SetHeader, SetHttpTimeout, SetOption, SetRetries, __construct, _get_header_cb, close, errno, error, info, setheaders,

Execute( ) : \OpenCloud\Common\Request\OpenCloud\HttpResponse

Description

Executes the current request
This method actually performs the request using the values set previously. It throws a OpenCloud\HttpError exception on any CURL error.

Return value

Type Description
\OpenCloud\Common\Request\OpenCloud\HttpResponse

Tags

Name Description
throws

ReturnHeaders( ) : n/a

Description

Returns the headers as an array

Return value

Type Description
n/a n/a

SetConnectTimeout( integer   $value, ) : n/a

Description

Explicit method for setting the connect timeout
The connect timeout is the time it takes for the initial connection request to be established. It is different than the HTTP timeout, which is the time for the entire request to be serviced.

Arguments

Name Type Description Default
$value integer

The connection timeout in seconds. Use 0 to wait indefinitely (NOT recommended)

Return value

Type Description
n/a n/a

SetHeader( string   $name, mixed   $value, ) : n/a

Description

Sets a single header
For example, to set the content type to JSON: `$request->SetHeader('Content-Type','application/json');`

Arguments

Name Type Description Default
$name string

The name of the header

$value mixed

The value of the header

Return value

Type Description
n/a n/a

SetHttpTimeout( integer   $value, ) : n/a

Description

Explicit method for setting the HTTP timeout
The HTTP timeout is the time it takes for the HTTP request to be serviced. This value is usually larger than the connect timeout value.

Arguments

Name Type Description Default
$value integer
  • the number of seconds to wait before timing out the HTTP request.

Return value

Type Description
n/a n/a

SetOption( \OpenCloud\Common\Request\const   $name, mixed   $value, ) : n/a

Description

Sets a CURL option

Arguments

Name Type Description Default
$name \OpenCloud\Common\Request\const
  • a CURL named constant; e.g. CURLOPT_TIMEOUT
$value mixed
  • the value for the option

Return value

Type Description
n/a n/a

SetRetries(   $value, ) : n/a

Description

Sets the number of retries
If you set this to a non-zero value, then it will repeat the request up to that number.

Arguments

Name Type Description Default
$value n/a

Return value

Type Description
n/a n/a

__construct( string   $url, string   $method = 'GET', array   $options = array(), ) : n/a

Description

initializes the CURL handle and HTTP method
The constructor also sets a number of default values for options.

Arguments

Name Type Description Default
$url string

the URL to connect to

$method string

the HTTP method (default "GET")

'GET'
$options array

optional hashed array of options => value pairs

array()

Return value

Type Description
n/a n/a

_get_header_cb( mixed   $ch, string   $header, ) : n/a

Description

This is a callback method used to handle the returned HTTP headers

Arguments

Name Type Description Default
$ch mixed

a CURL handle

$header string

the header string in its entirety

Return value

Type Description
n/a n/a

close( ) : n/a

Description

Closes the HTTP request

Return value

Type Description
n/a n/a

errno( ) : n/a

Description

returns the most recent CURL error number

Return value

Type Description
n/a n/a

error( ) : n/a

Description

returns the most recent CURL error string

Return value

Type Description
n/a n/a

info( ) : n/a

Description

returns an array of information about the request

Return value

Type Description
n/a n/a

setheaders(   $array, ) : n/a

Description

Simplified method for setting lots of headers at once
This method takes an associative array of header/value pairs and calls the setheader() method on each of them.

Arguments

Name Type Description Default
$array n/a

Return value

Type Description
n/a n/a

Properties

$handle, $headers, $method, $retries, $returnheaders, $url,

  private  $handle =




  private  $headers = array()




  private  $method =




  private  $retries = 0




  private  $returnheaders = array()




  private  $url =




Documentation was generated by phpDocumentor 2.0.0b6 .

Namespaces

Packages