PHP Class Symfony\Component\BrowserKit\Client

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.
Author: Fabien Potencier ([email protected])
Mostra file Open project: pmjones/php-framework-benchmarks Class Usage Examples

Protected Properties

Property Type Description
$cookieJar
$crawler
$followRedirects
$history
$insulated
$redirect
$request
$response
$server

Public Methods

Method Description
__construct ( array $server = [], Symfony\Component\BrowserKit\History $history = null, Symfony\Component\BrowserKit\CookieJar $cookieJar = null ) Constructor.
back ( ) : Crawler Goes back in the browser history.
click ( Symfony\Component\DomCrawler\Link $link ) Clicks on a given link.
click ( Symfony\Component\DomCrawler\Link $link ) : Crawler Clicks on a given link.
followRedirect ( ) : Crawler Follow redirects?
followRedirects ( boolean $followRedirect = true ) Sets whether to automatically follow redirects or not.
forward ( ) : Crawler Goes forward in the browser history.
getCookieJar ( ) : Symfony\Component\BrowserKit\CookieJar Returns the CookieJar instance.
getCrawler ( ) : Crawler Returns the current Crawler instance.
getHistory ( ) : Symfony\Component\BrowserKit\History Returns the History instance.
getRequest ( ) : Symfony\Component\BrowserKit\Request Returns the current Request instance.
getRequest ( ) : Symfony\Component\BrowserKit\Request Returns the current Request instance.
getResponse ( ) : Symfony\Component\BrowserKit\Response Returns the current Response instance.
getResponse ( ) : Symfony\Component\BrowserKit\Response Returns the current Response instance.
getServerParameter ( string $key, string $default = '' ) : string Gets single server parameter for specified key.
insulate ( boolean $insulated = true ) Sets the insulated flag.
reload ( ) : Crawler Reloads the current browser.
request ( string $method, string $uri, array $parameters = [], array $files = [], array $server = [], string $content = null, boolean $changeHistory = true ) : Crawler Calls a URI.
restart ( ) Restarts the client.
setServerParameter ( string $key, string $value ) Sets single server parameter.
setServerParameters ( array $server ) Sets server parameters.
submit ( Form $form, array $values = [] ) Submits a form.
submit ( Form $form, array $values = [] ) : Crawler Submits a form.

Protected Methods

Method Description
createCrawlerFromContent ( string $uri, string $content, string $type ) : Crawler Creates a crawler.
createCrawlerFromContent ( string $uri, string $content, string $type ) : Crawler | null Creates a crawler.
doRequest ( Symfony\Component\BrowserKit\Request $request ) : Symfony\Component\BrowserKit\Response Makes a request.
doRequest ( Symfony\Component\BrowserKit\Request $request ) : Symfony\Component\BrowserKit\Response Makes a request.
doRequestInProcess ( Symfony\Component\BrowserKit\Request $request ) : Symfony\Component\BrowserKit\Response Makes a request in another process.
doRequestInProcess ( Symfony\Component\BrowserKit\Request $request ) : Symfony\Component\BrowserKit\Response Makes a request in another process.
filterRequest ( Symfony\Component\BrowserKit\Request $request ) : Symfony\Component\BrowserKit\Request Filters the request.
filterRequest ( Symfony\Component\BrowserKit\Request $request ) : Symfony\Component\BrowserKit\Request Filters the request.
filterResponse ( Symfony\Component\BrowserKit\Response $response ) : Symfony\Component\BrowserKit\Response Filters the Response.
filterResponse ( Symfony\Component\BrowserKit\Response $response ) : Symfony\Component\BrowserKit\Response Filters the Response.
getAbsoluteUri ( string $uri ) : string Takes a URI and converts it to absolute if it is not already absolute.
getScript ( Symfony\Component\BrowserKit\Request $request ) Returns the script to execute when the request must be insulated.
getScript ( Symfony\Component\BrowserKit\Request $request ) Returns the script to execute when the request must be insulated.
requestFromRequest ( Symfony\Component\BrowserKit\Request $request, boolean $changeHistory = true ) : Crawler Makes a request from a Request object directly.
requestFromRequest ( Symfony\Component\BrowserKit\Request $request, boolean $changeHistory = true ) : Crawler Makes a request from a Request object directly.

Method Details

__construct() public method

Constructor.
public __construct ( array $server = [], Symfony\Component\BrowserKit\History $history = null, Symfony\Component\BrowserKit\CookieJar $cookieJar = null )
$server array The server parameters (equivalent of $_SERVER)
$history Symfony\Component\BrowserKit\History A History instance to store the browser history
$cookieJar Symfony\Component\BrowserKit\CookieJar A CookieJar instance to store the cookies

back() public method

Goes back in the browser history.
public back ( ) : Crawler
return Symfony\Component\DomCrawler\Crawler

click() public method

Clicks on a given link.
public click ( Symfony\Component\DomCrawler\Link $link )
$link Symfony\Component\DomCrawler\Link A Link instance

click() public method

Clicks on a given link.
public click ( Symfony\Component\DomCrawler\Link $link ) : Crawler
$link Symfony\Component\DomCrawler\Link A Link instance
return Symfony\Component\DomCrawler\Crawler

createCrawlerFromContent() protected method

Creates a crawler.
protected createCrawlerFromContent ( string $uri, string $content, string $type ) : Crawler
$uri string A uri
$content string Content for the crawler to use
$type string Content type
return Symfony\Component\DomCrawler\Crawler

createCrawlerFromContent() protected method

This method returns null if the DomCrawler component is not available.
protected createCrawlerFromContent ( string $uri, string $content, string $type ) : Crawler | null
$uri string A uri
$content string Content for the crawler to use
$type string Content type
return Symfony\Component\DomCrawler\Crawler | null

doRequest() abstract protected method

Makes a request.
abstract protected doRequest ( Symfony\Component\BrowserKit\Request $request ) : Symfony\Component\BrowserKit\Response
$request Symfony\Component\BrowserKit\Request A Request instance
return Symfony\Component\BrowserKit\Response A Response instance

doRequest() abstract protected method

Makes a request.
abstract protected doRequest ( Symfony\Component\BrowserKit\Request $request ) : Symfony\Component\BrowserKit\Response
$request Symfony\Component\BrowserKit\Request A Request instance
return Symfony\Component\BrowserKit\Response A Response instance

doRequestInProcess() protected method

Makes a request in another process.
protected doRequestInProcess ( Symfony\Component\BrowserKit\Request $request ) : Symfony\Component\BrowserKit\Response
$request Symfony\Component\BrowserKit\Request A Request instance
return Symfony\Component\BrowserKit\Response A Response instance

doRequestInProcess() protected method

Makes a request in another process.
protected doRequestInProcess ( Symfony\Component\BrowserKit\Request $request ) : Symfony\Component\BrowserKit\Response
$request Symfony\Component\BrowserKit\Request A Request instance
return Symfony\Component\BrowserKit\Response A Response instance

filterRequest() protected method

Filters the request.
protected filterRequest ( Symfony\Component\BrowserKit\Request $request ) : Symfony\Component\BrowserKit\Request
$request Symfony\Component\BrowserKit\Request The request to filter
return Symfony\Component\BrowserKit\Request

filterRequest() protected method

Filters the request.
protected filterRequest ( Symfony\Component\BrowserKit\Request $request ) : Symfony\Component\BrowserKit\Request
$request Symfony\Component\BrowserKit\Request The request to filter
return Symfony\Component\BrowserKit\Request

filterResponse() protected method

Filters the Response.
protected filterResponse ( Symfony\Component\BrowserKit\Response $response ) : Symfony\Component\BrowserKit\Response
$response Symfony\Component\BrowserKit\Response The Response to filter
return Symfony\Component\BrowserKit\Response

filterResponse() protected method

Filters the Response.
protected filterResponse ( Symfony\Component\BrowserKit\Response $response ) : Symfony\Component\BrowserKit\Response
$response Symfony\Component\BrowserKit\Response The Response to filter
return Symfony\Component\BrowserKit\Response

followRedirect() public method

Follow redirects?
public followRedirect ( ) : Crawler
return Symfony\Component\DomCrawler\Crawler

followRedirects() public method

Sets whether to automatically follow redirects or not.
public followRedirects ( boolean $followRedirect = true )
$followRedirect boolean Whether to follow redirects

forward() public method

Goes forward in the browser history.
public forward ( ) : Crawler
return Symfony\Component\DomCrawler\Crawler

getAbsoluteUri() protected method

Takes a URI and converts it to absolute if it is not already absolute.
protected getAbsoluteUri ( string $uri ) : string
$uri string A uri
return string An absolute uri

getCookieJar() public method

Returns the CookieJar instance.
public getCookieJar ( ) : Symfony\Component\BrowserKit\CookieJar
return Symfony\Component\BrowserKit\CookieJar A CookieJar instance

