Documentation

HttpBrowser extends AbstractBrowser
in package

An implementation of a browser using the HttpClient component to make real HTTP requests.

Tags
author

Fabien Potencier fabien@symfony.com

Table of Contents

Properties

$cookieJar  : mixed
$crawler  : mixed
$followMetaRefresh  : mixed
$followRedirects  : mixed
$history  : mixed
$insulated  : mixed
$internalRequest  : mixed
$internalResponse  : mixed
$redirect  : mixed
$request  : mixed
$response  : mixed
$server  : mixed
$client  : mixed
$isMainRequest  : bool
$maxRedirects  : int
$redirectCount  : int
$redirects  : array<string|int, mixed>

Methods

__construct()  : mixed
back()  : Crawler
Goes back in the browser history.
click()  : Crawler
Clicks on a given link.
clickLink()  : Crawler
Clicks the first link (or clickable image) that contains the given text.
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.
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.
getMaxRedirects()  : int
Returns the maximum number of redirects that crawler can follow.
getRequest()  : object
Returns the current origin Request instance.
getResponse()  : object
Returns the current origin response instance.
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.
jsonRequest()  : Crawler
Converts the request parameters into a JSON string and uses it as request content.
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()  : object
Makes a request.
doRequestInProcess()  : object
Makes a request in another process.
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.
getHeaders()  : array<string|int, mixed>
getScript()  : mixed
Returns the script to execute when the request must be insulated.
requestFromRequest()  : Crawler
Makes a request from a Request object directly.
extractHost()  : string|null
getBodyAndExtraHeaders()  : array<string|int, mixed>
getMetaRefreshUrl()  : string|null
getUploadedFiles()  : array<string|int, mixed>
Recursively go through the list. If the file has a tmp_name, convert it to a DataPart.
updateServerFromUri()  : array<string|int, mixed>

Properties

Methods

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

followMetaRefresh()

Sets whether to automatically follow meta refresh redirects or not.

public followMetaRefresh([bool $followMetaRefresh = true ]) : mixed
Parameters
$followMetaRefresh : bool = true

followRedirect()

Follow redirects?

public followRedirect() : Crawler
Tags
throws
LogicException

If request was not a redirect

Return values
Crawler

followRedirects()

Sets whether to automatically follow redirects or not.

public followRedirects([bool $followRedirects = true ]) : mixed
Parameters
$followRedirects : bool = true

getMaxRedirects()

Returns the maximum number of redirects that crawler can follow.

public getMaxRedirects() : int
Return values
int

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
see
doRequest()
Return values
object

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
see
doRequest()
Return values
object

getServerParameter()

Gets single server parameter for specified key.

public getServerParameter(string $key[, mixed $default = '' ]) : mixed
Parameters
$key : string
$default : mixed = ''

insulate()

Sets the insulated flag.

public insulate([bool $insulated = true ]) : mixed
Parameters
$insulated : bool = true
Tags
throws
RuntimeException

When Symfony Process Component is not installed

isFollowingRedirects()

Returns whether client automatically follows redirects or not.

public isFollowingRedirects() : bool
Return values
bool

jsonRequest()

Converts the request parameters into a JSON string and uses it as request content.

public jsonRequest(string $method, string $uri[, array<string|int, mixed> $parameters = [] ][, array<string|int, mixed> $server = [] ][, bool $changeHistory = true ]) : Crawler
Parameters
$method : string
$uri : string
$parameters : array<string|int, mixed> = []
$server : array<string|int, mixed> = []
$changeHistory : bool = true
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.

setMaxRedirects()

Sets the maximum number of redirects that crawler can follow.

public setMaxRedirects(int $maxRedirects) : mixed
Parameters
$maxRedirects : int

setServerParameter()

Sets single server parameter.

public setServerParameter(string $key, string $value) : mixed
Parameters
$key : string
$value : string

setServerParameters()

Sets server parameters.

public setServerParameters(array<string|int, mixed> $server) : mixed
Parameters
$server : array<string|int, mixed>

submit()

Submits a form.

public submit(Form $form[, array<string|int, mixed> $values = [] ][, array<string|int, mixed> $serverParameters = [] ]) : Crawler
Parameters
$form : Form
$values : array<string|int, mixed> = []

An array of form field values

$serverParameters : array<string|int, mixed> = []

An array of server parameters

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
$content : string
$type : string
Return values
Crawler|null

doRequest()

Makes a request.

protected doRequest(Request $request) : object
Parameters
$request : Request
Return values
object

doRequestInProcess()

Makes a request in another process.

protected doRequestInProcess(object $request) : object
Parameters
$request : object
Tags
throws
RuntimeException

When processing returns exit code

Return values
object

filterRequest()

Filters the BrowserKit request to the origin one.

protected filterRequest(Request $request) : object
Parameters
$request : Request
Return values
object

filterResponse()

Filters the origin response to the BrowserKit one.

protected filterResponse(object $response) : Response
Parameters
$response : object
Return values
Response

getAbsoluteUri()

Takes a URI and converts it to absolute if it is not already absolute.

protected getAbsoluteUri(string $uri) : string
Parameters
$uri : string
Return values
string

getHeaders()

protected getHeaders(Request $request) : array<string|int, mixed>
Parameters
$request : Request
Return values
array<string|int, mixed>

getScript()

Returns the script to execute when the request must be insulated.

protected getScript(object $request) : mixed
Parameters
$request : object

An origin request instance

Tags
throws
LogicException

When this abstract class is not implemented

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

getBodyAndExtraHeaders()

private getBodyAndExtraHeaders(Request $request, array<string|int, mixed> $headers) : array<string|int, mixed>
Parameters
$request : Request
$headers : array<string|int, mixed>
Return values
array<string|int, mixed>

[$body, $headers]

getUploadedFiles()

Recursively go through the list. If the file has a tmp_name, convert it to a DataPart.

private getUploadedFiles(array<string|int, mixed> $files) : array<string|int, mixed>

Keep the original hierarchy.

Parameters
$files : array<string|int, mixed>
Return values
array<string|int, mixed>

updateServerFromUri()

private updateServerFromUri(array<string|int, mixed> $server, string $uri) : array<string|int, mixed>
Parameters
$server : array<string|int, mixed>
$uri : string
Return values
array<string|int, mixed>

        
On this page

Search results