@@ -32,9 +32,6 @@ This project provides a *simple* API for invoking *async* RPCs to remote web ser
32
32
33
33
* [ Quickstart example] ( #quickstart-example )
34
34
* [ Usage] ( #usage )
35
- * [ Factory] ( #factory )
36
- * [ createClient()] ( #createclient )
37
- * [ createClientFromWsdl()] ( #createclientfromwsdl )
38
35
* [ Client] ( #client )
39
36
* [ soapCall()] ( #soapcall )
40
37
* [ getFunctions()] ( #getfunctions )
@@ -55,10 +52,11 @@ web service via SOAP:
55
52
56
53
``` php
57
54
$loop = React\EventLoop\Factory::create();
58
- $factory = new Factory ($loop);
55
+ $browser = new Browser ($loop);
59
56
$wsdl = 'http://example.com/demo.wsdl';
60
57
61
- $factory->createClient($wsdl)->then(function (Client $client) {
58
+ $browser->get($wsdl)->then(function (ResponseInterface $response) use ($browser) {
59
+ $client = new Client($browser, (string)$response->getBody());
62
60
$api = new Proxy($client);
63
61
64
62
$api->getBank(array('blz' => '12070000'))->then(function ($result) {
@@ -73,53 +71,76 @@ See also the [examples](examples).
73
71
74
72
## Usage
75
73
76
- ### Factory
74
+ ### Client
75
+
76
+ The ` Client ` class is responsible for communication with the remote SOAP
77
+ WebService server.
77
78
78
- The ` Factory ` class is responsible for fetching the WSDL file once and constructing
79
- the [ ` Client ` ] ( #client ) instance.
80
- It also registers everything with the main [ ` EventLoop ` ] ( https://github.com/reactphp/event-loop#usage ) .
79
+ It requires a [ ` Browser ` ] ( https://github.com/clue/reactphp-buzz#browser ) object
80
+ bound to the main [ ` EventLoop ` ] (https://github.com/reactphp/event-loop#usage
81
+ in order to handle async requests and the WSDL file contents:
81
82
82
83
``` php
83
84
$loop = React\EventLoop\Factory::create();
84
- $factory = new Factory($loop);
85
+ $browser = new Clue\React\Buzz\Browser($loop);
86
+
87
+ $client = new Client($browser, $wsdl);
85
88
```
86
89
87
- If you need custom DNS or proxy settings, you can explicitly pass a
90
+ If you need custom DNS, TLS or proxy settings, you can explicitly pass a
88
91
custom [ ` Browser ` ] ( https://github.com/clue/reactphp-buzz#browser ) instance:
89
92
90
93
``` php
91
- $browser = new Clue\React\Buzz\Browser($loop);
92
- $factory = new Factory($loop, $browser);
94
+ $connector = new \React\Socket\Connector($loop, array(
95
+ 'dns' => '127.0.0.1',
96
+ 'tcp' => array(
97
+ 'bindto' => '192.168.10.1:0'
98
+ ),
99
+ 'tls' => array(
100
+ 'verify_peer' => false,
101
+ 'verify_peer_name' => false
102
+ )
103
+ ));
104
+
105
+ $browser = new Browser($loop, $connector);
106
+ $client = new Client($browser, $wsdl);
93
107
```
94
108
95
- #### createClient()
96
-
97
- The ` createClient(string $wsdl): PromiseInterface<Client, Exception> ` method can be used to
98
- download the WSDL at the given URL into memory and create a new [ ` Client ` ] ( #client ) .
109
+ The ` Client ` works similar to PHP's ` SoapClient ` (which it uses under the
110
+ hood), but leaves you the responsibility to load the WSDL file. This allows
111
+ you to use local WSDL files, WSDL files from a cache or the most common form,
112
+ downloading the WSDL file contents from an URL through the ` Browser ` :
99
113
100
114
``` php
101
- $factory->createClient($url)->then(
102
- function (Client $client) {
103
- // client ready
115
+ $browser = new Browser($loop);
116
+
117
+ $browser->get($url)->then(
118
+ function (ResponseInterface $response) use ($browser) {
119
+ // WSDL file is ready, create client
120
+ $client = new Client($browser, (string)$response->getBody());
121
+ …
104
122
},
105
123
function (Exception $e) {
106
- // an error occured while trying to download or parse the WSDL
124
+ // an error occured while trying to download the WSDL
107
125
}
108
126
);
109
127
```
110
128
111
- #### createClientFromWsdl()
112
-
113
- The ` createClientFromWsdl(string $wsdlContents): Client ` method can be used to
114
- create a new [ ` Client ` ] ( #client ) from the given WSDL contents.
129
+ The ` Client ` constructor loads the given WSDL file contents into memory and
130
+ parses its definition. If the given WSDL file is invalid and can not be
131
+ parsed, this will throw a ` SoapFault ` :
115
132
116
- This works similar to ` createClient() ` , but leaves you the responsibility to load
117
- the WSDL file. This allows you to use local WSDL files, for instance.
118
-
119
- ### Client
133
+ ``` php
134
+ try {
135
+ $client = new Client($browser, $wsdl);
136
+ } catch (SoapFault $e) {
137
+ echo 'Error: ' . $e->getMessage() . PHP_EOL;
138
+ }
139
+ ```
120
140
121
- The ` Client ` class is responsible for communication with the remote SOAP
122
- WebService server.
141
+ > Note that if you have ` ext-debug ` loaded, this may halt with a fatal
142
+ error instead of throwing a ` SoapFault ` . It is not recommended to use this
143
+ extension in production, so this should only ever affect test environments.
123
144
124
145
If you want to call RPC functions, see below for the [ ` Proxy ` ] ( #proxy ) class.
125
146
0 commit comments