PHP Класс SimpleUserAgent, simpletest

@package SimpleTest
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__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.

Защищенные методы

Метод Описание
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.

Описание методов

__construct() публичный Метод

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

addAdditionalHeaders() защищенный Метод

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

addHeader() публичный Метод

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

ageCookies() публичный Метод

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

createHttpRequest() защищенный Метод

Builds the appropriate HTTP request object.
protected createHttpRequest ( SimpleUrl $url, $encoding ) : SimpleHttpRequest
$url SimpleUrl Target to fetch as url object.
Результат SimpleHttpRequest New request object.

createRequest() защищенный Метод

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.
Результат SimpleHttpRequest New request.

createRoute() защищенный Метод

Sets up either a direct route or via a proxy.
protected createRoute ( SimpleUrl $url ) : SimpleRoute
$url SimpleUrl Target to fetch as url object.
Результат SimpleRoute Route to take to fetch URL.

fetch() защищенный Метод

Actually make the web request.
protected fetch ( SimpleUrl $url, SimpleFormEncoding $encoding ) : SimpleHttpResponse
$url SimpleUrl Target to fetch.
$encoding SimpleFormEncoding Additional parameters for request.
Результат SimpleHttpResponse Headers and hopefully content.

fetchResponse() публичный Метод

It will also collect authentication realm information.
public fetchResponse ( string/SimpleUrl $url, SimpleEncoding $encoding ) : SimpleHttpResponse
$url string/SimpleUrl
$encoding SimpleEncoding Additional parameters for request.
Результат SimpleHttpResponse Hopefully the target page.

fetchWhileRedirected() защищенный Метод

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.
Результат SimpleHttpResponse Hopefully the target page.

getBaseCookieValue() публичный Метод

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.
Результат string/boolean

getCookieValue() публичный Метод

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.
Результат string False if not present, else the value as a string.

ignoreCookies() публичный Метод

Switches off cookie sending and recieving.
public ignoreCookies ( )

isTooManyRedirects() защищенный Метод

Test to see if the redirect limit is passed.
protected isTooManyRedirects ( integer $redirects ) : boolean
$redirects integer Count so far.
Результат boolean True if over.

restart() публичный Метод

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

setConnectionTimeout() публичный Метод

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

setCookie() публичный Метод

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() публичный Метод

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() публичный Метод

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

setReferer() публичный Метод

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() публичный Метод

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

useProxy() публичный Метод

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.