PHP Class Neos\Flow\Http\Client\Browser

Show file Open project: neos/flow-development-collection Class Usage Examples

Protected Properties

Property Type Description
$automaticRequestHeaders Neos\Flow\Http\Headers
$followRedirects boolean If redirects should be followed
$lastRequest Neos\Flow\Http\Request
$lastResponse Neos\Flow\Http\Response
$maximumRedirections integer The very maximum amount of redirections to follow if there is a "Location" redirect (see also $redirectionStack property)
$redirectionStack array A simple string array that keeps track of occurred "Location" header redirections to avoid infinite loops if the same redirection happens
$requestEngine Neos\Flow\Http\Client\RequestEngineInterface

Public Methods

Method Description
__construct ( ) Construct the Browser instance.
addAutomaticRequestHeader ( string $name, array | string | DateTime $values ) : void Allows to add headers to be sent with every request the browser executes.
getCrawler ( ) : Crawler Returns the DOM crawler which can be used to interact with the web page structure, submit forms, click links or fetch specific parts of the website's contents.
getForm ( string $xpath = '//form' ) : Form Get the form specified by $xpath. If no $xpath given, return the first form on the page.
getLastRequest ( ) : Request Returns the last request executed.
getLastResponse ( ) : Response Returns the response received after the last request.
getRequestEngine ( ) : Neos\Flow\Http\Client\RequestEngineInterface Returns the request engine used by this Browser.
removeAutomaticRequestHeader ( string $name ) : void Allows to remove headers that were added with addAutomaticRequestHeader.
request ( string | Uri $uri, string $method = 'GET', array $arguments = [], array $files = [], array $server = [], string $content = null ) : Response Requests the given URI with the method and other parameters as specified.
sendRequest ( Request $request ) : Response Sends a prepared request and returns the respective response.
setFollowRedirects ( boolean $flag ) : void Sets a flag if redirects should be followed or not.
setRequestEngine ( Neos\Flow\Http\Client\RequestEngineInterface $requestEngine ) : void Inject the request engine
submit ( Form $form ) : Response Submit a form

Method Details

__construct() public method

Construct the Browser instance.
public __construct ( )

addAutomaticRequestHeader() public method

Allows to add headers to be sent with every request the browser executes.
See also: Message::setHeader()
public addAutomaticRequestHeader ( string $name, array | string | DateTime $values ) : void
$name string Name of the header, for example "Location", "Content-Description" etc.
$values array | string | DateTime An array of values or a single value for the specified header field
return void

getCrawler() public method

The returned DOM crawler is bound to the response of the last executed request.
public getCrawler ( ) : Crawler
return Symfony\Component\DomCrawler\Crawler

getForm() public method

Get the form specified by $xpath. If no $xpath given, return the first form on the page.
public getForm ( string $xpath = '//form' ) : Form
$xpath string
return Symfony\Component\DomCrawler\Form

getLastRequest() public method

Returns the last request executed.
public getLastRequest ( ) : Request
return Neos\Flow\Http\Request The HTTP request or NULL if there wasn't a request yet

getLastResponse() public method

Returns the response received after the last request.
public getLastResponse ( ) : Response
return Neos\Flow\Http\Response The HTTP response or NULL if there wasn't a response yet

getRequestEngine() public method

Returns the request engine used by this Browser.
public getRequestEngine ( ) : Neos\Flow\Http\Client\RequestEngineInterface
return Neos\Flow\Http\Client\RequestEngineInterface

removeAutomaticRequestHeader() public method

Allows to remove headers that were added with addAutomaticRequestHeader.
public removeAutomaticRequestHeader ( string $name ) : void
$name string Name of the header, for example "Location", "Content-Description" etc.
return void

request() public method

If a Location header was given and the status code is of response type 3xx (see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html, 14.30 Location)
public request ( string | Uri $uri, string $method = 'GET', array $arguments = [], array $files = [], array $server = [], string $content = null ) : Response
$uri string | Neos\Flow\Http\Uri
$method string Request method, for example "GET"
$arguments array Arguments to send in the request body
$files array
$server array
$content string
return Neos\Flow\Http\Response The HTTP response

sendRequest() public method

Sends a prepared request and returns the respective response.
public sendRequest ( Request $request ) : Response
$request Neos\Flow\Http\Request
return Neos\Flow\Http\Response

setFollowRedirects() public method

Sets a flag if redirects should be followed or not.
public setFollowRedirects ( boolean $flag ) : void
$flag boolean
return void

setRequestEngine() public method

Inject the request engine
public setRequestEngine ( Neos\Flow\Http\Client\RequestEngineInterface $requestEngine ) : void
$requestEngine Neos\Flow\Http\Client\RequestEngineInterface
return void

submit() public method

Submit a form
public submit ( Form $form ) : Response
$form Symfony\Component\DomCrawler\Form
return Neos\Flow\Http\Response

Property Details

$automaticRequestHeaders protected property

protected Headers,Neos\Flow\Http $automaticRequestHeaders
return Neos\Flow\Http\Headers

$followRedirects protected property

If redirects should be followed
protected bool $followRedirects
return boolean

$lastRequest protected property

protected Request,Neos\Flow\Http $lastRequest
return Neos\Flow\Http\Request

$lastResponse protected property

protected Response,Neos\Flow\Http $lastResponse
return Neos\Flow\Http\Response

$maximumRedirections protected property

The very maximum amount of redirections to follow if there is a "Location" redirect (see also $redirectionStack property)
protected int $maximumRedirections
return integer

$redirectionStack protected property

A simple string array that keeps track of occurred "Location" header redirections to avoid infinite loops if the same redirection happens
protected array $redirectionStack
return array

$requestEngine protected property

protected RequestEngineInterface,Neos\Flow\Http\Client $requestEngine
return Neos\Flow\Http\Client\RequestEngineInterface