Moodle  2.2.1
http://www.collinsharper.com
Zend_Http_Client Class Reference
Inheritance diagram for Zend_Http_Client:

Public Member Functions

 __construct ($uri=null, $config=null)
 setUri ($uri)
 getUri ($as_string=false)
 setConfig ($config=array())
 setMethod ($method=self::GET)
 setHeaders ($name, $value=null)
 getHeader ($key)
 setParameterGet ($name, $value=null)
 setParameterPost ($name, $value=null)
 getRedirectionsCount ()
 setAuth ($user, $password= '', $type=self::AUTH_BASIC)
 setCookieJar ($cookiejar=true)
 getCookieJar ()
 setCookie ($cookie, $value=null)
 setFileUpload ($filename, $formname, $data=null, $ctype=null)
 setEncType ($enctype=self::ENC_URLENCODED)
 setRawData ($data, $enctype=null)
 resetParameters ($clearAll=false)
 getLastRequest ()
 getLastResponse ()
 setAdapter ($adapter)
 getAdapter ()
 setStream ($streamfile=true)
 getStream ()
 request ($method=null)

Static Public Member Functions

static encodeFormData ($boundary, $name, $value, $filename=null, $headers=array())
static encodeAuthHeader ($user, $password, $type=self::AUTH_BASIC)

Data Fields

const GET = 'GET'
const POST = 'POST'
const PUT = 'PUT'
const HEAD = 'HEAD'
const DELETE = 'DELETE'
const TRACE = 'TRACE'
const OPTIONS = 'OPTIONS'
const CONNECT = 'CONNECT'
const MERGE = 'MERGE'
const AUTH_BASIC = 'basic'
const HTTP_1 = '1.1'
const HTTP_0 = '1.0'
const CONTENT_TYPE = 'Content-Type'
const CONTENT_LENGTH = 'Content-Length'
const ENC_URLENCODED = 'application/x-www-form-urlencoded'
const ENC_FORMDATA = 'multipart/form-data'

Protected Member Functions

 _setParameter ($type, $name, $value)
 _openTempStream ()
 _prepareHeaders ()
 _prepareBody ()
 _getParametersRecursive ($parray, $urlencode=false)
 _detectFileMimeType ($file)

Static Protected Member Functions

static _flattenParametersArray ($parray, $prefix=null)

Protected Attributes

 $config
 $adapter = null
 $uri = null
 $headers = array()
 $method = self::GET
 $paramsGet = array()
 $paramsPost = array()
 $enctype = null
 $raw_post_data = null
 $auth
 $files = array()
 $cookiejar = null
 $last_request = null
 $last_response = null
 $redirectCounter = 0

Static Protected Attributes

static $_fileInfoDb = null

Detailed Description

Definition at line 66 of file Client.php.


Constructor & Destructor Documentation

__construct ( uri = null,
config = null 
)

Contructor method. Will create a new HTTP client. Accepts the target URL and optionally configuration array.

Parameters:
Zend_Uri_Http | string$uri
array$configConfiguration key-value pairs.

Definition at line 249 of file Client.php.

Here is the call graph for this function:


Member Function Documentation

_detectFileMimeType ( file) [protected]

Attempt to detect the MIME type of a file using available extensions

This method will try to detect the MIME type of a file. If the fileinfo extension is available, it will be used. If not, the mime_magic extension which is deprected but is still available in many PHP setups will be tried.

If neither extension is available, the default application/octet-stream MIME type will be returned

Parameters:
string$fileFile path
Returns:
string MIME type

Definition at line 1317 of file Client.php.

Here is the caller graph for this function:

static _flattenParametersArray ( parray,
prefix = null 
) [static, protected]

Convert an array of parameters into a flat array of (key, value) pairs

Will flatten a potentially multi-dimentional array of parameters (such as POST parameters) into a flat array of (key, value) paris. In case of multi-dimentional arrays, square brackets ([]) will be added to the key to indicate an array.

Since:
1.9
Parameters:
array$parray
string$prefix
Returns:
array

Definition at line 1428 of file Client.php.

Here is the caller graph for this function:

_getParametersRecursive ( parray,
urlencode = false 
) [protected]

Helper method that gets a possibly multi-level parameters array (get or post) and flattens it.

The method returns an array of (key, value) pairs (because keys are not necessarily unique. If one of the parameters in as array, it will also add a [] suffix to the key.

This method is deprecated since Zend Framework 1.9 in favour of self::_flattenParametersArray() and will be dropped in 2.0

Deprecated:
since 1.9
Parameters:
array$parrayThe parameters array
bool$urlencodeWhether to urlencode the name and value
Returns:
array

Definition at line 1267 of file Client.php.

_openTempStream ( ) [protected]

Create temporary stream

Returns:
resource

Definition at line 904 of file Client.php.

Here is the caller graph for this function:

_prepareBody ( ) [protected]

Prepare the request body (for POST and PUT requests)

Returns:
string
Exceptions:
Zend_Http_Client_Exception
See also:
Zend_Http_Client_Exception

Reimplemented in Zend_Gdata_HttpClient.

Definition at line 1160 of file Client.php.

Here is the call graph for this function:

Here is the caller graph for this function:

_prepareHeaders ( ) [protected]

Prepare the request headers

Returns:
array

Definition at line 1079 of file Client.php.

Here is the call graph for this function:

Here is the caller graph for this function:

_setParameter ( type,
name,
value 
) [protected]

Set a GET or POST parameter - used by SetParameterGet and SetParameterPost

Parameters:
string$typeGET or POST
string$name
string$value
Returns:
null

Definition at line 493 of file Client.php.

Here is the caller graph for this function:

static encodeAuthHeader ( user,
password,
type = self::AUTH_BASIC 
) [static]

Create a HTTP authentication "Authorization:" header according to the specified user, password and authentication method.

See also:
http://www.faqs.org/rfcs/rfc2617.html
Parameters:
string$user
string$password
string$type
Returns:
string
Exceptions:
Zend_Http_Client_Exception
See also:
Zend_Http_Client_Exception
Todo:
Implement digest authentication
See also:
Zend_Http_Client_Exception

Definition at line 1383 of file Client.php.

Here is the caller graph for this function:

static encodeFormData ( boundary,
name,
value,
filename = null,
headers = array() 
) [static]

Definition at line 1353 of file Client.php.

Here is the caller graph for this function:

Load the connection adapter

Returns:
Zend_Http_Client_Adapter_Interface $adapter

Reimplemented in Zend_Gdata_HttpClient.

Definition at line 873 of file Client.php.

Return the current cookie jar or null if none.

Returns:
Zend_Http_CookieJar|null

Definition at line 612 of file Client.php.

getHeader ( key)

Get the value of a specific header

Note that if the header has more than one value, an array will be returned.

Parameters:
string$key
Returns:
string|array|null The header value or null if it is not set

Definition at line 437 of file Client.php.

Get the last HTTP request as string

Returns:
string

Definition at line 811 of file Client.php.

Get the last HTTP response received by this client

If $config['storeresponse'] is set to false, or no response was stored yet, will return null

Returns:
Zend_Http_Response or null if none

Definition at line 824 of file Client.php.

Get the number of redirections done on the last request

Returns:
int

Definition at line 518 of file Client.php.

getStream ( )

Get status of streaming for received data

Returns:
boolean|string

Definition at line 894 of file Client.php.

getUri ( as_string = false)

Get the URI for the next request

Parameters:
boolean$as_stringIf true, will return the URI as a string
Returns:
Zend_Uri_Http|string

Definition at line 299 of file Client.php.

Here is the caller graph for this function:

request ( method = null)

Send the HTTP request and return an HTTP response object

Parameters:
string$method
Returns:
Zend_Http_Response
Exceptions:
Zend_Http_Client_Exception
See also:
Zend_Http_Client_Exception
Zend_Http_Client_Exception
Zend_Http_Client_Exception
Zend_Http_Client_Exception

Definition at line 931 of file Client.php.

Here is the call graph for this function:

resetParameters ( clearAll = false)

Clear all GET and POST parameters

Should be used to reset the request parameters if the client is used for several concurrent requests.

clearAll parameter controls if we clean just parameters or also headers and last_*

Parameters:
bool$clearAllShould all data be cleared?
Returns:
Zend_Http_Client

Reimplemented in Zend_Gdata_HttpClient.

Definition at line 781 of file Client.php.

Here is the caller graph for this function:

setAdapter ( adapter)

Load the connection adapter

While this method is not called more than one for a client, it is seperated from ->request() to preserve logic and readability

Parameters:
Zend_Http_Client_Adapter_Interface | string$adapter
Returns:
null
Exceptions:
Zend_Http_Client_Exception
See also:
Zend_Http_Client_Exception
Zend_Http_Client_Exception

Reimplemented in Zend_Gdata_HttpClient.

Definition at line 839 of file Client.php.

Here is the call graph for this function:

Here is the caller graph for this function:

setAuth ( user,
password = '',
type = self::AUTH_BASIC 
)

Set HTTP authentication parameters

$type should be one of the supported types - see the self::AUTH_* constants.

To enable authentication: $this->setAuth('shahar', 'secret', Zend_Http_Client::AUTH_BASIC);

To disable authentication: $this->setAuth(false);

See also:
http://www.faqs.org/rfcs/rfc2617.html
Parameters:
string | false$userUser name or false disable authentication
string$passwordPassword
string$typeAuthentication type
Returns:
Zend_Http_Client
Exceptions:
Zend_Http_Client_Exception
See also:
Zend_Http_Client_Exception

Definition at line 546 of file Client.php.

Here is the call graph for this function:

Here is the caller graph for this function:

setConfig ( config = array())

Set configuration parameters for this HTTP client

Parameters:
Zend_Config| array $config
Returns:
Zend_Http_Client
Exceptions:
Zend_Http_Client_Exception
See also:
Zend_Http_Client_Exception

Definition at line 315 of file Client.php.

Here is the caller graph for this function:

setCookie ( cookie,
value = null 
)

Add a cookie to the request. If the client has no Cookie Jar, the cookies will be added directly to the headers array as "Cookie" headers.

Parameters:
Zend_Http_Cookie | string$cookie
string | null$valueIf "cookie" is a string, this is the cookie value.
Returns:
Zend_Http_Client
Exceptions:
Zend_Http_Client_Exception
See also:
Zend_Http_Client_Exception

Definition at line 626 of file Client.php.

Here is the call graph for this function:

setCookieJar ( cookiejar = true)

Set the HTTP client's cookie jar.

A cookie jar is an object that holds and maintains cookies across HTTP requests and responses.

Parameters:
Zend_Http_CookieJar | boolean$cookiejarExisting cookiejar object, true to create a new one, false to disable
Returns:
Zend_Http_Client
Exceptions:
Zend_Http_Client_Exception
See also:
Zend_Http_Client_Exception

Definition at line 586 of file Client.php.

setEncType ( enctype = self::ENC_URLENCODED)

Set the encoding type for POST data

Parameters:
string$enctype
Returns:
Zend_Http_Client

Definition at line 734 of file Client.php.

Here is the caller graph for this function:

setFileUpload ( filename,
formname,
data = null,
ctype = null 
)

Set a file to upload (using a POST request)

Can be used in two ways:

1. $data is null (default): $filename is treated as the name if a local file which will be read and sent. Will try to guess the content type using mime_content_type(). 2. $data is set - $filename is sent as the file name, but $data is sent as the file contents and no file is read from the file system. In this case, you need to manually set the Content-Type ($ctype) or it will default to application/octet-stream.

Parameters:
string$filenameName of file to upload, or name to save as
string$formnameName of form element to send as
string$dataData to send (if null, $filename is read and sent)
string$ctypeContent type to use (if $data is set and $ctype is null, will be application/octet-stream)
Returns:
Zend_Http_Client
Exceptions:
Zend_Http_Client_Exception
See also:
Zend_Http_Client_Exception

Definition at line 701 of file Client.php.

Here is the call graph for this function:

setHeaders ( name,
value = null 
)

Set one or more request headers

This function can be used in several ways to set the client's request headers: 1. By providing two parameters: $name as the header to set (eg. 'Host') and $value as it's value (eg. 'www.example.com'). 2. By providing a single header string as the only parameter eg. 'Host: www.example.com' 3. By providing an array of headers as the first parameter eg. array('host' => 'www.example.com', 'x-foo: bar'). In This case the function will call itself recursively for each array item.

Parameters:
string | array$nameHeader name, full header string ('Header: value') or an array of headers
mixed$valueHeader value or null
Returns:
Zend_Http_Client
Exceptions:
Zend_Http_Client_Exception
See also:
Zend_Http_Client_Exception

Definition at line 385 of file Client.php.

Here is the caller graph for this function:

setMethod ( method = self::GET)

Set the next request's method

Validated the passed method and sets it. If we have files set for POST requests, and the new method is not POST, the files are silently dropped.

Parameters:
string$method
Returns:
Zend_Http_Client
Exceptions:
Zend_Http_Client_Exception
See also:
Zend_Http_Client_Exception

Definition at line 349 of file Client.php.

Here is the call graph for this function:

Here is the caller graph for this function:

setParameterGet ( name,
value = null 
)

Set a GET parameter for the request. Wrapper around _setParameter

Parameters:
string | array$name
string$value
Returns:
Zend_Http_Client

Definition at line 454 of file Client.php.

Here is the call graph for this function:

setParameterPost ( name,
value = null 
)

Set a POST parameter for the request. Wrapper around _setParameter

Parameters:
string | array$name
string$value
Returns:
Zend_Http_Client

Definition at line 473 of file Client.php.

Here is the call graph for this function:

setRawData ( data,
enctype = null 
)

Set the raw (already encoded) POST data.

This function is here for two reasons: 1. For advanced user who would like to set their own data, already encoded 2. For backwards compatibilty: If someone uses the old post($data) method. this method will be used to set the encoded data.

$data can also be stream (such as file) from which the data will be read.

Parameters:
string | resource$data
string$enctype
Returns:
Zend_Http_Client

Definition at line 755 of file Client.php.

Here is the call graph for this function:

Here is the caller graph for this function:

setStream ( streamfile = true)

Set streaming for received data

Parameters:
string | boolean$streamfileStream file, true for temp file, false/null for no streaming
Returns:
Zend_Http_Client

Definition at line 884 of file Client.php.

Here is the call graph for this function:

setUri ( uri)

Set the URI for the next request

Parameters:
Zend_Uri_Http | string$uri
Returns:
Zend_Http_Client
Exceptions:
Zend_Http_Client_Exception
See also:
Zend_Http_Client_Exception

Definition at line 266 of file Client.php.

Here is the call graph for this function:

Here is the caller graph for this function:


Field Documentation

$_fileInfoDb = null [static, protected]

Definition at line 240 of file Client.php.

$adapter = null [protected]

Definition at line 129 of file Client.php.

$auth [protected]

Definition at line 192 of file Client.php.

$config [protected]
Initial value:
 array(
        'maxredirects'    => 5,
        'strictredirects' => false,
        'useragent'       => 'Zend_Http_Client',
        'timeout'         => 10,
        'adapter'         => 'Zend_Http_Client_Adapter_Socket',
        'httpversion'     => self::HTTP_1,
        'keepalive'       => false,
        'storeresponse'   => true,
        'strict'          => true,
        'output_stream'   => false,
        'encodecookies'   => true,
    )

Definition at line 110 of file Client.php.

$cookiejar = null [protected]

Definition at line 209 of file Client.php.

$enctype = null [protected]

Definition at line 171 of file Client.php.

$files = array() [protected]

Definition at line 202 of file Client.php.

$headers = array() [protected]

Definition at line 143 of file Client.php.

$last_request = null [protected]

Definition at line 216 of file Client.php.

$last_response = null [protected]

Definition at line 223 of file Client.php.

$method = self::GET [protected]

Definition at line 150 of file Client.php.

$paramsGet = array() [protected]

Definition at line 157 of file Client.php.

$paramsPost = array() [protected]

Definition at line 164 of file Client.php.

$raw_post_data = null [protected]

Definition at line 178 of file Client.php.

$redirectCounter = 0 [protected]

Definition at line 230 of file Client.php.

$uri = null [protected]

Definition at line 136 of file Client.php.

const AUTH_BASIC = 'basic'

Supported HTTP Authentication methods

Definition at line 84 of file Client.php.

const CONNECT = 'CONNECT'

Definition at line 78 of file Client.php.

const CONTENT_LENGTH = 'Content-Length'

Definition at line 97 of file Client.php.

const CONTENT_TYPE = 'Content-Type'

Content attributes

Definition at line 96 of file Client.php.

const DELETE = 'DELETE'

Definition at line 75 of file Client.php.

const ENC_FORMDATA = 'multipart/form-data'

Definition at line 103 of file Client.php.

const ENC_URLENCODED = 'application/x-www-form-urlencoded'

POST data encoding methods

Definition at line 102 of file Client.php.

const GET = 'GET'

HTTP request methods

Definition at line 71 of file Client.php.

const HEAD = 'HEAD'

Definition at line 74 of file Client.php.

const HTTP_0 = '1.0'

Definition at line 91 of file Client.php.

const HTTP_1 = '1.1'

HTTP protocol versions

Definition at line 90 of file Client.php.

const MERGE = 'MERGE'

Definition at line 79 of file Client.php.

const OPTIONS = 'OPTIONS'

Definition at line 77 of file Client.php.

const POST = 'POST'

Definition at line 72 of file Client.php.

const PUT = 'PUT'

Definition at line 73 of file Client.php.

const TRACE = 'TRACE'

Definition at line 76 of file Client.php.


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Enumerations