getCrawler() public method

Returns the current Crawler instance.
public getCrawler ( ) : Crawler
return Symfony\Component\DomCrawler\Crawler A Crawler instance

getHistory() public method

Returns the History instance.
public getHistory ( ) : Symfony\Component\BrowserKit\History
return Symfony\Component\BrowserKit\History A History instance

getRequest() public method

Returns the current Request instance.
public getRequest ( ) : Symfony\Component\BrowserKit\Request
return Symfony\Component\BrowserKit\Request A Request instance

getRequest() public method

Returns the current Request instance.
public getRequest ( ) : Symfony\Component\BrowserKit\Request
return Symfony\Component\BrowserKit\Request A Request instance

getResponse() public method

Returns the current Response instance.
public getResponse ( ) : Symfony\Component\BrowserKit\Response
return Symfony\Component\BrowserKit\Response A Response instance

getResponse() public method

Returns the current Response instance.
public getResponse ( ) : Symfony\Component\BrowserKit\Response
return Symfony\Component\BrowserKit\Response A Response instance

getScript() protected method

Returns the script to execute when the request must be insulated.
protected getScript ( Symfony\Component\BrowserKit\Request $request )
$request Symfony\Component\BrowserKit\Request A Request instance

getScript() protected method

Returns the script to execute when the request must be insulated.
protected getScript ( Symfony\Component\BrowserKit\Request $request )
$request Symfony\Component\BrowserKit\Request A Request instance

getServerParameter() public method

Gets single server parameter for specified key.
public getServerParameter ( string $key, string $default = '' ) : string
$key string A key of the parameter to get
$default string A default value when key is undefined
return string A value of the parameter

insulate() public method

Sets the insulated flag.
public insulate ( boolean $insulated = true )
$insulated boolean Whether to insulate the requests or not

reload() public method

Reloads the current browser.
public reload ( ) : Crawler
return Symfony\Component\DomCrawler\Crawler

request() public method

Calls a URI.
public request ( string $method, string $uri, array $parameters = [], array $files = [], array $server = [], string $content = null, boolean $changeHistory = true ) : Crawler
$method string The request method
$uri string The URI to fetch
$parameters array The Request parameters
$files array The files
$server array The server parameters (HTTP headers are referenced with a HTTP_ prefix as PHP does)
$content string The raw body data
$changeHistory boolean Whether to update the history or not (only used internally for back(), forward(), and reload())
return Symfony\Component\DomCrawler\Crawler

requestFromRequest() protected method

Makes a request from a Request object directly.
protected requestFromRequest ( Symfony\Component\BrowserKit\Request $request, boolean $changeHistory = true ) : Crawler
$request Symfony\Component\BrowserKit\Request A Request instance
$changeHistory boolean Whether to update the history or not (only used internally for back(), forward(), and reload())
return Symfony\Component\DomCrawler\Crawler

requestFromRequest() protected method

Makes a request from a Request object directly.
protected requestFromRequest ( Symfony\Component\BrowserKit\Request $request, boolean $changeHistory = true ) : Crawler
$request Symfony\Component\BrowserKit\Request A Request instance
$changeHistory boolean Whether to update the history or not (only used internally for back(), forward(), and reload())
return Symfony\Component\DomCrawler\Crawler

restart() public method

It flushes history and all cookies.
public restart ( )

setServerParameter() public method

Sets single server parameter.
public setServerParameter ( string $key, string $value )
$key string A key of the parameter
$value string A value of the parameter

setServerParameters() public method

Sets server parameters.
public setServerParameters ( array $server )
$server array An array of server parameters

submit() public method

Submits a form.
public submit ( Form $form, array $values = [] )
$form Symfony\Component\DomCrawler\Form A Form instance
$values array An array of form field values

submit() public method

Submits a form.
public submit ( Form $form, array $values = [] ) : Crawler
$form Symfony\Component\DomCrawler\Form A Form instance
$values array An array of form field values
return Symfony\Component\DomCrawler\Crawler

Property Details

$cookieJar protected_oe property

protected $cookieJar

$crawler protected_oe property

protected $crawler

$followRedirects protected_oe property

protected $followRedirects

$history protected_oe property

protected $history

$insulated protected_oe property

protected $insulated

$redirect protected_oe property

protected $redirect

$request protected_oe property

protected $request

$response protected_oe property

protected $response

$server protected_oe property

protected $server