1 | <?php |
||
14 | class SoapServer extends NativeSoapServer |
||
15 | { |
||
16 | use ProcessesWithPipelines; |
||
17 | |||
18 | /** |
||
19 | * Creates and returns a new SoapServer with empty inbound and outbound |
||
20 | * pipelines. |
||
21 | * |
||
22 | * @param string|null $wsdl |
||
23 | * @param array $options |
||
24 | */ |
||
25 | public function __construct($wsdl, array $options = array()) |
||
33 | |||
34 | /** |
||
35 | * Handles a SOAP request. |
||
36 | * |
||
37 | * This function delegates on PHP's native SoapServer handle(), but |
||
38 | * processes the input XML through the inbound and outbound pipelines. This |
||
39 | * allows for arbitrary manipulation of requests and responses, such as |
||
40 | * encryption or logging. |
||
41 | * |
||
42 | * Just as the parent class, this function will fetch the input from the |
||
43 | * POST data if none is passed as an argument. Likewise, it will return |
||
44 | * nothing and output the response instead. |
||
45 | * |
||
46 | * @see http://php.net/manual/en/soapserver.handle.php |
||
47 | * @param string|null $soapRequest |
||
48 | */ |
||
49 | public function handle($soapRequest = null) |
||
77 | |||
78 | protected function outputResponse($soapResponse) |
||
85 | } |
||
86 |
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: