@@ -23,6 +23,32 @@ Basic Usage
23
23
.. note ::
24
24
The component only provides an abstract client and does not provide any "default" backend for the HTTP layer.
25
25
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
+
26
52
Making Request
27
53
~~~~~~~~~~~~~~
28
54
@@ -52,8 +78,23 @@ Select a link with the crawler and pass it to the click method to click on the l
52
78
$client->click($link);
53
79
54
80
Submiting Forms
55
- ~~~~~~~~~~~~~~~~
81
+ ~~~~~~~~~~~~~~~
82
+
83
+ .. code-block :: php
56
84
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);
57
98
58
99
Cookies
59
100
-------
@@ -64,29 +105,5 @@ History
64
105
Insulated Request
65
106
-----------------
66
107
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
-
91
108
.. _Packagist : https://packagist.org/packages/symfony/browser-kit
92
109
.. _Goutte : https://github.com/fabpot/Goutte
0 commit comments