1
|
|
|
<?php |
2
|
|
|
require_once __DIR__ . "/_prepend.php"; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Demoing how to inject a custom logger for use by the library |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
use PhpXmlRpc\Client; |
9
|
|
|
use PhpXmlRpc\Encoder; |
10
|
|
|
use PhpXmlRpc\PhpXmlRpc; |
11
|
|
|
use PhpXmlRpc\Request; |
12
|
|
|
|
13
|
|
|
// Definition of a custom logger implementing the same API as the default one |
14
|
|
|
|
15
|
|
|
class MyLogger |
16
|
|
|
{ |
17
|
|
|
protected $debugBuffer = ''; |
18
|
|
|
protected $errorBuffer = ''; |
19
|
|
|
protected $warningBuffer = ''; |
20
|
|
|
|
21
|
|
|
// logger API |
22
|
|
|
public function debug($message, $context = array()) |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
$this->debugBuffer .= $message . "\n"; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function error($message, $context = array()) |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
$this->errorBuffer .= $message . "\n"; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function warning($message, $context = array()) |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
$this->warningBuffer .= $message . "\n"; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function getDebug() |
38
|
|
|
{ |
39
|
|
|
return $this->debugBuffer; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function getError() |
43
|
|
|
{ |
44
|
|
|
return $this->errorBuffer; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function getWarning() |
48
|
|
|
{ |
49
|
|
|
return $this->warningBuffer; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
// create the custom logger instance |
54
|
|
|
|
55
|
|
|
$logger = new MyLogger(); |
56
|
|
|
|
57
|
|
|
// inject it into all the classes (possibly) involved |
58
|
|
|
|
59
|
|
|
PhpXmlRpc::setLogger($logger); |
60
|
|
|
|
61
|
|
|
// then send a request |
62
|
|
|
|
63
|
|
|
$input = array( |
64
|
|
|
array('name' => 'Dave', 'age' => 24), |
65
|
|
|
array('name' => 'Edd', 'age' => 45), |
66
|
|
|
array('name' => 'Joe', 'age' => 37), |
67
|
|
|
array('name' => 'Fred', 'age' => 27), |
68
|
|
|
); |
69
|
|
|
|
70
|
|
|
$encoder = new Encoder(); |
71
|
|
|
$client = new Client(XMLRPCSERVER); |
72
|
|
|
|
73
|
|
|
// enable warnings for use of deprecated features |
74
|
|
|
PhpXmlRpc::$xmlrpc_silence_deprecations = false; |
75
|
|
|
|
76
|
|
|
// set maximum debug level, to have all the communication details logged |
77
|
|
|
$client->setDebug(2); |
78
|
|
|
|
79
|
|
|
// avid compressed responses, as they mess up the output if echoed on the command-line |
80
|
|
|
$client->setOption(Client::OPT_ACCEPTED_COMPRESSION, ''); |
81
|
|
|
|
82
|
|
|
// send request |
83
|
|
|
output("Sending the request. No output debug should appear below...<br>"); |
84
|
|
|
$request = new Request('examples.sortByAge', array($encoder->encode($input))); |
85
|
|
|
$response = $client->send($request); |
86
|
|
|
output("Response received.<br>"); |
87
|
|
|
|
88
|
|
|
output("The client error info is:<pre>\n" . $logger->getError() . "\n</pre>"); |
89
|
|
|
output("The client warning info is:<pre>\n" . $logger->getWarning() . "\n</pre>"); |
90
|
|
|
output("The client debug info is:<pre>\n" . $logger->getDebug() . "\n</pre>"); |
91
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.