本文整理汇总了PHP中xmlrpcval类的典型用法代码示例。如果您正苦于以下问题:PHP xmlrpcval类的具体用法?PHP xmlrpcval怎么用?PHP xmlrpcval使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了xmlrpcval类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _xmlrpcs_listMethods
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);
}
示例2: xmlrpc_encode
function xmlrpc_encode($php_val)
{
global $xmlrpcInt;
global $xmlrpcDouble;
global $xmlrpcString;
global $xmlrpcArray;
global $xmlrpcStruct;
global $xmlrpcBoolean;
$type = gettype($php_val);
$xmlrpc_val = new xmlrpcval();
switch ($type) {
case "array":
case "object":
$arr = array();
while (list($k, $v) = each($php_val)) {
$arr[$k] = xmlrpc_encode($v);
}
$xmlrpc_val->addStruct($arr);
break;
case "integer":
$xmlrpc_val->addScalar($php_val, $xmlrpcInt);
break;
case "double":
$xmlrpc_val->addScalar($php_val, $xmlrpcDouble);
break;
case "string":
$xmlrpc_val->addScalar($php_val, $xmlrpcString);
break;
// <G_Giunta_2001-02-29>
// Add support for encoding/decoding of booleans, since they are supported in PHP
// <G_Giunta_2001-02-29>
// Add support for encoding/decoding of booleans, since they are supported in PHP
case "boolean":
$xmlrpc_val->addScalar($php_val, $xmlrpcBoolean);
break;
// </G_Giunta_2001-02-29>
// </G_Giunta_2001-02-29>
case "unknown type":
default:
// giancarlo pinerolo <ping@alt.it>
// it has to return
// an empty object in case (which is already
// at this point), not a boolean.
break;
}
return $xmlrpc_val;
}
示例3: array
<p></p>
<?php
include "xmlrpc.inc";
$inAr = array("Dave" => 24, "Edd" => 45, "Joe" => 37, "Fred" => 27);
reset($inAr);
print "This is the input data:<br/><pre>";
while (list($key, $val) = each($inAr)) {
print $key . ", " . $val . "\n";
}
print "</pre>";
// create parameters from the input array: an xmlrpc array of xmlrpc structs
$p = array();
foreach ($inAr as $key => $val) {
$p[] = new xmlrpcval(array("name" => new xmlrpcval($key), "age" => new xmlrpcval($val, "int")), "struct");
}
$v = new xmlrpcval($p, "array");
print "Encoded into xmlrpc format it looks like this: <pre>\n" . htmlentities($v->serialize()) . "</pre>\n";
// create client and message objects
$f = new xmlrpcmsg('examples.sortByAge', array($v));
$c = new xmlrpc_client("/server.php", "phpxmlrpc.sourceforge.net", 80);
// set maximum debug level, to have the complete communication printed to screen
$c->setDebug(2);
// send request
print "Now sending request (detailed debug info follows)";
$r =& $c->send($f);
// check response for errors, and take appropriate action
if (!$r->faultCode()) {
print "The server gave me these results:<pre>";
$v = $r->value();
$max = $v->arraysize();
for ($i = 0; $i < $max; $i++) {
示例4: switch
switch ($task) {
case 'list_methods':
jimport('joomla.html.html');
$msg = new xmlrpcmsg('system.listMethods');
$xmlrpcdoc = $client->send($msg);
//echo var_dump($xmlrpcdoc);
//die;
if ($xmlrpcdoc->faultCode() == 0) {
$result = $xmlrpcdoc->value();
$array = $result->scalarval();
} else {
print $xmlrpcdoc->faultString();
}
$methods = array();
for ($i = 0; $i < sizeof($array); $i++) {
$var = new xmlrpcval($array[$i]);
$array_method = $var->scalarval();
$methods[$i] = JHTML::_('select.option', $array_method->scalarval());
}
$output = 'Methods<br />';
$output .= JHTML::_('select.genericlist', $methods, 'method', 'size="10"', 'value', 'text');
$output .= ' <input name="args" type="text" />';
$output .= ' <input name="task" type="submit" value="exec" />';
break;
case 'exec':
$method = JRequest::getVar('method', '', '', 'cmd');
$args = JRequest::getVar('args');
$message = new xmlrpcmsg($method, array(new xmlrpcval(0, "int")));
$xmlrpcdoc = $client->send($message);
if ($xmlrpcdoc->faultCode() == 0) {
$scalar_var = $xmlrpcdoc->value();
示例5: testStringInt
function testStringInt()
{
$v = new xmlrpcval('hello world', 'int');
$s = $v->serialize();
$this->assertequals("<value><int>0</int></value>\n", $s);
}
示例6: php_xmlrpc_decode
/**
* Takes an xmlrpc value in PHP xmlrpcval object format and translates it into native PHP types.
*
* Works with xmlrpc message objects as input, too.
*
* Given proper options parameter, can rebuild generic php object instances
* (provided those have been encoded to xmlrpc format using a corresponding
* option in php_xmlrpc_encode())
* PLEASE NOTE that rebuilding php objects involves calling their constructor function.
* This means that the remote communication end can decide which php code will
* get executed on your server, leaving the door possibly open to 'php-injection'
* style of attacks (provided you have some classes defined on your server that
* might wreak havoc if instances are built outside an appropriate context).
* Make sure you trust the remote server/client before eanbling this!
*
* @author Dan Libby (dan@libby.com)
*
* @param xmlrpcval $xmlrpc_val
* @param array $options if 'decode_php_objs' is set in the options array, xmlrpc structs can be decoded into php objects
* @return mixed
*/
function php_xmlrpc_decode($xmlrpc_val, $options=array())
{
switch($xmlrpc_val->kindOf())
{
case 'scalar':
if (in_array('extension_api', $options))
{
reset($xmlrpc_val->me);
list($typ,$val) = each($xmlrpc_val->me);
switch ($typ)
{
case 'dateTime.iso8601':
$xmlrpc_val->scalar = $val;
$xmlrpc_val->xmlrpc_type = 'datetime';
$xmlrpc_val->timestamp = iso8601_decode($val);
return $xmlrpc_val;
case 'base64':
$xmlrpc_val->scalar = $val;
$xmlrpc_val->type = $typ;
return $xmlrpc_val;
default:
return $xmlrpc_val->scalarval();
}
}
return $xmlrpc_val->scalarval();
case 'array':
$size = $xmlrpc_val->arraysize();
$arr = array();
for($i = 0; $i < $size; $i++)
{
$arr[] = php_xmlrpc_decode($xmlrpc_val->arraymem($i), $options);
}
return $arr;
case 'struct':
$xmlrpc_val->structreset();
// If user said so, try to rebuild php objects for specific struct vals.
/// @todo should we raise a warning for class not found?
// shall we check for proper subclass of xmlrpcval instead of
// presence of _php_class to detect what we can do?
if (in_array('decode_php_objs', $options) && $xmlrpc_val->_php_class != ''
&& class_exists($xmlrpc_val->_php_class))
{
$obj = @new $xmlrpc_val->_php_class;
while(list($key,$value)=$xmlrpc_val->structeach())
{
$obj->$key = php_xmlrpc_decode($value, $options);
}
return $obj;
}
else
{
$arr = array();
while(list($key,$value)=$xmlrpc_val->structeach())
{
$arr[$key] = php_xmlrpc_decode($value, $options);
}
return $arr;
}
case 'msg':
$paramcount = $xmlrpc_val->getNumParams();
$arr = array();
for($i = 0; $i < $paramcount; $i++)
{
$arr[] = php_xmlrpc_decode($xmlrpc_val->getParam($i));
}
return $arr;
}
}
示例7: testDateTime
public function testDateTime()
{
$time = time();
$t1 = new xmlrpcval($time, 'dateTime.iso8601');
$t2 = new xmlrpcval(iso8601_encode($time), 'dateTime.iso8601');
$this->assertEquals($t1->serialize(), $t2->serialize());
if (class_exists('DateTime')) {
$datetime = new DateTime();
// skip this test for php 5.2. It is a bit harder there to build a DateTime from unix timestamp with proper TZ info
if (is_callable(array($datetime, 'setTimestamp'))) {
$t3 = new xmlrpcval($datetime->setTimestamp($time), 'dateTime.iso8601');
$this->assertEquals($t1->serialize(), $t3->serialize());
}
}
}
示例8: xmlrpcmsg
<body>
<?php
include "xmlrpc.inc";
$f = new xmlrpcmsg('examples.getStateName');
print "<h3>Testing value serialization</h3>\n";
$v = new xmlrpcval(23, "int");
print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
$v = new xmlrpcval("What are you saying? >> << &&");
print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
$v = new xmlrpcval(array(new xmlrpcval("ABCDEFHIJ"), new xmlrpcval(1234, 'int'), new xmlrpcval(1, 'boolean')), "array");
print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
$v = new xmlrpcval(array("thearray" => new xmlrpcval(array(new xmlrpcval("ABCDEFHIJ"), new xmlrpcval(1234, 'int'), new xmlrpcval(1, 'boolean'), new xmlrpcval(0, 'boolean'), new xmlrpcval(true, 'boolean'), new xmlrpcval(false, 'boolean')), "array"), "theint" => new xmlrpcval(23, 'int'), "thestring" => new xmlrpcval("foobarwhizz"), "thestruct" => new xmlrpcval(array("one" => new xmlrpcval(1, 'int'), "two" => new xmlrpcval(2, 'int')), "struct")), "struct");
print "<PRE>" . htmlentities($v->serialize()) . "</PRE>";
$w = new xmlrpcval(array($v, new xmlrpcval("That was the struct!")), "array");
print "<PRE>" . htmlentities($w->serialize()) . "</PRE>";
$w = new xmlrpcval("Mary had a little lamb,\nWhose fleece was white as snow,\nAnd everywhere that Mary went\nthe lamb was sure to go.\n\nMary had a little lamb\nShe tied it to a pylon\nTen thousand volts went down its back\nAnd turned it into nylon", "base64");
print "<PRE>" . htmlentities($w->serialize()) . "</PRE>";
print "<PRE>Value of base64 string is: '" . $w->scalarval() . "'</PRE>";
$f->method('');
$f->addParam(new xmlrpcval("41", "int"));
print "<h3>Testing request serialization</h3>\n";
$op = $f->serialize();
print "<PRE>" . htmlentities($op) . "</PRE>";
print "<h3>Testing ISO date format</h3><pre>\n";
$t = time();
$date = iso8601_encode($t);
print "Now is {$t} --> {$date}\n";
print "Or in UTC, that is " . iso8601_encode($t, 1) . "\n";
$tb = iso8601_decode($date);
print "That is to say {$date} --> {$tb}\n";
print "Which comes out at " . iso8601_encode($tb) . "\n";
示例9: processResult
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;
}
示例10: TestLocale
function TestLocale()
{
$locale = setlocale(LC_NUMERIC, 0);
/// @todo on php 5.3/win setting locale to german does not seem to set decimal separator to comma...
if (setlocale(LC_NUMERIC, 'deu', 'de_DE@euro', 'de_DE', 'de', 'ge') !== false) {
$v = new xmlrpcval(1.1, 'double');
if (strpos($v->scalarval(), ',') == 1) {
$r = $v->serialize();
$this->assertequals(false, strpos($r, ','));
}
setlocale(LC_NUMERIC, $locale);
}
}
示例11: __phpxmlrpc_encapsulate
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;
}
示例12: testMinusOneString
function testMinusOneString()
{
$v = new xmlrpcval('-1');
$u = new xmlrpcval('-1', 'string');
$this->assertEquals($u->scalarval(), $v->scalarval());
}
示例13: TestLocale
function TestLocale()
{
$locale = setlocale(LC_NUMERIC, 0);
if (setlocale(LC_NUMERIC, 'deu', 'de_DE@euro', 'de_DE', 'de', 'ge') !== false) {
$v = new xmlrpcval(1.1, 'double');
$r = $v->serialize();
$this->assertequals(false, strpos($r, ','));
$this->assertequals(1, strpos($v->scalarval(), ','));
setlocale(LC_NUMERIC, $locale);
}
}
示例14: php_xmlrpc_decode
/**
* Takes an xmlrpc value in PHP xmlrpcval object format
* and translates it into native PHP types.
*
* @author Dan Libby (dan@libby.com)
*
* @param xmlrpcval $xmlrpc_val
* @param array $options if 'decode_php_objs' is set in the options array, xmlrpc structs can be decoded into php objects
* @return mixed
*/
function php_xmlrpc_decode($xmlrpc_val, $options = '')
{
$kind = $xmlrpc_val->kindOf();
if ($kind == 'scalar') {
return $xmlrpc_val->scalarval();
} elseif ($kind == 'array') {
$size = $xmlrpc_val->arraysize();
$arr = array();
for ($i = 0; $i < $size; $i++) {
$arr[] = php_xmlrpc_decode($xmlrpc_val->arraymem($i), $options);
}
return $arr;
} elseif ($kind == 'struct') {
$xmlrpc_val->structreset();
// If user said so, try to rebuild php objects for specific struct vals.
/// @todo should we raise a warning for class not found?
// shall we check for proper subclass of xmlrpcval instead of
// presence of _php_class to detect what we can do?
if (@in_array('decode_php_objs', $options) && $xmlrpc_val->_php_class != '' && class_exists($xmlrpc_val->_php_class)) {
$obj = @new $xmlrpc_val->_php_class();
while (list($key, $value) = $xmlrpc_val->structeach()) {
$obj->{$key} = php_xmlrpc_decode($value, $options);
}
return $obj;
} else {
$arr = array();
while (list($key, $value) = $xmlrpc_val->structeach()) {
$arr[$key] = php_xmlrpc_decode($value, $options);
}
return $arr;
}
}
}
示例15: _book_request
function _book_request($token, $fac, $rooms, $grooms)
{
$fac->request = 0;
$server = _serv();
$arooms = array();
foreach ($rooms as $rid => $how) {
$fat = new xmlrpcval();
$show = new xmlrpcval($how, 'int');
$srid = new xmlrpcval($rid, 'int');
$fat->addStruct(array('number' => $show, 'id' => $srid));
$arooms[] = $fat;
}
$lcode = $fac->lcode;
$message = new xmlrpcmsg('rooms_request', array(new xmlrpcval($token, 'string'), new xmlrpcval($lcode, 'int'), new xmlrpcval($arooms, 'array')));
$struct = $server->send($message)->value();
$res = _scal($struct, 0);
if ($res < 0) {
return -1;
}
$s = $struct->arraymem(1);
$br = parse_book_request($s);
$fac->request = $br;
return $br;
}