|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Meng\Soap\HttpBinding; |
|
4
|
|
|
|
|
5
|
|
|
use Meng\Soap\Interpreter; |
|
6
|
|
|
use Psr\Http\Message\RequestInterface; |
|
7
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
8
|
|
|
use Zend\Diactoros\Stream; |
|
9
|
|
|
|
|
10
|
|
|
class HttpBinding |
|
11
|
|
|
{ |
|
12
|
|
|
private $interpreter; |
|
13
|
|
|
private $builder; |
|
14
|
|
|
|
|
15
|
|
|
public function __construct(Interpreter $interpreter, RequestBuilder $builder) |
|
16
|
|
|
{ |
|
17
|
|
|
$this->interpreter = $interpreter; |
|
18
|
|
|
$this->builder = $builder; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Embed SOAP messages in PSR-7 HTTP Requests |
|
23
|
|
|
* |
|
24
|
|
|
* @param $name |
|
25
|
|
|
* @param array $arguments |
|
26
|
|
|
* @param array|null $options |
|
27
|
|
|
* @param null $inputHeaders |
|
28
|
|
|
* @return RequestInterface |
|
29
|
|
|
*/ |
|
30
|
|
|
public function request($name, array $arguments, array $options = null, $inputHeaders = null) |
|
31
|
|
|
{ |
|
32
|
|
|
$soapRequest = $this->interpreter->request($name, $arguments, $options, $inputHeaders); |
|
33
|
|
|
if ($soapRequest->getSoapVersion() == '1') { |
|
34
|
|
|
$this->builder->isSOAP11(); |
|
35
|
|
|
} else { |
|
36
|
|
|
$this->builder->isSOAP12(); |
|
37
|
|
|
} |
|
38
|
|
|
$this->builder->setEndpoint($soapRequest->getEndpoint()); |
|
39
|
|
|
$this->builder->setSoapAction($soapRequest->getSoapAction()); |
|
40
|
|
|
$stream = fopen('php://temp', 'r+'); |
|
41
|
|
|
fwrite($stream, $soapRequest->getSoapMessage()); |
|
42
|
|
|
fseek($stream, 0); |
|
43
|
|
|
$this->builder->setSoapMessage(new Stream($stream)); |
|
44
|
|
|
return $this->builder->getSoapHttpRequest(); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Retrieve SOAP messages from PSR-7 HTTP responses |
|
49
|
|
|
* |
|
50
|
|
|
* @param ResponseInterface $response |
|
51
|
|
|
* @param $name |
|
52
|
|
|
* @param null $output_headers |
|
53
|
|
|
* @return mixed |
|
54
|
|
|
*/ |
|
55
|
|
|
public function response(ResponseInterface $response, $name, &$output_headers = null) |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->interpreter->response($response->getBody()->__toString(), $name, $output_headers); |
|
58
|
|
|
} |
|
59
|
|
|
} |