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 / Php / 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.10 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/Util/HTTPRequest.php';
  45. require_once 'XML/RPC2/Value.php';
  46. require_once 'XML/RPC2/Client.php';
  47. require_once 'XML/RPC2/Backend/Php/Request.php';
  48. require_once 'XML/RPC2/Backend/Php/Response.php';
  49. // }}}
  50.  
  51. /**
  52.  * XML_RPC client backend class. This is the default, all-php XML_RPC client backend.
  53.  *
  54.  * This backend does not require the xmlrpc extension to be compiled in. It implements
  55.  * XML_RPC based on the always present DOM and SimpleXML PHP5 extensions.
  56.  * 
  57.  * @category   XML
  58.  * @package    XML_RPC2
  59.  * @author     Sergio Carvalho <sergio.carvalho@portugalmail.com>  
  60.  * @copyright  2004-2006 Sergio Carvalho
  61.  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  62.  * @link       http://pear.php.net/package/XML_RPC2 
  63.  */
  64. class XML_RPC2_Backend_Php_Client extends XML_RPC2_Client
  65. {
  66.  
  67.     // {{{ constructor
  68.  
  69.     /**
  70.      * Construct a new XML_RPC2_Client PHP Backend.
  71.      *
  72.      * To create a new XML_RPC2_Client, a URI must be provided (e.g. http://xmlrpc.example.com/1.0/). 
  73.      * Optionally, some options may be set
  74.      *
  75.      * @param string URI for the XML-RPC server
  76.      * @param array (optional) Associative array of options
  77.      */
  78.     public function __construct($uri, $options = array())
  79.     {
  80.         parent::__construct($uri, $options);
  81.     }
  82.     
  83.     // }}} 
  84.     // {{{ remoteCall___()
  85.     
  86.     /**
  87.      * remoteCall executes the XML-RPC call, and returns the result
  88.      *
  89.      * NB : The '___' at the end of the method name is to avoid collisions with
  90.      * XMLRPC __call() 
  91.      *
  92.      * @param   string      Method name
  93.      * @param   array       Parameters
  94.      */
  95.     public function remoteCall___($methodName, $parameters)
  96.     {
  97.         $request = new XML_RPC2_Backend_Php_Request($this->prefix . $methodName, $this->encoding);
  98.         $request->setParameters($parameters);
  99.         $request = $request->encode();
  100.         $uri = $this->uri;
  101.         $options = array(
  102.             'encoding' => $this->encoding,
  103.             'proxy' => $this->proxy,
  104.             'sslverify' => $this->sslverify
  105.         );
  106.         $httpRequest = new XML_RPC2_Util_HTTPRequest($uri, $options);
  107.         $httpRequest->setPostData($request);
  108.         $httpRequest->sendRequest();
  109.         $body = $httpRequest->getBody();
  110.         if ($this->debug) {
  111.             $this->displayDebugInformations___($request, $body);
  112.         }
  113.         try {
  114.             $result = XML_RPC2_Backend_Php_Response::decode(simplexml_load_string($body));
  115.         } catch (XML_RPC2_Exception $e) {
  116.             if ($this->debug) {
  117.                 if (get_class($e)=='XML_RPC2_FaultException') {
  118.                     print "XML_RPC2_FaultException #" . $e->getFaultCode() . " : " . $e->getMessage();
  119.                 } else {
  120.                     print get_class($e) . " : " . $e->getMessage();
  121.                 }
  122.             }
  123.             throw $e;
  124.         }
  125.         if ($this->debug) {
  126.             $this->displayDebugInformations2___($result);
  127.         }
  128.         return $result;
  129.     }
  130.     
  131.     // }}}
  132.     
  133. }
  134.  
  135. ?>
  136.