@@ -23,6 +23,32 @@ Basic Usage
2323.. note ::
2424 The component only provides an abstract client and does not provide any "default" backend for the HTTP layer.
2525
26+ Creating a Client
27+ -----------------
28+
29+ To create your own client you must extend the abstract client class and implement the doRequest method.
30+ This method accepts a request and should return a response.
31+
32+ .. code-block :: php
33+
34+ namespace ACME;
35+
36+ use Symfony\Component\BrowserKit\Client as BaseClient;
37+ use Symfony\Component\BrowserKit\Response;
38+
39+ class Client extends BaseClient {
40+ protected function doRequest($request) {
41+ // convert request into a response
42+ // ...
43+ return new Response($content, $status, $headers);
44+ }
45+ }
46+
47+ For a simple implementation of a browser based on an HTTP layer, have a look at Goutte _.
48+
49+ For an implementation based on HttpKernelInterface, have a look at the Client provided by the :doc: `/components/http_kernel/introduction `.
50+
51+
2652Making Request
2753~~~~~~~~~~~~~~
2854
@@ -52,8 +78,23 @@ Select a link with the crawler and pass it to the click method to click on the l
5278 $client->click($link);
5379
5480 Submiting Forms
55- ~~~~~~~~~~~~~~~~
81+ ~~~~~~~~~~~~~~~
82+
83+ .. code-block :: php
5684
85+ use ACME\Client;
86+
87+ // make a real request to an external site
88+ $client = new Client();
89+ $crawler = $client->request('GET', 'https://github.com/login');
90+
91+ // select the form and fill in some values
92+ $form = $crawler->selectButton('Log in')->form();
93+ $form['login'] = 'symfonyfan';
94+ $form['password'] = 'anypass';
95+
96+ // submit that form
97+ $crawler = $client->submit($form);
5798
5899 Cookies
59100-------
@@ -64,29 +105,5 @@ History
64105Insulated Request
65106-----------------
66107
67- Creating a Client
68- -----------------
69-
70- To create your own client you must extend the abstract client class and implement the doRequest method.
71- This method accepts a request and should return a response.
72-
73- .. code-block :: php
74- namespace ACME;
75-
76- use Symfony\Component\BrowserKit\Client as BaseClient;
77- use Symfony\Component\BrowserKit\Response;
78-
79- class Client extends BaseClient {
80- protected function doRequest($request) {
81- // convert request into a response
82- // ...
83- return new Response($content, $status, $headers);
84- }
85- }
86-
87- For a simple implementation of a browser based on an HTTP layer, have a look at Goutte _.
88-
89- For an implementation based on HttpKernelInterface, have a look at the Client provided by the :doc: `/components/http_kernel/introduction `.
90-
91108.. _Packagist : https://packagist.org/packages/symfony/browser-kit
92109.. _Goutte : https://github.com/fabpot/Goutte
0 commit comments