PHP Class SimpleUserAgent, simpletest

@package SimpleTest
Datei anzeigen Open project: simpletest/simpletest Class Usage Examples

Public Methods

Method Description
__construct ( ) Starts with no cookies, realms or proxies.
addHeader ( string $header ) Adds a header to every fetch.
ageCookies ( integer $interval ) Ages the cookies by the specified time.
fetchResponse ( string/SimpleUrl $url, SimpleEncoding $encoding ) : SimpleHttpResponse Fetches a URL as a response object. Will keep trying if redirected.
getBaseCookieValue ( string $name, SimpleUrl $base ) : string/boolean Reads the current cookies within the base URL.
getCookieValue ( string $host, string $path, string $name ) : string Reads the most specific cookie value from the browser cookies.
ignoreCookies ( ) Switches off cookie sending and recieving.
restart ( string/integer $date = false ) Removes expired and temporary cookies as if the browser was closed and re-opened.
setConnectionTimeout ( integer $timeout ) Sets the socket timeout for opening a connection.
setCookie ( string $name, string $value, string $host = false, string $path = '/', string $expiry = false ) Sets an additional cookie. If a cookie has the same name and path it is replaced.
setIdentity ( string $host, string $realm, string $username, string $password ) Sets the identity for the current realm.
setMaximumRedirects ( integer $max ) Sets the maximum number of redirects before a page will be loaded anyway.
setReferer ( string $referer ) Sets the referrer to send with the request, as long as it is not set explicitely via {@link addHeader()}.
useCookies ( ) Switches back on the cookie sending and recieving.
useProxy ( string $proxy, string $username, string $password ) Sets proxy to use on all requests for when testing from behind a firewall.

Protected Methods

Method Description
addAdditionalHeaders ( SimpleHttpRequest &$request ) Adds additional manual headers.
createHttpRequest ( SimpleUrl $url, $encoding ) : SimpleHttpRequest Builds the appropriate HTTP request object.
createRequest ( SimpleUrl $url, SimpleFormEncoding $encoding ) : SimpleHttpRequest Creates a full page request.
createRoute ( SimpleUrl $url ) : SimpleRoute Sets up either a direct route or via a proxy.
fetch ( SimpleUrl $url, SimpleFormEncoding $encoding ) : SimpleHttpResponse Actually make the web request.
fetchWhileRedirected ( SimpleUrl $url, SimpelFormEncoding $encoding ) : SimpleHttpResponse Fetches the page until no longer redirected or until the redirect limit runs out.
isTooManyRedirects ( integer $redirects ) : boolean Test to see if the redirect limit is passed.

Method Details

__construct() public method

Starts with no cookies, realms or proxies.
public __construct ( )

addAdditionalHeaders() protected method

Adds additional manual headers.
protected addAdditionalHeaders ( SimpleHttpRequest &$request )
$request SimpleHttpRequest Outgoing request.

addHeader() public method

Adds a header to every fetch.
public addHeader ( string $header )
$header string Header line to add to every request until cleared.

ageCookies() public method

Ages the cookies by the specified time.
public ageCookies ( integer $interval )
$interval integer Amount in seconds.

createHttpRequest() protected method

Builds the appropriate HTTP request object.
protected createHttpRequest ( SimpleUrl $url, $encoding ) : SimpleHttpRequest
$url SimpleUrl Target to fetch as url object.
return SimpleHttpRequest New request object.

createRequest() protected method

Creates a full page request.
protected createRequest ( SimpleUrl $url, SimpleFormEncoding $encoding ) : SimpleHttpRequest
$url SimpleUrl Target to fetch as url object.
$encoding SimpleFormEncoding POST/GET parameters.
return SimpleHttpRequest New request.

createRoute() protected method

Sets up either a direct route or via a proxy.
protected createRoute ( SimpleUrl $url ) : SimpleRoute
$url SimpleUrl Target to fetch as url object.
return SimpleRoute Route to take to fetch URL.

fetch() protected method

Actually make the web request.
protected fetch ( SimpleUrl $url, SimpleFormEncoding $encoding ) : SimpleHttpResponse
$url SimpleUrl Target to fetch.
$encoding SimpleFormEncoding Additional parameters for request.
return SimpleHttpResponse Headers and hopefully content.

fetchResponse() public method

It will also collect authentication realm information.
public fetchResponse ( string/SimpleUrl $url, SimpleEncoding $encoding ) : SimpleHttpResponse
$url string/SimpleUrl
$encoding SimpleEncoding Additional parameters for request.
return SimpleHttpResponse Hopefully the target page.

fetchWhileRedirected() protected method

Fetches the page until no longer redirected or until the redirect limit runs out.
protected fetchWhileRedirected ( SimpleUrl $url, SimpelFormEncoding $encoding ) : SimpleHttpResponse
$url SimpleUrl Target to fetch.
$encoding SimpelFormEncoding Additional parameters for request.
return SimpleHttpResponse Hopefully the target page.

getBaseCookieValue() public method

Reads the current cookies within the base URL.
public getBaseCookieValue ( string $name, SimpleUrl $base ) : string/boolean
$name string Key of cookie to find.
$base SimpleUrl Base URL to search from.
return string/boolean

getCookieValue() public method

Reads the most specific cookie value from the browser cookies.
public getCookieValue ( string $host, string $path, string $name ) : string
$host string Host to search.
$path string Applicable path.
$name string Name of cookie to read.
return string False if not present, else the value as a string.

ignoreCookies() public method

Switches off cookie sending and recieving.
public ignoreCookies ( )

isTooManyRedirects() protected method

Test to see if the redirect limit is passed.
protected isTooManyRedirects ( integer $redirects ) : boolean
$redirects integer Count so far.
return boolean True if over.

restart() public method

Authorisation has to be obtained again as well.
public restart ( string/integer $date = false )
$date string/integer

setConnectionTimeout() public method

Sets the socket timeout for opening a connection.
public setConnectionTimeout ( integer $timeout )
$timeout integer Maximum time in seconds.

setCookie() public method

Sets an additional cookie. If a cookie has the same name and path it is replaced.
public setCookie ( string $name, string $value, string $host = false, string $path = '/', string $expiry = false )
$name string Cookie key.
$value string Value of cookie.
$host string Host upon which the cookie is valid.
$path string Cookie path if not host wide.
$expiry string Expiry date.

setIdentity() public method

Sets the identity for the current realm.
public setIdentity ( string $host, string $realm, string $username, string $password )
$host string Host to which realm applies.
$realm string Full name of realm.
$username string Username for realm.
$password string Password for realm.

setMaximumRedirects() public method

Sets the maximum number of redirects before a page will be loaded anyway.
public setMaximumRedirects ( integer $max )
$max integer Most hops allowed.

setReferer() public method

Sets the referrer to send with the request, as long as it is not set explicitely via {@link addHeader()}.
public setReferer ( string $referer )
$referer string Referer URI to add to every request until cleared.

useCookies() public method

Switches back on the cookie sending and recieving.
public useCookies ( )

useProxy() public method

Set URL to false to disable.
public useProxy ( string $proxy, string $username, string $password )
$proxy string Proxy URL.
$username string Proxy username for authentication.
$password string Proxy password for authentication.