W3cubDocs

/Symfony 2.7

Symfony\Bundle\FrameworkBundle\Client

class Client extends Client

Client simulates a browser and makes requests to a Kernel object.

Methods

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

Constructor.

followRedirects(bool $followRedirect = true)

Sets whether to automatically follow redirects or not.

from Client
setMaxRedirects(int $maxRedirects)

Sets the maximum number of requests that crawler can follow.

from Client
insulate(bool $insulated = true)

Sets the insulated flag.

from Client
setServerParameters(array $server)

Sets server parameters.

from Client
setServerParameter(string $key, string $value)

Sets single server parameter.

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

Gets single server parameter for specified key.

from Client
History getHistory()

Returns the History instance.

from Client
CookieJar getCookieJar()

Returns the CookieJar instance.

from Client
Crawler|null getCrawler()

Returns the current Crawler instance.

from Client
Response|null getInternalResponse()

Returns the current BrowserKit Response instance.

from Client
Response|null getResponse()

Returns the current origin response instance.

from Client
Request|null getInternalRequest()

Returns the current BrowserKit Request instance.

from Client
Request|null getRequest()

Returns the current origin Request instance.

from Client
Crawler click(Link $link)

Clicks on a given link.

from Client
Crawler submit(Form $form, array $values = array())

Submits a form.

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

Calls a URI.

from Client
Crawler back()

Goes back in the browser history.

from Client
Crawler forward()

Goes forward in the browser history.

from Client
Crawler reload()

Reloads the current browser.

from Client
Crawler followRedirect()

Follow redirects?

from Client
restart()

Restarts the client.

from Client
ContainerInterface getContainer()

Returns the container.

KernelInterface getKernel()

Returns the kernel.

Profile getProfile()

Gets the profile associated with the current Response.

enableProfiler()

Enables the profiler for the very next request.

Details

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

Constructor.

Parameters

KernelInterface $kernel An HttpKernel instance
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

public followRedirects(bool $followRedirect = true)

Sets whether to automatically follow redirects or not.

Parameters

bool $followRedirect Whether to follow redirects

public setMaxRedirects(int $maxRedirects)

Sets the maximum number of requests that crawler can follow.

Parameters

int $maxRedirects

public 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

public setServerParameters(array $server)

Sets server parameters.

Parameters

array $server An array of server parameters

public setServerParameter(string $key, string $value)

Sets single server parameter.

Parameters

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

public 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

public History getHistory()

Returns the History instance.

Return Value

History A History instance

public CookieJar getCookieJar()

Returns the CookieJar instance.

Return Value

CookieJar A CookieJar instance

public Crawler|null getCrawler()

Returns the current Crawler instance.

Return Value

Crawler|null A Crawler instance

public Response|null getInternalResponse()

Returns the current BrowserKit Response instance.

Return Value

Response|null A BrowserKit Response instance

public Response|null 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

Response|null A Response instance

public Request|null getInternalRequest()

Returns the current BrowserKit Request instance.

Return Value

Request|null A BrowserKit Request instance

public Request|null 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

Request|null A Request instance

public Crawler click(Link $link)

Clicks on a given link.

Parameters

Link $link A Link instance

Return Value

Crawler

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

Submits a form.

Parameters

Form $form A Form instance
array $values An array of form field values

Return Value

Crawler

public 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

public Crawler back()

Goes back in the browser history.

Return Value

Crawler

public Crawler forward()

Goes forward in the browser history.

Return Value

Crawler

public Crawler reload()

Reloads the current browser.

Return Value

Crawler

public Crawler followRedirect()

Follow redirects?

Return Value

Crawler

Exceptions

LogicException If request was not a redirect

public restart()

Restarts the client.

It flushes history and all cookies.

public ContainerInterface getContainer()

Returns the container.

Return Value

ContainerInterface

public KernelInterface getKernel()

Returns the kernel.

Return Value

KernelInterface

public Profile getProfile()

Gets the profile associated with the current Response.

Return Value

Profile A Profile instance

public enableProfiler()

Enables the profiler for the very next request.

If the profiler is not enabled, the call to this method does nothing.

© 2004–2016 Fabien Potencier
Licensed under the MIT License.
http://api.symfony.com/2.7/Symfony/Bundle/FrameworkBundle/Client.html