Browser
class Browser implements ClientInterface (View source)
An HTTP client simulating a web browser
Properties
protected RequestInterface | $lastRequest | ||
protected ResponseInterface | $lastResponse | ||
protected bool | $followRedirects | If redirects should be followed |
|
protected int | $maximumRedirections | The very maximum amount of redirections to follow if there is a "Location" redirect (see also $redirectionStack property) |
|
protected array | $redirectionStack | A simple string array that keeps track of occurred "Location" header redirections to avoid infinite loops if the same redirection happens |
|
protected Headers | $automaticRequestHeaders | ||
protected RequestEngineInterface | $requestEngine | ||
protected ServerRequestFactoryInterface | $serverRequestFactory | ||
protected StreamFactoryInterface | $contentStreamFactory |
Methods
Construct the Browser instance.
Allows to add headers to be sent with every request the browser executes.
Allows to remove headers that were added with addAutomaticRequestHeader.
Requests the given URI with the method and other parameters as specified.
Sets a flag if redirects should be followed or not.
Sends a prepared request and returns the respective response.
Returns the response received after the last request.
Returns the last request executed.
Returns the request engine used by this Browser.
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.
Get the form specified by $xpath. If no $xpath given, return the first form on the page.
Submit a form
Details
__construct()
Construct the Browser instance.
void
setRequestEngine(RequestEngineInterface $requestEngine)
Inject the request engine
void
addAutomaticRequestHeader(string $name, array|string|DateTime $values)
Allows to add headers to be sent with every request the browser executes.
void
removeAutomaticRequestHeader(string $name)
Allows to remove headers that were added with addAutomaticRequestHeader.
ResponseInterface
request(string|UriInterface $uri, string $method = 'GET', array $arguments = [], array $files = [], array $server = [], string $content = null)
Requests the given URI with the method and other parameters as specified.
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)
void
setFollowRedirects(bool $flag)
Sets a flag if redirects should be followed or not.
ResponseInterface
sendRequest(RequestInterface $request)
Sends a prepared request and returns the respective response.
ResponseInterface|null
getLastResponse()
Returns the response received after the last request.
RequestInterface|null
getLastRequest()
Returns the last request executed.
RequestEngineInterface
getRequestEngine()
Returns the request engine used by this Browser.
Crawler
getCrawler()
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.
The returned DOM crawler is bound to the response of the last executed request.
Form
getForm(string $xpath = '//form')
Get the form specified by $xpath. If no $xpath given, return the first form on the page.
ResponseInterface
submit(Form $form)
Submit a form