class Client

Client simulates a browser.

To make the actual request, you need to implement the doRequest() method.

If you want to be able to run requests in their own process (insulated flag), you need to also implement the getScript() method.

Methods

__construct(array $server = array(), History $history = null, CookieJar $cookieJar = null)

No description

followRedirects(bool $followRedirect = true)

Sets whether to automatically follow redirects or not.

bool
isFollowingRedirects()

Returns whether client automatically follows redirects or not.

setMaxRedirects(int $maxRedirects)

Sets the maximum number of redirects that crawler can follow.

int
getMaxRedirects()

Returns the maximum number of redirects that crawler can follow.

insulate(bool $insulated = true)

Sets the insulated flag.

setServerParameters(array $server)

Sets server parameters.

setServerParameter(string $key, string $value)

Sets single server parameter.

string
getServerParameter(string $key, string $default = '')

Gets single server parameter for specified key.

xmlHttpRequest(string $method, string $uri, array $parameters = array(), array $files = array(), array $server = array(), string $content = null, bool $changeHistory = true)

No description

getHistory()

Returns the History instance.

getCookieJar()

Returns the CookieJar instance.

Crawler
getCrawler()

Returns the current Crawler instance.

getInternalResponse()

Returns the current BrowserKit Response instance.

object
getResponse()

Returns the current origin response instance.

getInternalRequest()

Returns the current BrowserKit Request instance.

object
getRequest()

Returns the current origin Request instance.

Crawler
click(Link $link)

Clicks on a given link.

Crawler
submit(Form $form, array $values = array(), $serverParameters = array())

Submits a form.

Crawler
request(string $method, string $uri, array $parameters = array(), array $files = array(), array $server = array(), string $content = null, bool $changeHistory = true)

Calls a URI.

Crawler
back()

Goes back in the browser history.

Crawler
forward()

Goes forward in the browser history.

Crawler
reload()

Reloads the current browser.

Crawler
followRedirect()

Follow redirects?

restart()

Restarts the client.

Details

at line line 54
__construct(array $server = array(), History $history = null, CookieJar $cookieJar = null)

Parameters

array $server The server parameters (equivalent of $_SERVER)
History $history A History instance to store the browser history
CookieJar $cookieJar A CookieJar instance to store the cookies

at line line 66
followRedirects(bool $followRedirect = true)

Sets whether to automatically follow redirects or not.

Parameters

bool $followRedirect Whether to follow redirects

at line line 76
bool isFollowingRedirects()

Returns whether client automatically follows redirects or not.

Return Value

bool

at line line 86
setMaxRedirects(int $maxRedirects)

Sets the maximum number of redirects that crawler can follow.

Parameters

int $maxRedirects

at line line 97
int getMaxRedirects()

Returns the maximum number of redirects that crawler can follow.

Return Value

int

at line line 109
insulate(bool $insulated = true)

Sets the insulated flag.

Parameters

bool $insulated Whether to insulate the requests or not

Exceptions

RuntimeException When Symfony Process Component is not installed

at line line 123
setServerParameters(array $server)

Sets server parameters.

Parameters

array $server An array of server parameters

at line line 136
setServerParameter(string $key, string $value)

Sets single server parameter.

Parameters

string $key A key of the parameter
string $value A value of the parameter

at line line 149
string getServerParameter(string $key, string $default = '')

Gets single server parameter for specified key.

Parameters

string $key A key of the parameter to get
string $default A default value when key is undefined

Return Value

string A value of the parameter

at line line 154
xmlHttpRequest(string $method, string $uri, array $parameters = array(), array $files = array(), array $server = array(), string $content = null, bool $changeHistory = true)

Parameters

string $method
string $uri
array $parameters
array $files
array $server
string $content
bool $changeHistory

at line line 170
History getHistory()

Returns the History instance.

Return Value

History A History instance

at line line 180
CookieJar getCookieJar()

Returns the CookieJar instance.

Return Value

CookieJar A CookieJar instance

at line line 190
Crawler getCrawler()

Returns the current Crawler instance.

Return Value

Crawler A Crawler instance

at line line 205
Response getInternalResponse()

Returns the current BrowserKit Response instance.

Return Value

Response A BrowserKit Response instance

at line line 225
object getResponse()

Returns the current origin response instance.

The origin response is the response instance that is returned by the code that handles requests.

Return Value

object A response instance

See also

doRequest()

at line line 240
Request getInternalRequest()

Returns the current BrowserKit Request instance.

Return Value

Request A BrowserKit Request instance

at line line 260
object getRequest()

Returns the current origin Request instance.

The origin request is the request instance that is sent to the code that handles requests.

Return Value

object A Request instance

See also

doRequest()

at line line 275
Crawler click(Link $link)

Clicks on a given link.

Parameters

Link $link

Return Value

Crawler

at line line 292
Crawler submit(Form $form, array $values = array(), $serverParameters = array())

Submits a form.

Parameters

Form $form
array $values
$serverParameters

Return Value

Crawler

at line line 312
Crawler request(string $method, string $uri, array $parameters = array(), array $files = array(), array $server = array(), string $content = null, bool $changeHistory = true)

Calls a URI.

Parameters

string $method The request method
string $uri The URI to fetch
array $parameters The Request parameters
array $files The files
array $server The server parameters (HTTP headers are referenced with a HTTP_ prefix as PHP does)
string $content The raw body data
bool $changeHistory Whether to update the history or not (only used internally for back(), forward(), and reload())

Return Value

Crawler

at line line 482
Crawler back()

Goes back in the browser history.

Return Value

Crawler

at line line 496
Crawler forward()

Goes forward in the browser history.

Return Value

Crawler

at line line 510
Crawler reload()

Reloads the current browser.

Return Value

Crawler

at line line 522
Crawler followRedirect()

Follow redirects?

Return Value

Crawler

Exceptions

LogicException If request was not a redirect

at line line 571
restart()

Restarts the client.

It flushes history and all cookies.