|
11 | 11 |
|
12 | 12 | /**
|
13 | 13 | * The `Client` class is responsible for communication with the remote SOAP
|
14 |
| - * WebService server. |
15 |
| - * |
16 |
| - * It requires a [`Browser`](https://github.com/reactphp/http#browser) object |
17 |
| - * bound to the main [`EventLoop`](https://github.com/reactphp/event-loop#usage) |
18 |
| - * in order to handle async requests, the WSDL file contents and an optional |
| 14 | + * WebService server. It requires the WSDL file contents and an optional |
19 | 15 | * array of SOAP options:
|
20 | 16 | *
|
21 | 17 | * ```php
|
22 |
| - * $browser = new React\Http\Browser(); |
23 |
| - * |
24 | 18 | * $wsdl = '<?xml …';
|
25 | 19 | * $options = array();
|
26 | 20 | *
|
27 |
| - * $client = new Clue\React\Soap\Client($browser, $wsdl, $options); |
| 21 | + * $client = new Clue\React\Soap\Client(null, $wsdl, $options); |
28 | 22 | * ```
|
29 | 23 | *
|
| 24 | + * This class takes an optional `Browser|null $browser` parameter that can be used to |
| 25 | + * pass the browser instance to use for this object. |
30 | 26 | * If you need custom connector settings (DNS resolution, TLS parameters, timeouts,
|
31 | 27 | * proxy servers etc.), you can explicitly pass a custom instance of the
|
32 | 28 | * [`ConnectorInterface`](https://github.com/reactphp/socket#connectorinterface)
|
33 |
| - * to the [`Browser`](https://github.com/clue/reactphp/http#browser) instance: |
| 29 | + * to the [`Browser`](https://github.com/reactphp/http#browser) instance |
| 30 | + * and pass it as an additional argument to the `Client` like this: |
34 | 31 | *
|
35 | 32 | * ```php
|
36 |
| - * $connector = new React\Socket\Connector(null, array( |
| 33 | + * $connector = new React\Socket\Connector(array( |
37 | 34 | * 'dns' => '127.0.0.1',
|
38 | 35 | * 'tcp' => array(
|
39 | 36 | * 'bindto' => '192.168.10.1:0'
|
|
44 | 41 | * )
|
45 | 42 | * ));
|
46 | 43 | *
|
47 |
| - * $browser = new React\Http\Browser(null, $connector); |
| 44 | + * $browser = new React\Http\Browser($connector); |
48 | 45 | * $client = new Clue\React\Soap\Client($browser, $wsdl);
|
49 | 46 | * ```
|
50 | 47 | *
|
|
75 | 72 | *
|
76 | 73 | * ```php
|
77 | 74 | * try {
|
78 |
| - * $client = new Clue\React\Soap\Client($browser, $wsdl); |
| 75 | + * $client = new Clue\React\Soap\Client(null, $wsdl); |
79 | 76 | * } catch (SoapFault $e) {
|
80 | 77 | * echo 'Error: ' . $e->getMessage() . PHP_EOL;
|
81 | 78 | * }
|
|
99 | 96 | * namespace of the SOAP service:
|
100 | 97 | *
|
101 | 98 | * ```php
|
102 |
| - * $client = new Clue\React\Soap\Client($browser, null, array( |
| 99 | + * $client = new Clue\React\Soap\Client(null, null, array( |
103 | 100 | * 'location' => 'http://example.com',
|
104 | 101 | * 'uri' => 'http://ping.example.com',
|
105 | 102 | * ));
|
|
109 | 106 | * explicitly overwrite the URL of the SOAP server to send the request to:
|
110 | 107 | *
|
111 | 108 | * ```php
|
112 |
| - * $client = new Clue\React\Soap\Client($browser, $wsdl, array( |
| 109 | + * $client = new Clue\React\Soap\Client(null, $wsdl, array( |
113 | 110 | * 'location' => 'http://example.com'
|
114 | 111 | * ));
|
115 | 112 | * ```
|
|
118 | 115 | * use SOAP 1.2 instead:
|
119 | 116 | *
|
120 | 117 | * ```php
|
121 |
| - * $client = new Clue\React\Soap\Client($browser, $wsdl, array( |
| 118 | + * $client = new Clue\React\Soap\Client(null, $wsdl, array( |
122 | 119 | * 'soap_version' => SOAP_1_2
|
123 | 120 | * ));
|
124 | 121 | * ```
|
|
127 | 124 | * like this:
|
128 | 125 | *
|
129 | 126 | * ```php
|
130 |
| - * $client = new Clue\React\Soap\Client($browser, $wsdl, array( |
| 127 | + * $client = new Clue\React\Soap\Client(null, $wsdl, array( |
131 | 128 | * 'classmap' => array(
|
132 | 129 | * 'getBankResponseType' => BankResponse::class
|
133 | 130 | * )
|
|
145 | 142 | */
|
146 | 143 | class Client
|
147 | 144 | {
|
| 145 | + /** @var Browser */ |
148 | 146 | private $browser;
|
| 147 | + |
149 | 148 | private $encoder;
|
150 | 149 | private $decoder;
|
151 | 150 |
|
152 | 151 | /**
|
153 | 152 | * Instantiate a new SOAP client for the given WSDL contents.
|
154 | 153 | *
|
155 |
| - * @param Browser $browser |
156 |
| - * @param string|null $wsdlContents |
157 |
| - * @param array $options |
| 154 | + * @param ?Browser $browser |
| 155 | + * @param ?string $wsdlContents |
| 156 | + * @param ?array $options |
158 | 157 | */
|
159 |
| - public function __construct(Browser $browser, ?string $wsdlContents, array $options = array()) |
| 158 | + public function __construct(?Browser $browser, ?string $wsdlContents, array $options = array()) |
160 | 159 | {
|
161 | 160 | $wsdl = $wsdlContents !== null ? 'data://text/plain;base64,' . base64_encode($wsdlContents) : null;
|
162 | 161 |
|
| 162 | + $this->browser = $browser ?? new Browser(); |
| 163 | + |
163 | 164 | // Accept HTTP responses with error status codes as valid responses.
|
164 | 165 | // This is done in order to process these error responses through the normal SOAP decoder.
|
165 | 166 | // Additionally, we explicitly limit number of redirects to zero because following redirects makes little sense
|
166 | 167 | // because it transforms the POST request to a GET one and hence loses the SOAP request body.
|
167 |
| - $browser = $browser->withRejectErrorResponse(false); |
168 |
| - $browser = $browser->withFollowRedirects(0); |
| 168 | + $this->browser = $this->browser->withRejectErrorResponse(false); |
| 169 | + $this->browser = $this->browser->withFollowRedirects(0); |
169 | 170 |
|
170 |
| - $this->browser = $browser; |
171 | 171 | $this->encoder = new ClientEncoder($wsdl, $options);
|
172 | 172 | $this->decoder = new ClientDecoder($wsdl, $options);
|
173 | 173 | }
|
|
0 commit comments