1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NFePHP\Common\Soap; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Soap fake class used for development only |
7
|
|
|
* |
8
|
|
|
* @category NFePHP |
9
|
|
|
* @package NFePHP\Common\Soap\SoapFake |
10
|
|
|
* @copyright NFePHP Copyright (c) 2017 |
11
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPLv3+ |
12
|
|
|
* @license https://opensource.org/licenses/MIT MIT |
13
|
|
|
* @license http://www.gnu.org/licenses/gpl.txt GPLv3+ |
14
|
|
|
* @author Roberto L. Machado <linux.rlm at gmail dot com> |
15
|
|
|
* @link http://github.com/nfephp-org/sped-common for the canonical source repository |
16
|
|
|
*/ |
17
|
|
|
use NFePHP\Common\Soap\SoapBase; |
18
|
|
|
use NFePHP\Common\Soap\SoapInterface; |
19
|
|
|
use NFePHP\Common\Exception\SoapException; |
20
|
|
|
use NFePHP\Common\Certificate; |
21
|
|
|
use Psr\Log\LoggerInterface; |
22
|
|
|
|
23
|
|
|
class SoapFake extends SoapBase implements SoapInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Constructor |
27
|
|
|
* @param Certificate $certificate |
28
|
|
|
* @param LoggerInterface $logger |
29
|
|
|
*/ |
30
|
4 |
|
public function __construct(Certificate $certificate = null, LoggerInterface $logger = null) |
31
|
|
|
{ |
32
|
4 |
|
parent::__construct($certificate, $logger); |
33
|
3 |
|
} |
34
|
|
|
|
35
|
|
|
public function send( |
36
|
|
|
$url, |
37
|
|
|
$operation = '', |
38
|
|
|
$action = '', |
39
|
|
|
$soapver = SOAP_1_2, |
40
|
|
|
$parameters = [], |
41
|
|
|
$namespaces = [], |
42
|
|
|
$request = '', |
43
|
|
|
$soapheader = null |
44
|
|
|
) { |
45
|
|
|
$envelope = $this->makeEnvelopeSoap( |
46
|
|
|
$request, |
47
|
|
|
$namespaces, |
48
|
|
|
$soapver, |
49
|
|
|
$soapheader |
50
|
|
|
); |
51
|
|
|
$msgSize = strlen($envelope); |
52
|
|
|
$parameters = [ |
53
|
|
|
"Content-Type: application/soap+xml;charset=utf-8;", |
54
|
|
|
"Content-length: $msgSize" |
55
|
|
|
]; |
56
|
|
|
if (!empty($action)) { |
57
|
|
|
$parameters[0] .= "action=$action"; |
58
|
|
|
} |
59
|
|
|
$requestHead = implode("\n", $parameters); |
60
|
|
|
$requestBody = $envelope; |
61
|
|
|
|
62
|
|
|
return json_encode([ |
63
|
|
|
'url' => $url, |
64
|
|
|
'operation' => $operation, |
65
|
|
|
'action' => $action, |
66
|
|
|
'soapver' => $soapver, |
67
|
|
|
'parameters' => $parameters, |
68
|
|
|
'header' => $requestHead, |
69
|
|
|
'namespaces' => $namespaces, |
70
|
|
|
'body' => $requestBody |
71
|
|
|
], JSON_PRETTY_PRINT); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|