Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
HTTP_Request Class Reference

Public Member Functions

 HTTP_Request ($url= '', $params=array())
 
 _generateHostHeader ()
 
 reset ($url, $params=array())
 
 setURL ($url)
 
 getUrl ()
 
 setProxy ($host, $port=8080, $user=null, $pass=null)
 
 setBasicAuth ($user, $pass)
 
 setMethod ($method)
 
 setHttpVer ($http)
 
 addHeader ($name, $value)
 
 removeHeader ($name)
 
 addQueryString ($name, $value, $preencoded=false)
 
 addRawQueryString ($querystring, $preencoded=true)
 
 addPostData ($name, $value, $preencoded=false)
 
 _arrayMapRecursive ($callback, $value)
 
 addFile ($inputName, $fileName, $contentType= 'application/octet-stream')
 
 addRawPostData ($postdata, $preencoded=true)
 
 setBody ($body)
 
 clearPostData ()
 
 addCookie ($name, $value)
 
 clearCookies ()
 
 sendRequest ($saveBody=true)
 
 disconnect ()
 
 getResponseCode ()
 
 getResponseReason ()
 
 getResponseHeader ($headername=null)
 
 getResponseBody ()
 
 getResponseCookies ()
 
 getEncodedPath ()
 
 _buildRequest ()
 
 _flattenArray ($name, $values)
 
 attach (&$listener)
 
 detach (&$listener)
 
 _notify ($event, $data=null)
 

Data Fields

 $_url
 
 $_method
 
 $_http
 
 $_requestHeaders
 
 $_user
 
 $_pass
 
 $_sock
 
 $_proxy_host
 
 $_proxy_port
 
 $_proxy_user
 
 $_proxy_pass
 
 $_postData
 
 $_body
 
 $_bodyDisallowed = array('TRACE')
 
 $_bodyRequired = array('POST', 'PUT')
 
 $_postFiles = array()
 
 $_timeout
 
 $_response
 
 $_allowRedirects
 
 $_maxRedirects
 
 $_redirects
 
 $_useBrackets = true
 
 $_listeners = array()
 
 $_saveBody = true
 
 $_readTimeout = null
 
 $_socketOptions = null
 

Detailed Description

Definition at line 123 of file Request.php.

Member Function Documentation

_arrayMapRecursive (   $callback,
  $value 
)

Recursively applies the callback function to the value

Parameters
mixedCallback function
mixedValue to process private
Returns
mixed Processed value

Definition at line 573 of file Request.php.

_buildRequest ( )

Builds the request string

private

Returns
string The request string

Definition at line 960 of file Request.php.

_flattenArray (   $name,
  $values 
)

Helper function to change the (probably multidimensional) associative array into the simple one.

Parameters
stringname for item
mixeditem's values
Returns
array array with the following items: array('item name', 'item value'); private

Definition at line 1084 of file Request.php.

_generateHostHeader ( )

Generates a Host header for HTTP/1.1 requests

private

Returns
string

Definition at line 373 of file Request.php.

_notify (   $event,
  $data = null 
)

Notifies all registered listeners of an event.

Parameters
stringEvent name
mixedAdditional data private
See Also
HTTP_Request::attach()

Definition at line 1160 of file Request.php.

addCookie (   $name,
  $value 
)

Appends a cookie to "Cookie:" header

Parameters
string$namecookie name
string$valuecookie value public

Definition at line 665 of file Request.php.

addFile (   $inputName,
  $fileName,
  $contentType = 'application/octet-stream' 
)

Adds a file to form-based file upload

Used to emulate file upload via a HTML form. The method also sets Content-Type of HTTP request to 'multipart/form-data'.

If you just want to send the contents of a file as the body of HTTP request you should use setBody() method.

public

Parameters
stringname of file-upload field
mixedfile name(s)
mixedcontent-type(s) of file(s) being uploaded
Returns
bool true on success
Exceptions
PEAR_Error

Definition at line 602 of file Request.php.

addHeader (   $name,
  $value 
)

Adds a request header

Parameters
stringHeader name
stringHeader value public

Definition at line 505 of file Request.php.

addPostData (   $name,
  $value,
  $preencoded = false 
)

Adds postdata items

Parameters
stringPost data name
stringPost data value
boolWhether data is already urlencoded or not, default = not public

Definition at line 556 of file Request.php.

addQueryString (   $name,
  $value,
  $preencoded = false 
)

Adds a querystring parameter

Parameters
stringQuerystring parameter name
stringQuerystring parameter value
boolWhether the value is already urlencoded or not, default = not public

Definition at line 531 of file Request.php.

addRawPostData (   $postdata,
  $preencoded = true 
)

Adds raw postdata (DEPRECATED)

Parameters
stringThe data
boolWhether data is preencoded or not, default = already encoded public
Deprecated:
deprecated since 1.3.0, method setBody() should be used instead

Definition at line 629 of file Request.php.

addRawQueryString (   $querystring,
  $preencoded = true 
)

Sets the querystring to literally what you supply

Parameters
stringThe querystring data. Should be of the format foo=bar&x=y etc
boolWhether data is already urlencoded or not, default = already encoded public

Definition at line 543 of file Request.php.

attach ( $listener)

Adds a Listener to the list of listeners that are notified of the object's events

Events sent by HTTP_Request object

  • 'connect': on connection to server
  • 'sentRequest': after the request was sent
  • 'disconnect': on disconnection from server

Events sent by HTTP_Response object

  • 'gotHeaders': after receiving response headers (headers are passed in $data)
  • 'tick': on receiving a part of response body (the part is passed in $data)
  • 'gzTick': on receiving a gzip-encoded part of response body (ditto)
  • 'gotBody': after receiving the response body (passes the decoded body in $data if it was gzipped)
Parameters
HTTP_Request_Listenerlistener to attach
Returns
boolean whether the listener was successfully attached public

Definition at line 1124 of file Request.php.

clearCookies ( )

Clears any cookies that have been added (DEPRECATED).

Useful for multiple request scenarios

public

Deprecated:
deprecated since 1.2

Definition at line 679 of file Request.php.

clearPostData ( )

Clears any postdata that has been added (DEPRECATED).

Useful for multiple request scenarios.

public

Deprecated:
deprecated since 1.2

Definition at line 653 of file Request.php.

detach ( $listener)

Removes a Listener from the list of listeners

Parameters
HTTP_Request_Listenerlistener to detach
Returns
boolean whether the listener was successfully detached public

Definition at line 1141 of file Request.php.

disconnect ( )

Disconnect the socket, if connected. Only useful if using Keep-Alive.

public

Definition at line 838 of file Request.php.

getEncodedPath ( )

NOTE: Not included in HTTP_Request v.1.4.4 - i.e. this is a Matrix patch

Returns encoded path

Result is properly encoded and ready for use in the request. Complies with RFC 2396 - Uniform Resource Identifiers (URI): Generic Syntax Does not modify the internal state

Code Based on work by: By Esben Maal?e esm-at-baseclass.modulweb.dk see: http://baseclass.modulweb.dk/urlvalidator

Author
Andrei Railean arail.nosp@m.ean@.nosp@m.squiz.nosp@m..net
Returns
string Path public

Definition at line 925 of file Request.php.

getResponseBody ( )

Returns the body of the response

public

Returns
mixed response body, false if not set

Definition at line 892 of file Request.php.

getResponseCode ( )

Returns the response code

public

Returns
mixed Response code, false if not set

Definition at line 852 of file Request.php.

getResponseCookies ( )

Returns cookies set in response

public

Returns
mixed array of response cookies, false if none are present

Definition at line 903 of file Request.php.

getResponseHeader (   $headername = null)

Returns either the named header or all if no name given

public

Parameters
stringThe header name to return, do not set to get all headers
Returns
mixed either the value of $headername (false if header is not present) or an array of all headers

Definition at line 876 of file Request.php.

getResponseReason ( )

Returns the response reason phrase

public

Returns
mixed Response reason phrase, false if not set

Definition at line 863 of file Request.php.

getUrl ( )

Returns the current request URL

Returns
string Current request URL public

Definition at line 436 of file Request.php.

HTTP_Request (   $url = '',
  $params = array() 
)

#@- Constructor

Sets up the object

Parameters
stringThe url to fetch/access
arrayAssociative array of parameters which can have the following keys:
  • method - Method to use, GET, POST etc (string)
  • http - HTTP Version to use, 1.0 or 1.1 (string)
  • user - Basic Auth username (string)
  • pass - Basic Auth password (string)
  • proxy_host - Proxy server host (string)
  • proxy_port - Proxy server port (integer)
  • proxy_user - Proxy auth username (string)
  • proxy_pass - Proxy auth password (string)
  • timeout - Connection timeout in seconds (float)
  • allowRedirects - Whether to follow redirects or not (bool)
  • maxRedirects - Max number of redirects to follow (integer)
  • useBrackets - Whether to append [] to array variable names (bool)
  • saveBody - Whether to save response body in response object property (bool)
  • readTimeout - Timeout for reading / writing data over the socket (array (seconds, microseconds))
  • socketOptions - Options to pass to Net_Socket object (array)
public

Definition at line 314 of file Request.php.

removeHeader (   $name)

Removes a request header

Parameters
stringHeader name to remove public

Definition at line 516 of file Request.php.

reset (   $url,
  $params = array() 
)

Resets the object to its initial state (DEPRECATED). Takes the same parameters as the constructor.

Parameters
string$urlThe url to be requested
array$paramsAssociative array of parameters (see constructor for details) public
Deprecated:
deprecated since 1.2, call the constructor if this is necessary

Definition at line 401 of file Request.php.

sendRequest (   $saveBody = true)

Sends the request

public

Parameters
boolWhether to store response body in Response object property, set this to false if downloading a LARGE file and using a Listener
Returns
mixed PEAR error on error, true otherwise

Definition at line 692 of file Request.php.

setBasicAuth (   $user,
  $pass 
)

Sets basic authentication parameters

Parameters
stringUsername
stringPassword

Definition at line 468 of file Request.php.

setBody (   $body)

Sets the request body (for POST, PUT and similar requests)

Parameters
stringRequest body public

Definition at line 640 of file Request.php.

setHttpVer (   $http)

Sets the HTTP version to use, 1.0 or 1.1

Parameters
stringVersion to use. Use the defined constants for this public

Definition at line 493 of file Request.php.

setMethod (   $method)

Sets the method to be used, GET, POST etc.

Parameters
stringMethod to use. Use the defined constants for this public

Definition at line 482 of file Request.php.

setProxy (   $host,
  $port = 8080,
  $user = null,
  $pass = null 
)

Sets a proxy to be used

Parameters
stringProxy host
intProxy port
stringProxy username
stringProxy password public

Definition at line 450 of file Request.php.

setURL (   $url)

Sets the URL to be requested

Parameters
stringThe url to be requested public

Definition at line 412 of file Request.php.


The documentation for this class was generated from the following file: