home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / XML / RPC2 / Backend / Xmlrpcext / Client.php next >
Encoding:
PHP Script  |  2008-07-02  |  5.3 KB  |  136 lines

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
  4.  
  5. // LICENSE AGREEMENT. If folded, press za here to unfold and read license {{{ 
  6.  
  7. /**
  8. * +-----------------------------------------------------------------------------+
  9. * | Copyright (c) 2004-2006 Sergio Goncalves Carvalho                                |
  10. * +-----------------------------------------------------------------------------+
  11. * | This file is part of XML_RPC2.                                              |
  12. * |                                                                             |
  13. * | XML_RPC2 is free software; you can redistribute it and/or modify            |
  14. * | it under the terms of the GNU Lesser General Public License as published by |
  15. * | the Free Software Foundation; either version 2.1 of the License, or         |
  16. * | (at your option) any later version.                                         |
  17. * |                                                                             |
  18. * | XML_RPC2 is distributed in the hope that it will be useful,                 |
  19. * | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
  20. * | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
  21. * | GNU Lesser General Public License for more details.                         |
  22. * |                                                                             |
  23. * | You should have received a copy of the GNU Lesser General Public License    |
  24. * | along with XML_RPC2; if not, write to the Free Software                     |
  25. * | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA                    |
  26. * | 02111-1307 USA                                                              |
  27. * +-----------------------------------------------------------------------------+
  28. * | Author: Sergio Carvalho <sergio.carvalho@portugalmail.com>                  |
  29. * +-----------------------------------------------------------------------------+
  30. *
  31. * @category   XML
  32. * @package    XML_RPC2
  33. * @author     Sergio Carvalho <sergio.carvalho@portugalmail.com>  
  34. * @copyright  2004-2006 Sergio Carvalho
  35. * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  36. * @version    CVS: $Id: Client.php,v 1.14 2007/07/30 08:47:11 sergiosgc Exp $
  37. * @link       http://pear.php.net/package/XML_RPC2
  38. */
  39.  
  40. // }}}
  41.  
  42. // dependencies {{{
  43. require_once 'XML/RPC2/Exception.php';
  44. require_once 'XML/RPC2/Client.php';
  45. require_once 'XML/RPC2/Util/HTTPRequest.php';
  46. //}}}
  47.  
  48. /**
  49.  * XML_RPC client backend class. This backend class uses the XMLRPCext extension to execute the call.
  50.  *
  51.  * @category   XML
  52.  * @package    XML_RPC2
  53.  * @author     Sergio Carvalho <sergio.carvalho@portugalmail.com>  
  54.  * @copyright  2004-2006 Sergio Carvalho
  55.  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  56.  * @link       http://pear.php.net/package/XML_RPC2 
  57.  */
  58. class XML_RPC2_Backend_Xmlrpcext_Client extends XML_RPC2_Client
  59. {
  60.     
  61.     // {{{ constructor
  62.     
  63.     /**
  64.      * Construct a new XML_RPC2_Client PHP Backend.
  65.      *
  66.      * A URI must be provided (e.g. http://xmlrpc.example.com/1.0/). 
  67.      * Optionally, some options may be set.
  68.      *
  69.      * @param string URI for the XML-RPC server
  70.      * @param array (optional) Associative array of options
  71.      */
  72.     public function __construct($uri, $options = array())
  73.     {
  74.         parent::__construct($uri, $options);
  75.     }
  76.     
  77.     // }}}
  78.     // {{{ remoteCall()
  79.     
  80.     /**
  81.      * remoteCall executes the XML-RPC call, and returns the result
  82.      *
  83.      * NB : The '___' at the end of the method name is to avoid collisions with
  84.      * XMLRPC __call() 
  85.      *
  86.      * @param   string      Method name
  87.      * @param   array       Parameters
  88.      */
  89.     public function remoteCall___($methodName, $parameters)
  90.     {
  91.         $tmp = xmlrpc_encode_request($this->prefix . $methodName, $parameters, array('encoding' => $this->encoding));
  92.         if ($this->uglyStructHack) {
  93.             // ugly hack because of http://bugs.php.net/bug.php?id=21949
  94.             // see XML_RPC2_Backend_Xmlrpcext_Value::createFromNative() from more infos
  95.             $request = preg_replace('~<name>xml_rpc2_ugly_struct_hack_(.*)</name>~', '<name>\1</name>', $tmp);
  96.         } else {
  97.             $request = $tmp;
  98.         }
  99.         $uri = $this->uri;
  100.         $options = array(
  101.             'encoding' => $this->encoding,
  102.             'proxy' => $this->proxy,
  103.             'sslverify' => $this->sslverify
  104.         );
  105.         $httpRequest = new XML_RPC2_Util_HTTPRequest($uri, $options);
  106.         $httpRequest->setPostData($request);
  107.         $httpRequest->sendRequest();
  108.         $body = $httpRequest->getBody();
  109.         if ($this->debug) {
  110.             $this->displayDebugInformations___($request, $body);
  111.         }
  112.         $result = xmlrpc_decode($body, $this->encoding);
  113.         if ($result === false) {
  114.             if ($this->debug) {
  115.                 print "XML_RPC2_Exception : unable to decode response !";
  116.             }
  117.             throw new XML_RPC2_Exception('Unable to decode response');
  118.         }
  119.         if (xmlrpc_is_fault($result)) {
  120.             if ($this->debug) {
  121.                 print "XML_RPC2_FaultException(${result['faultString']}, ${result['faultCode']})";
  122.             }
  123.             throw new XML_RPC2_FaultException($result['faultString'], $result['faultCode']);
  124.         }
  125.         if ($this->debug) {
  126.             $this->displayDebugInformations2___($result);
  127.         }
  128.         return $result;
  129.     }
  130.     
  131.     // }}}
  132.     
  133. }
  134.  
  135. ?>
  136.