| 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 | public function __construct($wsdl, array $options = []) |
||
| 20 | {
|
||
| 21 | 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 | $this->logFile = fopen($options['log_file'], "a"); |
||
| 26 | |||
| 27 | $options['trace'] = 1; |
||
| 28 | |||
| 29 | parent::__construct($wsdl, $options); |
||
| 30 | } |
||
| 31 | |||
| 32 | |||
| 33 | public function __destruct() |
||
| 34 | {
|
||
| 35 | fclose($this->logFile); |
||
| 36 | } |
||
| 37 | |||
| 38 | |||
| 39 | public function __call($functionName, $arguments) |
||
| 40 | {
|
||
| 41 | $response = parent::__call($functionName, $arguments); |
||
| 42 | |||
| 43 | $this->log("Date: " . date('Y-m-d H:i:s');
|
||
|
|
|||
| 44 | $this->log("Request {$functionName}: \n{$this->__getLastRequest()}\n");
|
||
| 45 | $this->log("Response {$functionName}: \n{$this->__getLastResponse()}\n");
|
||
| 46 | |||
| 47 | return $response; |
||
| 48 | } |
||
| 49 | |||
| 50 | |||
| 51 | protected function log($message) |
||
| 52 | {
|
||
| 53 | fwrite($this->logFile, $message); |
||
| 54 | } |
||
| 55 | } |
||
| 56 |