Client
extends HttpKernelBrowser
in package
Client simulates a browser and makes requests to a Kernel object.
Tags
Table of Contents
- $cookieJar : mixed
- $crawler : mixed
- $followMetaRefresh : mixed
- $followRedirects : mixed
- $history : mixed
- $insulated : mixed
- $internalRequest : mixed
- $internalResponse : mixed
- $kernel : mixed
- $redirect : mixed
- $request : mixed
- $response : mixed
- $server : mixed
- $catchExceptions : mixed
- $hasPerformedRequest : mixed
- $isMainRequest : mixed
- $maxRedirects : mixed
- $profiler : mixed
- $reboot : mixed
- $redirectCount : mixed
- $redirects : mixed
- __construct() : mixed
- {@inheritdoc}
- back() : Crawler
- Goes back in the browser history.
- catchExceptions() : mixed
- Sets whether to catch exceptions when the kernel is handling a request.
- click() : Crawler
- Clicks on a given link.
- clickLink() : Crawler
- Clicks the first link (or clickable image) that contains the given text.
- disableReboot() : mixed
- Disables kernel reboot between requests.
- enableProfiler() : mixed
- Enables the profiler for the very next request.
- enableReboot() : mixed
- Enables kernel reboot between requests.
- followMetaRefresh() : mixed
- Sets whether to automatically follow meta refresh redirects or not.
- followRedirect() : Crawler
- Follow redirects?
- followRedirects() : mixed
- Sets whether to automatically follow redirects or not.
- forward() : Crawler
- Goes forward in the browser history.
- getContainer() : ContainerInterface|null
- Returns the container.
- getCookieJar() : CookieJar
- Returns the CookieJar instance.
- getCrawler() : Crawler
- Returns the current Crawler instance.
- getHistory() : History
- Returns the History instance.
- getInternalRequest() : Request
- Returns the current BrowserKit Request instance.
- getInternalResponse() : Response
- Returns the current BrowserKit Response instance.
- getKernel() : KernelInterface
- Returns the kernel.
- getMaxRedirects() : int
- Returns the maximum number of redirects that crawler can follow.
- getProfile() : Profile|false|null
- Gets the profile associated with the current Response.
- getRequest() :
- getRequest() :
- getRequest() : object
- Returns the current origin Request instance.
- getResponse() :
- getResponse() : object
- Returns the current origin response instance.
- getResponse() :
- getServerParameter() : mixed
- Gets single server parameter for specified key.
- insulate() : mixed
- Sets the insulated flag.
- isFollowingRedirects() : bool
- Returns whether client automatically follows redirects or not.
- reload() : Crawler
- Reloads the current browser.
- request() : Crawler
- Calls a URI.
- restart() : mixed
- Restarts the client.
- setMaxRedirects() : mixed
- Sets the maximum number of redirects that crawler can follow.
- setServerParameter() : mixed
- Sets single server parameter.
- setServerParameters() : mixed
- Sets server parameters.
- submit() : Crawler
- Submits a form.
- submitForm() : Crawler
- Finds the first form that contains a button with the given content and uses it to submit the given form field values.
- xmlHttpRequest() : Crawler
- createCrawlerFromContent() : Crawler|null
- Creates a crawler.
- doRequest() : Response
- {@inheritdoc}
- doRequestInProcess() : Response
- {@inheritdoc}
- filterFiles() : array<string|int, mixed>
- Filters an array of files.
- filterRequest() : object
- Filters the BrowserKit request to the origin one.
- filterResponse() : Response
- Filters the origin response to the BrowserKit one.
- getAbsoluteUri() : string
- Takes a URI and converts it to absolute if it is not already absolute.
- getHandleScript() : mixed
- getScript() : string
- Returns the script to execute when the request must be insulated.
- requestFromRequest() : Crawler
- Makes a request from a Request object directly.
- extractHost() : string|null
- getMetaRefreshUrl() : string|null
- updateServerFromUri() : array<string|int, mixed>
Properties
$cookieJar
protected
mixed
$cookieJar
$crawler
protected
mixed
$crawler
$followMetaRefresh
protected
mixed
$followMetaRefresh
= false
$followRedirects
protected
mixed
$followRedirects
= true
$history
protected
mixed
$history
$insulated
protected
mixed
$insulated
= false
$internalRequest
protected
mixed
$internalRequest
$internalResponse
protected
mixed
$internalResponse
$kernel
protected
mixed
$kernel
$redirect
protected
mixed
$redirect
$request
protected
mixed
$request
$response
protected
mixed
$response
$server
protected
mixed
$server
= []
$catchExceptions
private
mixed
$catchExceptions
= true
$hasPerformedRequest
private
mixed
$hasPerformedRequest
= false
$isMainRequest
private
mixed
$isMainRequest
= true
$maxRedirects
private
mixed
$maxRedirects
= -1
$profiler
private
mixed
$profiler
= false
$reboot
private
mixed
$reboot
= true
$redirectCount
private
mixed
$redirectCount
= 0
$redirects
private
mixed
$redirects
= []
Methods
__construct()
{@inheritdoc}
public
__construct(KernelInterface $kernel[, array<string|int, mixed> $server = [] ][, History $history = null ][, CookieJar $cookieJar = null ]) : mixed
Parameters
- $kernel : KernelInterface
- $server : array<string|int, mixed> = []
- $history : History = null
- $cookieJar : CookieJar = null
Return values
mixed —back()
Goes back in the browser history.
public
back() : Crawler
Return values
Crawler —catchExceptions()
Sets whether to catch exceptions when the kernel is handling a request.
public
catchExceptions(bool $catchExceptions) : mixed
Parameters
- $catchExceptions : bool
-
Whether to catch exceptions
Return values
mixed —click()
Clicks on a given link.
public
click(Link $link) : Crawler
Parameters
- $link : Link
Return values
Crawler —clickLink()
Clicks the first link (or clickable image) that contains the given text.
public
clickLink(string $linkText) : Crawler
Parameters
- $linkText : string
-
The text of the link or the alt attribute of the clickable image
Return values
Crawler —disableReboot()
Disables kernel reboot between requests.
public
disableReboot() : mixed
By default, the Client reboots the Kernel for each request. This method allows to keep the same kernel across requests.
Return values
mixed —enableProfiler()
Enables the profiler for the very next request.
public
enableProfiler() : mixed
If the profiler is not enabled, the call to this method does nothing.
Return values
mixed —enableReboot()
Enables kernel reboot between requests.
public
enableReboot() : mixed
Return values
mixed —followMetaRefresh()
Sets whether to automatically follow meta refresh redirects or not.
public
followMetaRefresh([bool $followMetaRefresh = true ]) : mixed
Parameters
- $followMetaRefresh : bool = true
Return values
mixed —followRedirect()
Follow redirects?
public
followRedirect() : Crawler
Tags
Return values
Crawler —followRedirects()
Sets whether to automatically follow redirects or not.
public
followRedirects([bool $followRedirect = true ]) : mixed
Parameters
- $followRedirect : bool = true
-
Whether to follow redirects
Return values
mixed —forward()
Goes forward in the browser history.
public
forward() : Crawler
Return values
Crawler —getContainer()
Returns the container.
public
getContainer() : ContainerInterface|null
Return values
ContainerInterface|null —Returns null when the Kernel has been shutdown or not started yet
getCookieJar()
Returns the CookieJar instance.
public
getCookieJar() : CookieJar
Return values
CookieJar —A CookieJar instance
getCrawler()
Returns the current Crawler instance.
public
getCrawler() : Crawler
Return values
Crawler —A Crawler instance
getHistory()
Returns the History instance.
public
getHistory() : History
Return values
History —A History instance
getInternalRequest()
Returns the current BrowserKit Request instance.
public
getInternalRequest() : Request
Return values
Request —A BrowserKit Request instance
getInternalResponse()
Returns the current BrowserKit Response instance.
public
getInternalResponse() : Response
Return values
Response —A BrowserKit Response instance
getKernel()
Returns the kernel.
public
getKernel() : KernelInterface
Return values
KernelInterface —getMaxRedirects()
Returns the maximum number of redirects that crawler can follow.
public
getMaxRedirects() : int
Return values
int —getProfile()
Gets the profile associated with the current Response.
public
getProfile() : Profile|false|null
Return values
Profile|false|null —A Profile instance
getRequest()
public
getRequest() :
A Request instance
Return values
—getRequest()
public
getRequest() :
A Request instance
Return values
—getRequest()
Returns the current origin Request instance.
public
getRequest() : object
The origin request is the request instance that is sent to the code that handles requests.
Tags
Return values
object —A Request instance
getResponse()
public
getResponse() :
A Response instance
Return values
—getResponse()
Returns the current origin response instance.
public
getResponse() : object
The origin response is the response instance that is returned by the code that handles requests.
Tags
Return values
object —A response instance
getResponse()
public
getResponse() :
A Response instance
Return values
—getServerParameter()
Gets single server parameter for specified key.
public
getServerParameter(string $key[, mixed $default = '' ]) : mixed
Parameters
- $key : string
-
A key of the parameter to get
- $default : mixed = ''
-
A default value when key is undefined
Return values
mixed —A value of the parameter
insulate()
Sets the insulated flag.
public
insulate([bool $insulated = true ]) : mixed
Parameters
- $insulated : bool = true
-
Whether to insulate the requests or not
Tags
Return values
mixed —isFollowingRedirects()
Returns whether client automatically follows redirects or not.
public
isFollowingRedirects() : bool
Return values
bool —reload()
Reloads the current browser.
public
reload() : Crawler
Return values
Crawler —request()
Calls a URI.
public
request(string $method, string $uri[, array<string|int, mixed> $parameters = [] ][, array<string|int, mixed> $files = [] ][, array<string|int, mixed> $server = [] ][, string $content = null ][, bool $changeHistory = true ]) : Crawler
Parameters
- $method : string
-
The request method
- $uri : string
-
The URI to fetch
- $parameters : array<string|int, mixed> = []
-
The Request parameters
- $files : array<string|int, mixed> = []
-
The files
- $server : array<string|int, mixed> = []
-
The server parameters (HTTP headers are referenced with an HTTP_ prefix as PHP does)
- $content : string = null
-
The raw body data
- $changeHistory : bool = true
-
Whether to update the history or not (only used internally for back(), forward(), and reload())
Return values
Crawler —restart()
Restarts the client.
public
restart() : mixed
It flushes history and all cookies.
Return values
mixed —setMaxRedirects()
Sets the maximum number of redirects that crawler can follow.
public
setMaxRedirects(int $maxRedirects) : mixed
Parameters
- $maxRedirects : int
Return values
mixed —setServerParameter()
Sets single server parameter.
public
setServerParameter(string $key, string $value) : mixed
Parameters
- $key : string
-
A key of the parameter
- $value : string
-
A value of the parameter
Return values
mixed —setServerParameters()
Sets server parameters.
public
setServerParameters(array<string|int, mixed> $server) : mixed
Parameters
- $server : array<string|int, mixed>
-
An array of server parameters
Return values
mixed —submit()
Submits a form.
public
submit(Form $form[, array<string|int, mixed> $values = [] ]) : Crawler
Parameters
- $form : Form
- $values : array<string|int, mixed> = []
-
An array of form field values
Return values
Crawler —submitForm()
Finds the first form that contains a button with the given content and uses it to submit the given form field values.
public
submitForm(string $button[, array<string|int, mixed> $fieldValues = [] ][, string $method = 'POST' ][, array<string|int, mixed> $serverParameters = [] ]) : Crawler
Parameters
- $button : string
-
The text content, id, value or name of the form
- $fieldValues : array<string|int, mixed> = []
-
Use this syntax: ['my_form[name]' => '...', 'my_form[email]' => '...']
- $method : string = 'POST'
-
The HTTP method used to submit the form
- $serverParameters : array<string|int, mixed> = []
-
These values override the ones stored in $SERVER (HTTP headers must include an HTTP prefix as PHP does)
Return values
Crawler —xmlHttpRequest()
public
xmlHttpRequest(string $method, string $uri[, array<string|int, mixed> $parameters = [] ][, array<string|int, mixed> $files = [] ][, array<string|int, mixed> $server = [] ][, string $content = null ][, bool $changeHistory = true ]) : Crawler
Parameters
- $method : string
- $uri : string
- $parameters : array<string|int, mixed> = []
- $files : array<string|int, mixed> = []
- $server : array<string|int, mixed> = []
- $content : string = null
- $changeHistory : bool = true
Return values
Crawler —createCrawlerFromContent()
Creates a crawler.
protected
createCrawlerFromContent(string $uri, string $content, string $type) : Crawler|null
This method returns null if the DomCrawler component is not available.
Parameters
- $uri : string
-
A URI
- $content : string
-
Content for the crawler to use
- $type : string
-
Content type
Return values
Crawler|null —doRequest()
{@inheritdoc}
protected
doRequest(Request $request) : Response
Parameters
- $request : Request
-
A Request instance
Return values
Response —A Response instance
doRequestInProcess()
{@inheritdoc}
protected
doRequestInProcess(Request $request) : Response
Parameters
- $request : Request
-
A Request instance
Return values
Response —A Response instance
filterFiles()
Filters an array of files.
protected
filterFiles(array<string|int, mixed> $files) : array<string|int, mixed>
This method created test instances of UploadedFile so that the move() method can be called on those instances.
If the size of a file is greater than the allowed size (from php.ini) then an invalid UploadedFile is returned with an error set to UPLOAD_ERR_INI_SIZE.
Parameters
- $files : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —An array with all uploaded files marked as already moved
filterRequest()
Filters the BrowserKit request to the origin one.
protected
filterRequest(Request $request) : object
Parameters
- $request : Request
Return values
object —An origin request instance
filterResponse()
Filters the origin response to the BrowserKit one.
protected
filterResponse(object $response) : Response
Parameters
- $response : object
-
The origin response to filter
Return values
Response —An BrowserKit Response instance
getAbsoluteUri()
Takes a URI and converts it to absolute if it is not already absolute.
protected
getAbsoluteUri(string $uri) : string
Parameters
- $uri : string
-
A URI
Return values
string —An absolute URI
getHandleScript()
protected
getHandleScript() : mixed
Return values
mixed —getScript()
Returns the script to execute when the request must be insulated.
protected
getScript(Request $request) : string
It assumes that the autoloader is named 'autoload.php' and that it is stored in the same directory as the kernel (this is the case for the Symfony Standard Edition). If this is not your case, create your own client and override this method.
Parameters
- $request : Request
-
A Request instance
Return values
string —The script content
requestFromRequest()
Makes a request from a Request object directly.
protected
requestFromRequest(Request $request[, bool $changeHistory = true ]) : Crawler
Parameters
- $request : Request
- $changeHistory : bool = true
-
Whether to update the history or not (only used internally for back(), forward(), and reload())
Return values
Crawler —extractHost()
private
extractHost(string $uri) : string|null
Parameters
- $uri : string
Return values
string|null —getMetaRefreshUrl()
private
getMetaRefreshUrl() : string|null
Tags
Return values
string|null —updateServerFromUri()
private
updateServerFromUri(array<string|int, mixed> $server, string $uri) : array<string|int, mixed>
Parameters
- $server : array<string|int, mixed>
- $uri : string