1 | <?php |
||
12 | trait SoapManager |
||
13 | { |
||
14 | use ArrayManager; |
||
15 | |||
16 | /** |
||
17 | * URL of WSDL service to consume. |
||
18 | * |
||
19 | * @var string|null $wsdl |
||
20 | */ |
||
21 | private $wsdl; |
||
22 | /** |
||
23 | * Set of options for SOAP request. |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | private $options = []; |
||
28 | /** |
||
29 | * Response of SOAP method. |
||
30 | * |
||
31 | * @var mixed |
||
32 | */ |
||
33 | private $response = []; |
||
34 | /** |
||
35 | * Last SOAP response. |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | private $rawResponse = ''; |
||
40 | /** |
||
41 | * The URIs of the namespaces. |
||
42 | * |
||
43 | * @var string[] |
||
44 | */ |
||
45 | private $namespaces = []; |
||
46 | /** |
||
47 | * Latest exception thrown out during SOAP call. |
||
48 | * |
||
49 | * @var null|\SoapFault |
||
50 | */ |
||
51 | private $exception; |
||
52 | |||
53 | /** |
||
54 | * Set of headers for SOAP request. |
||
55 | * |
||
56 | * @var array |
||
57 | */ |
||
58 | private $headers = []; |
||
59 | |||
60 | /** |
||
61 | * Make SOAP call to a function with params. |
||
62 | * |
||
63 | * @link http://php.net/manual/en/soapclient.getlastrequest.php#example-5896 |
||
64 | * |
||
65 | * @param string $function |
||
66 | * SOAP function name to execute. Use MethodNameIsIgnored if function name is in the XML body. |
||
67 | * @param array $arguments |
||
68 | * Arguments array to pass to soap call function. |
||
69 | */ |
||
70 | public function sendRequest($function, array $arguments) |
||
92 | |||
93 | /** |
||
94 | * Extracts first value matching provided XPATH expression. |
||
95 | * |
||
96 | * @param string $query |
||
97 | * XPATH expression used to extract value from $this->rawResponse |
||
98 | * |
||
99 | * @return \DOMNode|bool |
||
100 | */ |
||
101 | protected function extractResponseValueMatchingXPATH($query) |
||
117 | |||
118 | /** |
||
119 | 4 | * Helper to extract a property value from the response. |
|
120 | 4 | * |
|
121 | * @param string $property |
||
122 | 4 | * |
|
123 | * @return mixed |
||
124 | */ |
||
125 | protected function extractResponseProperty($property) |
||
129 | |||
130 | /** |
||
131 | * @return null|\SoapFault |
||
132 | */ |
||
133 | protected function getException() |
||
142 | |||
143 | /** |
||
144 | * @param string $wsdl |
||
145 | */ |
||
146 | protected function setWSDL($wsdl) |
||
147 | { |
||
148 | // Allow "null" and valid URLs. |
||
149 | $isWsdlValid = null === $wsdl || filter_var($wsdl, FILTER_VALIDATE_URL); |
||
150 | // Set the URL if it is validated. |
||
151 | $this->wsdl = $isWsdlValid ? $wsdl : null; |
||
152 | |||
153 | // Throw deferred exception when WSDL was reset due to it invalidation. |
||
154 | if (!$isWsdlValid) { |
||
155 | throw new \InvalidArgumentException(sprintf('You must pass a correct WSDL or null to %s.', __METHOD__)); |
||
156 | } |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * @param array $options |
||
161 | */ |
||
162 | protected function setOptions(array $options = null) |
||
172 | /** |
||
173 | * @param array $headers |
||
174 | */ |
||
175 | protected function setHeaders(array $headers = null) |
||
183 | |||
184 | /** |
||
185 | * @param string $option |
||
186 | * @param mixed $value |
||
187 | */ |
||
188 | protected function setOption($option, $value) |
||
192 | |||
193 | /** |
||
194 | * @param array $namespaces |
||
195 | */ |
||
196 | protected function setNamespaces(array $namespaces = null) |
||
206 | |||
207 | /** |
||
208 | * @param string $prefix |
||
209 | * @param string $uri |
||
210 | */ |
||
211 | protected function setNamespace($prefix, $uri) |
||
215 | |||
216 | /** |
||
217 | * @return mixed |
||
218 | */ |
||
219 | public function getResponse() |
||
223 | |||
224 | /** |
||
225 | * @return string |
||
226 | */ |
||
227 | public function getRawResponse() |
||
231 | } |
||
232 |