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 / Services / Blogging / XmlRpc.php < prev   
Encoding:
PHP Script  |  2008-07-02  |  1.9 KB  |  55 lines

  1. <?php
  2. require_once 'Services/Blogging/Exception.php';
  3. require_once 'XML/RPC.php';
  4.  
  5. /**
  6. * XmlRpc helper methods for the blogging API
  7. *
  8. * @category Services
  9. * @package  Services_Blogging
  10. * @author   Anant Narayanan <anant@php.net>
  11. * @author   Christian Weiske <cweiske@php.net>
  12. * @license  http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  13. * @link     http://pear.php.net/package/Services_Blogging
  14. */
  15. class Services_Blogging_XmlRpc
  16. {
  17.     /**
  18.     * The function that actually sends an XML-RPC request to the server, handles
  19.     * errors accordingly and returns the appropriately decoded data sent as response
  20.     * from the server.
  21.     *
  22.     * @param XML_RPC_Message $request An appropriately encoded XML-RPC message
  23.     *                                  that needs to be sent as a request to the
  24.     *                                  server.
  25.     * @param XML_RPC_Client  $client  The XML-RPC client as which the request
  26.     *                                  is to be sent.
  27.     *
  28.     * @return Array The appropriately decoded response sent by the server.
  29.     */
  30.     public static function sendRequest($request, $client)
  31.     {
  32.         $response = $client->send($request);
  33.         if (!$response) {
  34.             throw new Services_Blogging_Exception(
  35.                 'XML-RPC communication error: ' . $client->errstr
  36.             );
  37.         } else if ($response->faultCode() != 0) {
  38.             throw new Services_Blogging_Exception(
  39.                 $response->faultString(),
  40.                 $response->faultCode()
  41.             );
  42.         }
  43.  
  44.         $value = XML_RPC_Decode($response->value());
  45.         if (!is_array($value) || !isset($value['faultCode'])) {
  46.             return $value;
  47.         } else {
  48.             throw new Services_Blogging_Exception(
  49.                 $value['faultString'], $value['faultCode']
  50.             );
  51.         }
  52.     }//public static function sendRequest($request, $client)
  53.  
  54. }//class Services_Blogging_XmlRpc
  55. ?>