cvs: php4 /pear/PEAR Remote.php

From: Date: Tue, 14 May 2002 01:51:06 +0000
Subject: cvs: php4 /pear/PEAR Remote.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-3818@lists.php.net to get a copy of this message
ssb Mon May 13 21:51:06 2002 EDT Modified files: /php4/pear/PEAR Remote.php Log: * fall back to XML_RPC if xmlrpc-epi is not loaded # still buggy Index: php4/pear/PEAR/Remote.php diff -u php4/pear/PEAR/Remote.php:1.18 php4/pear/PEAR/Remote.php:1.19 --- php4/pear/PEAR/Remote.php:1.18 Sun Apr 28 03:34:46 2002 +++ php4/pear/PEAR/Remote.php Mon May 13 21:51:06 2002 @@ -16,7 +16,7 @@ // | Author: Stig Bakken <ssb@fast.no> | // +----------------------------------------------------------------------+ // -// $Id: Remote.php,v 1.18 2002/04/28 07:34:46 ssb Exp $ +// $Id: Remote.php,v 1.19 2002/05/14 01:51:06 ssb Exp $ require_once 'PEAR.php'; require_once 'PEAR/Config.php'; @@ -51,10 +51,29 @@ $args = func_get_args(); return call_user_func_array(array(&$this, 'call_epi'), $args); } - if (!include_once("XML/RPC.php")) { - return $this->raiseError("XML_RPC package not installed"); + if (!@include_once("XML/RPC.php")) { + return $this->raiseError("For this remote PEAR operation you need to install the XML_RPC package"); } - return $this->raiseError("XML_RPC fallback not yet implemented"); + $args = func_get_args(); + array_shift($args); + $server_host = $this->config->get('master_server'); + $username = $this->config->get('username'); + $password = $this->config->get('password'); + $f = new XML_RPC_Message($method, $this->_encode($args)); + $c = new XML_RPC_Client('/xmlrpc.php', $server_host, 80); + if ($username && $password) { + $c->setCredentials($username, $password); + } + $c->setDebug(1); + $r = $c->send($f); + if (!$r) { + return $this->raiseError("XML_RPC send failed"); + } + $v = $r->value(); + if ($e = $r->faultCode()) { + return $this->raiseError($r->faultString(), $e); + } + return XML_RPC_decode($v); } // }}} @@ -166,6 +185,74 @@ } // }}} + + // {{{ _encode + + // a slightly extended version of XML_RPC_encode + function _encode($php_val) + { + global $XML_RPC_Boolean, $XML_RPC_Int, $XML_RPC_Double; + global $XML_RPC_String, $XML_RPC_Array, $XML_RPC_Struct; + + $type = gettype($php_val); + $xmlrpcval = new XML_RPC_value; + + switch($type) { + case "array": + reset($php_val); + $firstkey = key($php_val); + end($php_val); + $lastkey = key($php_val); + if ($firstkey === 0 && is_int($lastkey) && + ($lastkey + 1) == count($php_val)) { + $is_continous = true; + reset($php_val); + for ($expect = 0; $expect < count($php_val); $expect++) { + if (key($php_val) !== $expect) { + $is_continous = false; + break; + } + } + if ($is_continous) { + reset($php_val); + $arr = array(); + while (list($k, $v) = each($php_val)) { + $arr[$k] = $this->_encode($v); + } + $xmlrpcval->addArray($arr); + break; + } + } + // fall though if not numerical and continous + case "object": + $arr = array(); + while (list($k, $v) = each($php_val)) { + $arr[$k] = $this->_encode($v); + } + $xmlrpcval->addStruct($arr); + break; + case "integer": + $xmlrpcval->addScalar($php_val, $XML_RPC_Int); + break; + case "double": + $xmlrpcval->addScalar($php_val, $XML_RPC_Double); + break; + case "string": + case "NULL": + $xmlrpcval->addScalar($php_val, $XML_RPC_String); + break; + case "boolean": + $xmlrpcval->addScalar($php_val, $XML_RPC_Boolean); + break; + case "unknown type": + default: + return null; + } + return $xmlrpcval; + } + + // }}} + } ?>

« previous php.pear.cvs (#3818) next »