1 | <?php |
||
11 | class DebugSoapClient extends SoapClient |
||
12 | { |
||
13 | /** |
||
14 | * Log file (or stream) to use for logging SOAP requests/responses |
||
15 | * @var resource |
||
16 | */ |
||
17 | protected $logFile = null; |
||
18 | |||
19 | 1 | public function __construct($wsdl, array $options = []) |
|
20 | { |
||
21 | 1 | if (!array_key_exists('log_file', $options)) { |
|
22 | throw new Exception("Debug soap client requires a log file path provided as {$options['log_file']} to work"); |
||
23 | } |
||
24 | |||
25 | 1 | $this->logFile = fopen($options['log_file'], "w+"); |
|
26 | |||
27 | 1 | $options['trace'] = 1; |
|
28 | |||
29 | 1 | parent::__construct($wsdl, $options); |
|
|
|||
30 | 1 | } |
|
31 | |||
32 | |||
33 | 1 | public function __destruct() |
|
34 | { |
||
35 | 1 | fclose($this->logFile); |
|
36 | 1 | } |
|
37 | |||
38 | |||
39 | public function __call($functionName, $arguments) |
||
48 | |||
49 | |||
50 | protected function log($message) |
||
54 | } |
||
55 |
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: