Skip to content

Commit 355bafb

Browse files
committed
Improve documentation
1 parent 0c26b41 commit 355bafb

File tree

4 files changed

+176
-28
lines changed

4 files changed

+176
-28
lines changed

README.md

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,25 +93,27 @@ $factory = new Factory($loop, $browser);
9393

9494
#### createClient()
9595

96-
The `createClient($wsdl)` method can be used to download the WSDL at the
97-
given URL into memory and create a new [`Client`](#client).
96+
The `createClient(string $wsdl): PromiseInterface<Client, Exception>` method can be used to
97+
download the WSDL at the given URL into memory and create a new [`Client`](#client).
9898

9999
```php
100100
$factory->createClient($url)->then(
101101
function (Client $client) {
102102
// client ready
103103
},
104104
function (Exception $e) {
105-
// an error occured while trying to download the WSDL
105+
// an error occured while trying to download or parse the WSDL
106106
}
107107
);
108108
```
109109

110110
#### createClientFromWsdl()
111111

112-
The `createClientFromWsdl($wsdlContents)` method works similar to `createClient()`,
113-
but leaves you the responsibility to load the WSDL file.
114-
This allows you to use local WSDL files, for instance.
112+
The `createClientFromWsdl(string $wsdlContents): Client` method can be used to
113+
create a new [`Client`](#client) from the given WSDL contents.
114+
115+
This works similar to `createClient()`, but leaves you the responsibility to load
116+
the WSDL file. This allows you to use local WSDL files, for instance.
115117

116118
### Client
117119

@@ -125,25 +127,41 @@ All public methods of the `Client` are considered *advanced usage*.
125127

126128
#### soapCall()
127129

128-
The `soapCall($method, $arguments)` method can be used to queue the given
129-
function to be sent via SOAP and wait for a response from the remote web service.
130+
The `soapCall(string $method, mixed[] $arguments): PromiseInterface<mixed, Exception>` method can be used to
131+
queue the given function to be sent via SOAP and wait for a response from the remote web service.
132+
133+
```php
134+
// advanced usage, see Proxy for recommended alternative
135+
$promise = $client->soapCall('ping', array('hello', 42));
136+
```
130137

131138
Note: This is considered *advanced usage*, you may want to look into using the [`Proxy`](#proxy) instead.
132139

140+
```php
141+
$proxy = new Proxy($client);
142+
$promise = $proxy->ping('hello', 42);
143+
```
144+
133145
#### getFunctions()
134146

135-
The `getFunctions()` method returns an array of functions defined in the WSDL.
136-
It returns the equivalent of PHP's [`SoapClient::__getFunctions()`](http://php.net/manual/en/soapclient.getfunctions.php).
147+
The `getFunctions(): string[]` method can be used to
148+
return an array of functions defined in the WSDL.
149+
150+
It returns the equivalent of PHP's
151+
[`SoapClient::__getFunctions()`](http://php.net/manual/en/soapclient.getfunctions.php).
137152

138153
#### getTypes()
139154

140-
The `getTypes()` method returns an array of types defined in the WSDL.
141-
It returns the equivalent of PHP's [`SoapClient::__getTypes()`](http://php.net/manual/en/soapclient.gettypes.php).
155+
The `getTypes(): string[]` method can be used to
156+
return an array of types defined in the WSDL.
157+
158+
It returns the equivalent of PHP's
159+
[`SoapClient::__getTypes()`](http://php.net/manual/en/soapclient.gettypes.php).
142160

143161
#### getLocation()
144162

145-
The `getLocation($function)` method can be used to return the location (URI)
146-
of the given webservice `$function`.
163+
The `getLocation(string|int $function): string` method can be used to
164+
return the location (URI) of the given webservice `$function`.
147165

148166
Note that this is not to be confused with the WSDL file location.
149167
A WSDL file can contain any number of function definitions.
@@ -153,15 +171,18 @@ However, technically each function can potentially use a different location.
153171
The `$function` parameter should be a string with the the SOAP function name.
154172
See also [`getFunctions()`](#getfunctions) for a list of all available functions.
155173

174+
```php
175+
assert('http://example.com/soap/service' === $client->getLocation('echo'));
176+
```
177+
156178
For easier access, this function also accepts a numeric function index.
157179
It then uses [`getFunctions()`](#getfunctions) internally to get the function
158180
name for the given index.
159181
This is particularly useful for the very common case where all functions use the
160182
same location and accessing the first location is sufficient.
161183

162184
```php
163-
assert('http://example.com/soap/service' == $client->getLocation('echo'));
164-
assert('http://example.com/soap/service' == $client->getLocation(0));
185+
assert('http://example.com/soap/service' === $client->getLocation(0));
165186
```
166187

167188
Passing a `$function` not defined in the WSDL file will throw a `SoapFault`.

src/Client.php

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,17 @@
77
use Clue\React\Soap\Protocol\ClientEncoder;
88
use Psr\Http\Message\ResponseInterface;
99
use React\Promise\Deferred;
10+
use React\Promise\PromiseInterface;
1011

12+
/**
13+
* The `Client` class is responsible for communication with the remote SOAP
14+
* WebService server.
15+
*
16+
* If you want to call RPC functions, see below for the [`Proxy`](#proxy) class.
17+
*
18+
* Note: It's recommended (and easier) to wrap the `Client` in a [`Proxy`](#proxy) instance.
19+
* All public methods of the `Client` are considered *advanced usage*.
20+
*/
1121
final class Client
1222
{
1323
private $wsdl;
@@ -40,6 +50,25 @@ public function __construct($wsdl, Browser $browser, ClientEncoder $encoder = nu
4050
$this->decoder = $decoder;
4151
}
4252

53+
/**
54+
* Queue the given function to be sent via SOAP and wait for a response from the remote web service.
55+
*
56+
* ```php
57+
* // advanced usage, see Proxy for recommended alternative
58+
* $promise = $client->soapCall('ping', array('hello', 42));
59+
* ```
60+
*
61+
* Note: This is considered *advanced usage*, you may want to look into using the [`Proxy`](#proxy) instead.
62+
*
63+
* ```php
64+
* $proxy = new Proxy($client);
65+
* $promise = $proxy->ping('hello', 42);
66+
* ```
67+
*
68+
* @param string $name
69+
* @param mixed[] $args
70+
* @return PromiseInterface Returns a Promise<mixed, Exception>
71+
*/
4372
public function soapCall($name, $args)
4473
{
4574
try {
@@ -55,43 +84,60 @@ public function soapCall($name, $args)
5584
);
5685
}
5786

87+
5888
/**
59-
* @param ResponseInterface $response
60-
* @return mixed
61-
* @internal
89+
* Returns an array of functions defined in the WSDL.
90+
*
91+
* It returns the equivalent of PHP's
92+
* [`SoapClient::__getFunctions()`](http://php.net/manual/en/soapclient.getfunctions.php).
93+
*
94+
* @return string[]
6295
*/
63-
public function handleResponse(ResponseInterface $response)
64-
{
65-
return $this->decoder->decode((string)$response->getBody());
66-
}
67-
6896
public function getFunctions()
6997
{
7098
return $this->encoder->__getFunctions();
7199
}
72100

101+
/**
102+
* Returns an array of types defined in the WSDL.
103+
*
104+
* It returns the equivalent of PHP's
105+
* [`SoapClient::__getTypes()`](http://php.net/manual/en/soapclient.gettypes.php).
106+
*
107+
* @return string[]
108+
*/
73109
public function getTypes()
74110
{
75111
return $this->encoder->__getTypes();
76112
}
77113

78114
/**
79-
* get location (URI) for given function name or number
115+
* Returns the location (URI) of the given webservice `$function`.
80116
*
81117
* Note that this is not to be confused with the WSDL file location.
82118
* A WSDL file can contain any number of function definitions.
83119
* It's very common that all of these functions use the same location definition.
84120
* However, technically each function can potentially use a different location.
85121
*
86122
* The `$function` parameter should be a string with the the SOAP function name.
87-
* See also `getFunctions()` for a list of all available functions.
123+
* See also [`getFunctions()`](#getfunctions) for a list of all available functions.
124+
*
125+
* ```php
126+
* assert('http://example.com/soap/service' === $client->getLocation('echo'));
127+
* ```
88128
*
89129
* For easier access, this function also accepts a numeric function index.
90-
* It then uses `getFunctions()` internally to get the function
130+
* It then uses [`getFunctions()`](#getfunctions) internally to get the function
91131
* name for the given index.
92132
* This is particularly useful for the very common case where all functions use the
93133
* same location and accessing the first location is sufficient.
94134
*
135+
* ```php
136+
* assert('http://example.com/soap/service' === $client->getLocation(0));
137+
* ```
138+
*
139+
* Passing a `$function` not defined in the WSDL file will throw a `SoapFault`.
140+
*
95141
* @param string|int $function
96142
* @return string
97143
* @throws \SoapFault if given function does not exist
@@ -109,4 +155,14 @@ public function getLocation($function)
109155
// encode request for given $function
110156
return (string)$this->encoder->encode($function, array())->getUri();
111157
}
158+
159+
/**
160+
* @param ResponseInterface $response
161+
* @return mixed
162+
* @internal
163+
*/
164+
public function handleResponse(ResponseInterface $response)
165+
{
166+
return $this->decoder->decode((string)$response->getBody());
167+
}
112168
}

src/Factory.php

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,29 @@
22

33
namespace Clue\React\Soap;
44

5-
use React\EventLoop\LoopInterface;
65
use Clue\React\Buzz\Browser;
76
use Psr\Http\Message\ResponseInterface;
7+
use React\EventLoop\LoopInterface;
8+
use React\Promise\PromiseInterface;
89

10+
/**
11+
* The `Factory` class is responsible for fetching the WSDL file once and constructing
12+
* the [`Client`](#client) instance.
13+
* It also registers everything with the main [`EventLoop`](https://github.com/reactphp/event-loop#usage).
14+
*
15+
* ```php
16+
* $loop = React\EventLoop\Factory::create();
17+
* $factory = new Factory($loop);
18+
* ```
19+
*
20+
* If you need custom DNS or proxy settings, you can explicitly pass a
21+
* custom [`Browser`](https://github.com/clue/php-buzz-react#browser) instance:
22+
*
23+
* ```php
24+
* $browser = new Clue\React\Buzz\Browser($loop);
25+
* $factory = new Factory($loop, $browser);
26+
* ```
27+
*/
928
final class Factory
1029
{
1130
private $loop;
@@ -20,6 +39,23 @@ public function __construct(LoopInterface $loop, Browser $browser = null)
2039
$this->browser = $browser;
2140
}
2241

42+
/**
43+
* Downloads the WSDL at the given URL into memory and create a new [`Client`](#client).
44+
*
45+
* ```php
46+
* $factory->createClient($url)->then(
47+
* function (Client $client) {
48+
* // client ready
49+
* },
50+
* function (Exception $e) {
51+
* // an error occured while trying to download or parse the WSDL
52+
* }
53+
* );
54+
* ```
55+
*
56+
* @param string $wsdl
57+
* @return PromiseInterface Returns a Promise<Client, Exception>
58+
*/
2359
public function createClient($wsdl)
2460
{
2561
$that = $this;
@@ -29,6 +65,15 @@ public function createClient($wsdl)
2965
});
3066
}
3167

68+
/**
69+
* Creates a new [`Client`](#client) from the given WSDL contents.
70+
*
71+
* This works similar to `createClient()`, but leaves you the responsibility to load
72+
* the WSDL file. This allows you to use local WSDL files, for instance.
73+
*
74+
* @param string $wsdlContents
75+
* @return Client
76+
*/
3277
public function createClientFromWsdl($wsdlContents)
3378
{
3479
$browser = $this->browser;

src/Proxy.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,27 @@
22

33
namespace Clue\React\Soap;
44

5+
use React\Promise\PromiseInterface;
6+
7+
/**
8+
* The `Proxy` class wraps an existing [`Client`](#client) instance in order to ease calling
9+
* SOAP functions.
10+
*
11+
* ```php
12+
* $proxy = new Proxy($client);
13+
* ```
14+
*
15+
* Each and every method call to the `Proxy` class will be sent via SOAP.
16+
*
17+
* ```php
18+
* $proxy->myMethod($myArg1, $myArg2)->then(function ($response) {
19+
* // result received
20+
* });
21+
* ```
22+
*
23+
* Please refer to your WSDL or its accompanying documentation for details
24+
* on which functions and arguments are supported.
25+
*/
526
final class Proxy
627
{
728
private $client;
@@ -11,6 +32,11 @@ public function __construct(Client $client)
1132
$this->client = $client;
1233
}
1334

35+
/**
36+
* @param string $name
37+
* @param mixed[] $args
38+
* @return PromiseInterface
39+
*/
1440
public function __call($name, $args)
1541
{
1642
return $this->client->soapCall($name, $args);

0 commit comments

Comments
 (0)