3 * Defines functions and signatures which can be registered as methods exposed by an XMLRPC Server
5 * To use this, use something akin to:
6 * $signatures = include('wrapper.php');
8 * Wrap methods of xmlrpc-unaware php classes and xmlrpc-unaware php functions so that they can be used transparently.
11 use PhpXmlRpc\Response;
17 * Inner code of the state-number server.
18 * Used to test wrapping of PHP functions into xmlrpc methods.
20 * @param integer $stateNo the state number
22 * @return string the name of the state (or error description)
24 * @throws Exception if state is not found
26 function plain_findstate($stateNo)
30 if (isset($stateNames[$stateNo - 1])) {
31 return $stateNames[$stateNo - 1];
33 // not, there so complain
34 throw new Exception("I don't have a state for the index '" . $stateNo . "'", PhpXmlRpc\PhpXmlRpc::$xmlrpcerruser);
38 $wrapper = new PhpXmlRpc\Wrapper();
40 $findstate2_sig = $wrapper->wrapPhpFunction('plain_findstate');
43 // *** objects/classes ***
46 * Used to test usage of object methods in dispatch maps and in wrapper code.
48 class xmlrpcServerMethodsContainer
51 * Method used to test logging of php warnings generated by user functions.
52 * @param PhpXmlRpc\Request $req
55 public function phpWarningGenerator($req)
57 $a = $undefinedVariable; // this triggers a warning in E_ALL mode, since $undefinedVariable is undefined
58 return new Response(new Value(1, Value::$xmlrpcBoolean));
62 * Method used to test catching of exceptions in the server.
63 * @param PhpXmlRpc\Request $req
66 public function exceptionGenerator($req)
68 throw new Exception("it's just a test", 1);
74 public function debugMessageGenerator($msg)
76 PhpXmlRpc\Server::xmlrpc_debugmsg($msg);
80 * A PHP version of the state-number server. Send me an integer and i'll sell you a state.
81 * Used to test wrapping of PHP methods into xmlrpc methods.
87 public static function findState($num)
90 return plain_findstate($num);
94 * Returns an instance of stdClass.
95 * Used to test wrapping of PHP objects with class preservation
97 public function returnObject()
99 $obj = new stdClass();
100 $obj->hello = 'world';
105 $findstate3_sig = $wrapper->wrapPhpFunction(array('xmlrpcServerMethodsContainer', 'findState'));
107 $obj = new xmlrpcServerMethodsContainer();
108 $findstate4_sig = $wrapper->wrapPhpFunction(array($obj, 'findstate'));
110 $findstate5_sig = $wrapper->wrapPhpFunction('xmlrpcServerMethodsContainer::findState', '', array('return_source' => true));
111 eval($findstate5_sig['source']);
113 $findstate6_sig = $wrapper->wrapPhpFunction('plain_findstate', '', array('return_source' => true));
114 eval($findstate6_sig['source']);
116 $findstate7_sig = $wrapper->wrapPhpFunction(array('xmlrpcServerMethodsContainer', 'findState'), '', array('return_source' => true));
117 eval($findstate7_sig['source']);
119 //$obj = new xmlrpcServerMethodsContainer();
120 $findstate8_sig = $wrapper->wrapPhpFunction(array($obj, 'findstate'), '', array('return_source' => true));
121 eval($findstate8_sig['source']);
123 $findstate9_sig = $wrapper->wrapPhpFunction('xmlrpcServerMethodsContainer::findState', '', array('return_source' => true));
124 eval($findstate9_sig['source']);
126 $findstate10_sig = array(
127 /// @todo add a demo/test with a closure
128 "function" => function ($req) { return findState($req); },
129 "signature" => array(array(Value::$xmlrpcString, Value::$xmlrpcInt)),
130 "docstring" => 'When passed an integer between 1 and 51 returns the name of a US state, where the integer is the ' .
131 'index of that state name in an alphabetic order.',
134 $findstate11_sig = $wrapper->wrapPhpFunction(function ($stateNo) { return plain_findstate($stateNo); });
136 /// @todo do we really need a new instance ?
137 $c = new xmlrpcServerMethodsContainer();
139 $moreSignatures = $wrapper->wrapPhpClass($c, array('prefix' => 'tests.', 'method_type' => 'all'));
141 $returnObj_sig = $wrapper->wrapPhpFunction(array($c, 'returnObject'), '', array('encode_php_objs' => true));
145 'tests.getStateName.2' => $findstate2_sig,
146 'tests.getStateName.3' => $findstate3_sig,
147 'tests.getStateName.4' => $findstate4_sig,
148 'tests.getStateName.5' => $findstate5_sig,
149 'tests.getStateName.6' => $findstate6_sig,
150 'tests.getStateName.7' => $findstate7_sig,
151 'tests.getStateName.8' => $findstate8_sig,
152 'tests.getStateName.9' => $findstate9_sig,
153 'tests.getStateName.10' => $findstate10_sig,
154 'tests.getStateName.11' => $findstate11_sig,
155 'tests.returnPhpObject' => $returnObj_sig,