Skip to content

Commit

Permalink
improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
gggeek committed Apr 25, 2024
1 parent 01f3074 commit 80d53e7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
19 changes: 17 additions & 2 deletions doc/manual/phpxmlrpc_manual.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,10 @@ $srv = new Server(array(
));
----

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
return value" in the XML-RPC specification, the best approximation is to also use the class property `Value::$xmlrpcValue` to
indicate the return type in the method signature.

==== Method handler functions [[method_handlers]]

The same php function can be registered as handler of multiple xml-rpc methods.
Expand Down Expand Up @@ -718,9 +722,14 @@ Here is a more detailed example of what a handler function "foo" might do:
[source, php]
----
use PhpXmlRpc\PhpXmlRpc;
use PhpXmlRpc\Request;
use PhpXmlRpc\Response;
use PhpXmlRpc\Value;
/**
* @param Request $xmlrpcreq
* @return Response
*/
function foo ($xmlrpcreq)
{
// retrieve method name
Expand Down Expand Up @@ -785,12 +794,18 @@ $srv = new Server(
"signature" => array(
array(Value::$xmlrpcStruct, Value::$xmlrpcInt),
array(Value::$xmlrpcStruct, Value::$xmlrpcInt, $xmlrpcString)
)
),
"parameters_type" => "phpvals"
)
),
false
);
$srv->setOption(Server::OPT_FUNCTIONS_PARAMETERS_TYPE, 'phpvals');
// The line below is an alternative to specifying `parameters_type` for every method in the dispatch map. It applies
// to all php functions registered with the server.
// If both the server option and the `parameters_type` are set, the latter takes precedence.
//$srv->setOption(Server::OPT_FUNCTIONS_PARAMETERS_TYPE, 'phpvals');
$srv->service();
----

Expand Down
7 changes: 5 additions & 2 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Server
/**
* @var string
* Defines how functions in $dmap will be invoked: either using an xml-rpc Request object or plain php values.
* Valid strings are 'xmlrpcvals', 'phpvals' or 'epivals' (only for use by polyfill-xmlrpc).
* Valid strings are 'xmlrpcvals', 'phpvals' or 'epivals' (the latter only for use by polyfill-xmlrpc).
*
* @todo create class constants for these
*/
Expand Down Expand Up @@ -163,7 +163,7 @@ class Server
* - docstring (optional)
* - signature (array, optional)
* - signature_docs (array, optional)
* - parameters_type (string, optional)
* - parameters_type (string, optional). Valid values: 'phpvals', 'xmlrpcvals'
* - exception_handling (int, optional)
* @param boolean $serviceNow set to false in order to prevent the server from running upon construction
*/
Expand Down Expand Up @@ -710,6 +710,9 @@ public function parseRequest($data, $reqEncoding = '')

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

0 comments on commit 80d53e7

Please sign in to comment.