Repository navigation
Expand file tree
/
Copy pathClient.php
More file actions
71 lines (59 loc) · 1.61 KB
/
Copy pathClient.php
File metadata and controls
71 lines (59 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
namespace Clue\React\Soap;
use Clue\React\Buzz\Browser;
use Exception;
use SoapClient;
use Clue\React\Soap\Protocol\ClientEncoder;
use Clue\React\Soap\Protocol\ClientDecoder;
use Clue\React\Buzz\Message\Response;
use React\Promise\Deferred;
class Client
{
private $wsdl;
private $browser;
private $encoder;
private $decoder;
public function __construct($wsdl, Browser $browser, ClientEncoder $encoder = null, ClientDecoder $decoder = null)
{
if ($encoder === null) {
$encoder = new ClientEncoder($wsdl);
}
if ($decoder === null) {
$decoder = new ClientDecoder($wsdl);
}
$this->wsdl = $wsdl;
$this->browser = $browser;
$this->encoder = $encoder;
$this->decoder = $decoder;
}
public function soapCall($name, $args)
{
try {
$request = $this->encoder->encode($name, $args);
} catch (\Exception $e) {
$deferred = new Deferred();
$deferred->reject($e);
return $deferred->promise();
}
return $this->browser->send($request)->then(
array($this, 'handleResponse'),
array($this, 'handleError')
);
}
public function handleResponse(Response $response)
{
return $this->decoder->decode((string)$response->getBody());
}
public function handleError(Exception $error)
{
throw $error;
}
public function getFunctions()
{
return $this->encoder->__getFunctions();
}
public function getTypes()
{
return $this->encoder->__getTypes();
}
}