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