addArray() public method

public addArray ( $vals )
 function _xmlrpcs_listMethods($server, $m)
 {
     global $xmlrpcerr, $xmlrpcstr, $_xmlrpcs_dmap;
     $v = new xmlrpcval();
     $dmap = $server->dmap;
     $outAr = array();
     for (reset($dmap); list($key, $val) = each($dmap);) {
         $outAr[] = new xmlrpcval($key, 'string');
     }
     $dmap = $_xmlrpcs_dmap;
     for (reset($dmap); list($key, $val) = each($dmap);) {
         $outAr[] = new xmlrpcval($key, 'string');
     }
     $v->addArray($outAr);
     return new xmlrpcresp($v);
 }
 function __phpxmlrpc_encapsulate($arg)
 {
     // The class xmlrpcval is defined in the phpxmlrpc library. It requires both the variable
     // and the type. Dates are handled through the API as ISO 8601 string representations.
     if (is_string($arg)) {
         $encapArg = new xmlrpcval($arg, 'string');
     } elseif (is_int($arg)) {
         $encapArg = new xmlrpcval($arg, 'int');
     } elseif (is_bool($arg)) {
         $encapArg = new xmlrpcval($arg, 'boolean');
     } elseif (is_array($arg)) {
         // The API server treats indexed arrays (lists) and associative arrays (dictionaries)
         // differently where in php they are essentially the same. Assuming that having a zero
         // index set indicates an indexed array is not perfect but should suffice for the
         // purpose of the API examples.
         if (isset($arg[0])) {
             $array = array();
             foreach ($arg as $key => $value) {
                 $array[] = $this->__phpxmlrpc_encapsulate($value);
             }
             $encapArray = new xmlrpcval();
             $encapArray->addArray($array);
             $encapArg = $encapArray;
         } else {
             $struct = array();
             foreach ($arg as $key => $value) {
                 $struct[$key] = $this->__phpxmlrpc_encapsulate($value);
             }
             $encapStruct = new xmlrpcval();
             $encapStruct->addStruct($struct);
             $encapArg = $encapStruct;
         }
     } else {
         $encapArg = new xmlrpcval($arg, 'string');
     }
     return $encapArg;
 }
Beispiel #3
0
function agesorter($m)
{
    global $agesorter_arr, $xmlrpcerruser, $s;
    xmlrpc_debugmsg("Entering 'agesorter'");
    // get the parameter
    $sno = $m->getParam(0);
    // error string for [if|when] things go wrong
    $err = "";
    // create the output value
    $v = new xmlrpcval();
    $agar = array();
    if (isset($sno) && $sno->kindOf() == "array") {
        $max = $sno->arraysize();
        // TODO: create debug method to print can work once more
        // print "<!-- found $max array elements -->\n";
        for ($i = 0; $i < $max; $i++) {
            $rec = $sno->arraymem($i);
            if ($rec->kindOf() != "struct") {
                $err = "Found non-struct in array at element {$i}";
                break;
            }
            // extract name and age from struct
            $n = $rec->structmem("name");
            $a = $rec->structmem("age");
            // $n and $a are xmlrpcvals,
            // so get the scalarval from them
            $agar[$n->scalarval()] = $a->scalarval();
        }
        $agesorter_arr = $agar;
        // hack, must make global as uksort() won't
        // allow us to pass any other auxilliary information
        uksort($agesorter_arr, agesorter_compare);
        $outAr = array();
        while (list($key, $val) = each($agesorter_arr)) {
            // recreate each struct element
            $outAr[] = new xmlrpcval(array("name" => new xmlrpcval($key), "age" => new xmlrpcval($val, "int")), "struct");
        }
        // add this array to the output value
        $v->addArray($outAr);
    } else {
        $err = "Must be one parameter, an array of structs";
    }
    if ($err) {
        return new xmlrpcresp(0, $xmlrpcerruser, $err);
    } else {
        return new xmlrpcresp($v);
    }
}
Beispiel #4
0
function processResult($result)
{
    $ret = new xmlrpcval();
    if (is_object($result)) {
        $result = get_object_vars($result);
    }
    if (is_associative_array($result)) {
        $ar = array();
        $keys = array_keys($result);
        foreach ($keys as $k) {
            $tmp = new xmlrpcval(array($k => new xmlrpcval($result[$k])), 'struct');
            $ar[] = $tmp;
        }
        $ret->addArray($ar);
    } else {
        if (is_array($result)) {
            foreach ($result as $key => $value) {
                if (!is_string($value)) {
                    $tmp = processResult($value);
                } else {
                    $tmp = new xmlrpcval();
                    $tmp->addScalar($value);
                }
                $result[$key] = $tmp;
            }
            $ret->addArray($result);
        } else {
            if (is_bool($result)) {
                $ret->addScalar($result, "boolean");
            } else {
                $ret->addScalar($result);
            }
        }
    }
    return $ret;
}