1 | <?php |
||
24 | class SoapClient extends \SoapClient implements ClientInterface |
||
25 | { |
||
26 | use LoggerAwareTrait; |
||
27 | |||
28 | const PROTOCOL = 'soap'; |
||
29 | |||
30 | /** |
||
31 | * @var ConverterInterface |
||
32 | */ |
||
33 | private $converter; |
||
34 | |||
35 | /** |
||
36 | * Guzzle Client for the SOAP calls. |
||
37 | * |
||
38 | * @var HttpClient |
||
39 | */ |
||
40 | private $httpClient; |
||
41 | |||
42 | /** |
||
43 | * @var Manager |
||
44 | */ |
||
45 | private $manager; |
||
46 | |||
47 | /** |
||
48 | * Soap settings. |
||
49 | * |
||
50 | * @var SoapSettings; |
||
51 | */ |
||
52 | private $settings; |
||
53 | |||
54 | /** |
||
55 | * Content types for SOAP versions. |
||
56 | * |
||
57 | * @var array(string=>string) |
||
58 | */ |
||
59 | protected static $versionToContentTypeMap = [ |
||
60 | SOAP_1_1 => 'text/xml; charset=utf-8', |
||
61 | SOAP_1_2 => 'application/soap+xml; charset=utf-8', |
||
62 | ]; |
||
63 | |||
64 | /** |
||
65 | * SoapClient constructor. |
||
66 | * |
||
67 | * @param SoapSettings $settings |
||
68 | * @param Manager $manager |
||
69 | * @param $client |
||
70 | * |
||
71 | * @throws NoServerAvailableException |
||
72 | * @throws \InvalidArgumentException |
||
73 | */ |
||
74 | public function __construct(SoapSettings $settings, Manager $manager, $client) |
||
87 | |||
88 | /** |
||
89 | * Triggers the SOAP request over HTTP. |
||
90 | * Sent request by cURL instead of native SOAP request. |
||
91 | * |
||
92 | * @param string $request |
||
93 | * @param string $location |
||
94 | * @param string $action |
||
95 | * @param int $version |
||
96 | * @param string|null $one_way |
||
97 | * |
||
98 | * @return string The XML SOAP response. |
||
99 | * @throws WsClientException |
||
100 | * @throws NoServerAvailableException |
||
101 | * @throws \InvalidArgumentException |
||
102 | * @throws \SoapFault |
||
103 | */ |
||
104 | public function __doRequest($request, $location, $action, $version, $one_way = null) |
||
120 | |||
121 | /** |
||
122 | * Proxy function to SoapCall |
||
123 | * |
||
124 | * @param array $args |
||
125 | * |
||
126 | * @return mixed |
||
127 | * @throws \Exception |
||
128 | * @throws \SoapFault |
||
129 | */ |
||
130 | public function call(array $args = []) |
||
139 | |||
140 | /** |
||
141 | * Determine the SOAPHeaders for given version. |
||
142 | * |
||
143 | * @param string $action |
||
144 | * |
||
145 | * @return array |
||
146 | */ |
||
147 | private function createHeaders($action) |
||
156 | |||
157 | /** |
||
158 | * Determines methods. |
||
159 | * For Soap it's either GET or POST. |
||
160 | * |
||
161 | * @param mixed $request |
||
162 | * |
||
163 | * @return string |
||
164 | */ |
||
165 | private static function determineMethod($request) |
||
169 | |||
170 | /** |
||
171 | * Http version of doRequest. |
||
172 | * |
||
173 | * @param mixed $requestBody |
||
174 | * @param string $location |
||
175 | * @param string $action |
||
176 | * |
||
177 | * @return string |
||
178 | * @throws WsClientException |
||
179 | * @throws \SoapFault |
||
180 | * @throws \InvalidArgumentException |
||
181 | * @todo move exception handler to middleware, find solution error suppressing |
||
182 | */ |
||
183 | private function doHttpRequest($requestBody, $location, $action) |
||
205 | |||
206 | /** |
||
207 | * @return ConverterInterface |
||
208 | */ |
||
209 | public function getConverter() |
||
213 | |||
214 | /** |
||
215 | * @param ConverterInterface $converter |
||
216 | */ |
||
217 | public function setConverter($converter) |
||
221 | |||
222 | /** |
||
223 | * @return httpClient |
||
224 | */ |
||
225 | public function getHttpClient() |
||
229 | |||
230 | /** |
||
231 | * Return this connector over which a connection is established. |
||
232 | * |
||
233 | * @return string |
||
234 | */ |
||
235 | public function getProtocolName() |
||
239 | |||
240 | /** |
||
241 | * Log message. |
||
242 | * |
||
243 | * @param string $message |
||
244 | * @param int $level |
||
245 | * @param array $context |
||
246 | */ |
||
247 | public function log($message, $level, array $context = []) |
||
253 | |||
254 | /** |
||
255 | * Prepares the soapCall. |
||
256 | * |
||
257 | * @param string $function_name |
||
258 | * @param array $arguments |
||
259 | * @param array $options |
||
260 | * @param array $input_headers |
||
261 | * @param array|null $output_headers |
||
262 | * |
||
263 | * @return mixed |
||
264 | * @throws \Exception|\SoapFault |
||
265 | */ |
||
266 | public function soapCall( |
||
284 | } |
||
285 |
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: