*/
function inner_findstate($stateno)
{
    global $stateNames;
    if (isset($stateNames[$stateno - 1])) {
        return $stateNames[$stateno - 1];
    } else {
        // not, there so complain
        return "I don't have a state for the index '" . $stateno . "'";
    }
}
$findstate2_sig = wrap_php_function('inner_findstate');
$findstate3_sig = wrap_php_function(array('xmlrpc_server_methods_container', 'findstate'));
$findstate5_sig = wrap_php_function('xmlrpc_server_methods_container::findstate');
$obj = new xmlrpc_server_methods_container();
$findstate4_sig = wrap_php_function(array($obj, 'findstate'));
$addtwo_sig = array(array($xmlrpcInt, $xmlrpcInt, $xmlrpcInt));
$addtwo_doc = 'Add two integers together and return the result';
function addtwo($m)
{
    $s = $m->getParam(0);
    $t = $m->getParam(1);
    return new xmlrpcresp(new xmlrpcval($s->scalarval() + $t->scalarval(), "int"));
}
$addtwodouble_sig = array(array($xmlrpcDouble, $xmlrpcDouble, $xmlrpcDouble));
$addtwodouble_doc = 'Add two doubles together and return the result';
function addtwodouble($m)
{
    $s = $m->getParam(0);
    $t = $m->getParam(1);
    return new xmlrpcresp(new xmlrpcval($s->scalarval() + $t->scalarval(), "double"));
Example #2
0
 * Inner code of the state-number server.
 * Used to test auto-registration of PHP funcions as xmlrpc methods.
 * @param integer $stateno the state number
 * @return string the name of the state (or error descrption)
 */
function inner_findstate($stateno)
{
    global $stateNames;
    if (isset($stateNames[$stateno - 1])) {
        return $stateNames[$stateno - 1];
    } else {
        // not, there so complain
        return "I don't have a state for the index '" . $stateno . "'";
    }
}
$findstate2_sig = wrap_php_function('inner_findstate');
$addtwo_sig = array(array($xmlrpcInt, $xmlrpcInt, $xmlrpcInt));
$addtwo_doc = 'Add two integers together and return the result';
function addtwo($m)
{
    $s = $m->getParam(0);
    $t = $m->getParam(1);
    return new xmlrpcresp(new xmlrpcval($s->scalarval() + $t->scalarval(), "int"));
}
$addtwodouble_sig = array(array($xmlrpcDouble, $xmlrpcDouble, $xmlrpcDouble));
$addtwodouble_doc = 'Add two doubles together and return the result';
function addtwodouble($m)
{
    $s = $m->getParam(0);
    $t = $m->getParam(1);
    return new xmlrpcresp(new xmlrpcval($s->scalarval() + $t->scalarval(), "double"));
/**
 * Given a user-defined PHP class or php object, map its methods onto a list of
 * PHP 'wrapper' functions that can be exposed as xmlrpc methods from an xmlrpc_server
 * object and called from remote clients (as well as their corresponding signature info).
 *
 * @param mixed $classname the name of the class whose methods are to be exposed as xmlrpc methods, or an object instance of that class
 * @param array $extra_options see the docs for wrap_php_method for more options
 *        string method_type 'static', 'nonstatic', 'all' and 'auto' (default); the latter will switch between static and non-static depending on wheter $classname is a class name or object instance
 * @return array or false on failure
 *
 * @todo get_class_methods will return both static and non-static methods.
 *       we have to differentiate the action, depending on wheter we recived a class name or object
 */
function wrap_php_class($classname, $extra_options = array())
{
    $methodfilter = isset($extra_options['method_filter']) ? $extra_options['method_filter'] : '';
    $methodtype = isset($extra_options['method_type']) ? $extra_options['method_type'] : 'auto';
    if (version_compare(phpversion(), '5.0.3') == -1) {
        // up to php 5.0.3 some useful reflection methods were missing
        error_log('XML-RPC: cannot not wrap php functions unless running php version bigger than 5.0.3');
        return false;
    }
    $result = array();
    $mlist = get_class_methods($classname);
    foreach ($mlist as $mname) {
        if ($methodfilter == '' || preg_match($methodfilter, $mname)) {
            // echo $mlist."\n";
            $func = new ReflectionMethod($classname, $mname);
            if (!$func->isPrivate() && !$func->isProtected() && !$func->isConstructor() && !$func->isDestructor() && !$func->isAbstract()) {
                if ($func->isStatic && ($methodtype == 'all' || $methodtype == 'static' || $methodtype == 'auto' && is_string($classname)) || !$func->isStatic && ($methodtype == 'all' || $methodtype == 'nonstatic' || $methodtype == 'auto' && is_object($classname))) {
                    $methodwrap = wrap_php_function(array($classname, $mname), '', $extra_options);
                    if ($methodwrap) {
                        $result[$methodwrap['function']] = $methodwrap['function'];
                    }
                }
            }
        }
    }
    return $result;
}