Skip to content

Commit 80d53e7

Browse files
committed
improve docs
1 parent 01f3074 commit 80d53e7

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

doc/manual/phpxmlrpc_manual.adoc

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,10 @@ $srv = new Server(array(
688688
));
689689
----
690690

691+
In case a php method that you want to expose has `void` return type, given the fact that there is no such thing as "no
692+
return value" in the XML-RPC specification, the best approximation is to also use the class property `Value::$xmlrpcValue` to
693+
indicate the return type in the method signature.
694+
691695
==== Method handler functions [[method_handlers]]
692696

693697
The same php function can be registered as handler of multiple xml-rpc methods.
@@ -718,9 +722,14 @@ Here is a more detailed example of what a handler function "foo" might do:
718722
[source, php]
719723
----
720724
use PhpXmlRpc\PhpXmlRpc;
725+
use PhpXmlRpc\Request;
721726
use PhpXmlRpc\Response;
722727
use PhpXmlRpc\Value;
723728
729+
/**
730+
* @param Request $xmlrpcreq
731+
* @return Response
732+
*/
724733
function foo ($xmlrpcreq)
725734
{
726735
// retrieve method name
@@ -785,12 +794,18 @@ $srv = new Server(
785794
"signature" => array(
786795
array(Value::$xmlrpcStruct, Value::$xmlrpcInt),
787796
array(Value::$xmlrpcStruct, Value::$xmlrpcInt, $xmlrpcString)
788-
)
797+
),
798+
"parameters_type" => "phpvals"
789799
)
790800
),
791801
false
792802
);
793-
$srv->setOption(Server::OPT_FUNCTIONS_PARAMETERS_TYPE, 'phpvals');
803+
804+
// The line below is an alternative to specifying `parameters_type` for every method in the dispatch map. It applies
805+
// to all php functions registered with the server.
806+
// If both the server option and the `parameters_type` are set, the latter takes precedence.
807+
//$srv->setOption(Server::OPT_FUNCTIONS_PARAMETERS_TYPE, 'phpvals');
808+
794809
$srv->service();
795810
----
796811

src/Server.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Server
4545
/**
4646
* @var string
4747
* Defines how functions in $dmap will be invoked: either using an xml-rpc Request object or plain php values.
48-
* Valid strings are 'xmlrpcvals', 'phpvals' or 'epivals' (only for use by polyfill-xmlrpc).
48+
* Valid strings are 'xmlrpcvals', 'phpvals' or 'epivals' (the latter only for use by polyfill-xmlrpc).
4949
*
5050
* @todo create class constants for these
5151
*/
@@ -163,7 +163,7 @@ class Server
163163
* - docstring (optional)
164164
* - signature (array, optional)
165165
* - signature_docs (array, optional)
166-
* - parameters_type (string, optional)
166+
* - parameters_type (string, optional). Valid values: 'phpvals', 'xmlrpcvals'
167167
* - exception_handling (int, optional)
168168
* @param boolean $serviceNow set to false in order to prevent the server from running upon construction
169169
*/
@@ -710,6 +710,9 @@ public function parseRequest($data, $reqEncoding = '')
710710

711711
$xmlRpcParser = $this->getParser();
712712
try {
713+
// NB: during parsing, the actual type of php values built will be automatically switched from
714+
// $this->functions_parameters_type to the one defined in the method signature, if defined there. This
715+
// happens via the parser making a call to $this->methodNameCallback as soon as it finds the desired method
713716
$_xh = $xmlRpcParser->parse($data, $this->functions_parameters_type, XMLParser::ACCEPT_REQUEST, $options);
714717
// BC
715718
if (!is_array($_xh)) {

0 commit comments

Comments
 (0)