1 | <?php |
||
25 | class SoapClient extends \SoapClient implements ClientInterface |
||
26 | { |
||
27 | use LoggerAwareTrait; |
||
28 | |||
29 | const PROTOCOL = 'soap'; |
||
30 | |||
31 | /** |
||
32 | * @var ConverterInterface |
||
33 | */ |
||
34 | private $converter; |
||
35 | |||
36 | /** |
||
37 | * Guzzle Client for the SOAP calls. |
||
38 | * |
||
39 | * @var HttpClient |
||
40 | */ |
||
41 | private $httpClient; |
||
42 | |||
43 | /** |
||
44 | * @var Manager |
||
45 | */ |
||
46 | private $manager; |
||
47 | |||
48 | /** |
||
49 | * Soap settings. |
||
50 | * |
||
51 | * @var SoapSettings; |
||
52 | */ |
||
53 | private $settings; |
||
54 | |||
55 | /** |
||
56 | * Content types for SOAP versions. |
||
57 | * |
||
58 | * @var array(string=>string) |
||
59 | */ |
||
60 | protected static $versionToContentTypeMap = [ |
||
61 | SOAP_1_1 => 'text/xml; charset=utf-8', |
||
62 | SOAP_1_2 => 'application/soap+xml; charset=utf-8', |
||
63 | ]; |
||
64 | |||
65 | /** |
||
66 | * SoapClient constructor. |
||
67 | * |
||
68 | * @param SoapSettings $settings |
||
69 | * @param Manager $manager |
||
70 | * @param HttpClient $client |
||
71 | * |
||
72 | * @throws NoServerAvailableException |
||
73 | * @throws \InvalidArgumentException |
||
74 | * @throws \Ddeboer\Transcoder\Exception\ExtensionMissingException |
||
75 | * @throws \Ddeboer\Transcoder\Exception\UnsupportedEncodingException |
||
76 | */ |
||
77 | 14 | public function __construct(SoapSettings $settings, Manager $manager, HttpClient $client) |
|
91 | |||
92 | /** |
||
93 | * Triggers the SOAP request over HTTP. |
||
94 | * Sent request by cURL instead of native SOAP request. |
||
95 | * |
||
96 | * @param string $request |
||
97 | * @param string $location |
||
98 | * @param string $action |
||
99 | * @param int $version |
||
100 | * @param string|null $one_way |
||
101 | * |
||
102 | * @return string The XML SOAP response. |
||
103 | * @throws WsClientException |
||
104 | * @throws NoServerAvailableException |
||
105 | * @throws \InvalidArgumentException |
||
106 | * @throws \SoapFault |
||
107 | */ |
||
108 | 6 | public function __doRequest($request, $location, $action, $version, $one_way = null) |
|
124 | |||
125 | /** |
||
126 | * Proxy function to SoapCall. |
||
127 | * |
||
128 | * @param array $args |
||
129 | * |
||
130 | * @return mixed |
||
131 | * @throws \Exception |
||
132 | * @throws \SoapFault |
||
133 | */ |
||
134 | 1 | public function call(array $args = []) |
|
143 | |||
144 | /** |
||
145 | * Determine the SOAPHeaders for given version. |
||
146 | * |
||
147 | * @param string $action |
||
148 | * |
||
149 | * @return array |
||
150 | */ |
||
151 | 6 | private function createHeaders($action) |
|
160 | |||
161 | /** |
||
162 | * Determines methods. |
||
163 | * For Soap it's either GET or POST. |
||
164 | * |
||
165 | * @param string|null $request |
||
166 | * |
||
167 | * @return string |
||
168 | */ |
||
169 | 6 | private static function determineMethod($request) |
|
173 | |||
174 | /** |
||
175 | * Http version of doRequest. |
||
176 | * |
||
177 | * @param string $requestBody |
||
178 | * @param string $location |
||
179 | * @param string $action |
||
180 | * |
||
181 | * @return string |
||
182 | * @throws WsClientException |
||
183 | * @throws \SoapFault |
||
184 | * @throws \InvalidArgumentException |
||
185 | * @todo move exception handler to middleware, find solution error suppressing |
||
186 | */ |
||
187 | 6 | private function doHttpRequest($requestBody, $location, $action) |
|
209 | |||
210 | /** |
||
211 | * @return ConverterInterface |
||
212 | */ |
||
213 | 5 | public function getConverter() |
|
217 | |||
218 | /** |
||
219 | * @param ConverterInterface $converter |
||
220 | */ |
||
221 | 9 | public function setConverter($converter) |
|
225 | |||
226 | /** |
||
227 | * @return HttpClient |
||
228 | */ |
||
229 | 1 | public function getHttpClient() |
|
233 | |||
234 | /** |
||
235 | * Return this connector over which a connection is established. |
||
236 | * |
||
237 | * @return string |
||
238 | */ |
||
239 | 4 | public function getProtocolName() |
|
243 | |||
244 | /** |
||
245 | * Log message. |
||
246 | * |
||
247 | * @param string $message |
||
248 | * @param int $level |
||
249 | * @param array $context |
||
250 | */ |
||
251 | 14 | public function log($message, $level, array $context = []) |
|
257 | |||
258 | /** |
||
259 | * Prepares the soapCall. |
||
260 | * |
||
261 | * @param string $function_name |
||
262 | * @param array $arguments |
||
263 | * @param array $options |
||
264 | * @param array $input_headers |
||
265 | * @param array|null $output_headers |
||
266 | * |
||
267 | * @return mixed |
||
268 | * @throws \Exception|\SoapFault |
||
269 | */ |
||
270 | 7 | public function __soapCall( |
|
288 | } |
||
289 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: