1 | <?php |
||
39 | class SoapClient extends \SoapClient implements Log\LoggerAwareInterface |
||
40 | { |
||
41 | use Log\LoggerAwareTrait; |
||
42 | |||
43 | const REMOVE_EMPTY_XSLT_LOCATION = 'SoapClient/removeempty.xslt'; |
||
44 | |||
45 | /** |
||
46 | * Construct a new SoapClient |
||
47 | * |
||
48 | * @param string $wsdl Location of WSDL file |
||
49 | * @param array $options initialisation options |
||
50 | * @param Log\LoggerInterface|null $logger Error logging object |
||
51 | */ |
||
52 | 15 | public function __construct($wsdl, $options, Log\LoggerInterface $logger = null) |
|
53 | { |
||
54 | 15 | if (!($logger instanceof Log\LoggerInterface)) { |
|
55 | 9 | $logger = new Log\NullLogger(); |
|
56 | } |
||
57 | 15 | $this->setLogger($logger); |
|
58 | |||
59 | 15 | parent::__construct($wsdl, $options); |
|
|
|||
60 | 15 | } |
|
61 | |||
62 | /** |
||
63 | * __doRequest override of SoapClient |
||
64 | * |
||
65 | * @param string $request The XML SOAP request. |
||
66 | * @param string $location The URL to request. |
||
67 | * @param string $action The SOAP action. |
||
68 | * @param int $version The SOAP version. |
||
69 | * @param int|null $oneWay |
||
70 | * @uses parent::__doRequest |
||
71 | * @return string The XML SOAP response. |
||
72 | * @throws Exception When PHP XSL extension is not enabled or WSDL file isn't readable. |
||
73 | */ |
||
74 | public function __doRequest($request, $location, $action, $version, $oneWay = null) |
||
84 | |||
85 | /** |
||
86 | * @param string $request |
||
87 | * @return string |
||
88 | * @throws Exception when XSLT file isn't readable |
||
89 | */ |
||
90 | 9 | protected function transformIncomingRequest($request) |
|
128 | } |
||
129 |
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: