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 / Exception.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  11.4 KB  |  332 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: Exception.php,v 1.7 2007/07/30 08:47:11 sergiosgc Exp $
  37. * @link       http://pear.php.net/package/XML_RPC2
  38. */
  39.  
  40. // }}}
  41.  
  42. /**
  43.  * XML_RPC2 base exception class. All XML_RPC2 originated exceptions inherit from XML_RPC2_Exception
  44.  * 
  45.  * @category   XML
  46.  * @package    XML_RPC2
  47.  * @author     Sergio Carvalho <sergio.carvalho@portugalmail.com>  
  48.  * @copyright  2004-2006 Sergio Carvalho
  49.  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  50.  * @link       http://pear.php.net/package/XML_RPC2
  51.  */
  52. class XML_RPC2_Exception extends Exception
  53. {
  54. }
  55.  
  56. /* Encoding and decoding values exceptions {{{
  57. /**
  58.  * XML_RPC2_InvalidTypeException is thrown whenever an invalid XML_RPC type is used in an operation
  59.  * 
  60.  * @category   XML
  61.  * @package    XML_RPC2
  62.  * @author     Sergio Carvalho <sergio.carvalho@portugalmail.com>  
  63.  * @copyright  2004-2006 Sergio Carvalho
  64.  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  65.  * @link       http://pear.php.net/package/XML_RPC2
  66.  */
  67. class XML_RPC2_InvalidTypeException extends XML_RPC2_Exception
  68. {
  69. }
  70.  
  71. /**
  72.  * XML_RPC2_InvalidTypeException is thrown when creating DateTime value objects from invalid string datetime representations
  73.  * 
  74.  * @category   XML
  75.  * @package    XML_RPC2
  76.  * @author     Sergio Carvalho <sergio.carvalho@portugalmail.com>  
  77.  * @copyright  2004-2006 Sergio Carvalho
  78.  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  79.  * @link       http://pear.php.net/package/XML_RPC2
  80.  */
  81. class XML_RPC2_InvalidDateFormatException extends XML_RPC2_Exception
  82. {
  83. }
  84.  
  85. /**
  86.  * XML_RPC2_EncodeException is thrown whenever a class is asked to encode itself in XML with invalid or not enough data.
  87.  * 
  88.  * @category   XML
  89.  * @package    XML_RPC2
  90.  * @author     Sergio Carvalho <sergio.carvalho@portugalmail.com>  
  91.  * @copyright  2004-2006 Sergio Carvalho
  92.  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  93.  * @link       http://pear.php.net/package/XML_RPC2
  94.  */
  95. class XML_RPC2_EncodeException extends XML_RPC2_Exception
  96. {
  97. }
  98.  
  99. /**
  100.  * XML_RPC2_DecodeException is thrown whenever there is a problem decoding transport XML
  101.  * 
  102.  * @category   XML
  103.  * @package    XML_RPC2
  104.  * @author     Sergio Carvalho <sergio.carvalho@portugalmail.com>  
  105.  * @copyright  2004-2006 Sergio Carvalho
  106.  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  107.  * @link       http://pear.php.net/package/XML_RPC2
  108.  */
  109. class XML_RPC2_DecodeException extends XML_RPC2_Exception
  110. {
  111. }
  112.  
  113. /**
  114.  * XML_RPC2_InvalidTypeEncodeException is thrown whenever a class is asked to encode itself and provided a PHP type 
  115.  * that can't be translated to XML_RPC
  116.  * 
  117.  * @category   XML
  118.  * @package    XML_RPC2
  119.  * @author     Sergio Carvalho <sergio.carvalho@portugalmail.com>  
  120.  * @copyright  2004-2006 Sergio Carvalho
  121.  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  122.  * @link       http://pear.php.net/package/XML_RPC2
  123.  */
  124. class XML_RPC2_InvalidTypeEncodeException extends XML_RPC2_Exception
  125. {
  126. }
  127. /* }}} */
  128.  
  129. /**
  130.  * XML_RPC2_InvalidUriException is thrown whenever the XML_RPC2 client is asked to use an invalid uri
  131.  * 
  132.  * @category   XML
  133.  * @package    XML_RPC2
  134.  * @author     Sergio Carvalho <sergio.carvalho@portugalmail.com>  
  135.  * @copyright  2004-2006 Sergio Carvalho
  136.  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  137.  * @link       http://pear.php.net/package/XML_RPC2
  138.  */
  139. class XML_RPC2_InvalidUriException extends XML_RPC2_Exception
  140. {
  141. }
  142.  
  143. /**
  144.  * XML_RPC2_InvalidPrefixException is thrown whenever the XML_RPC2 client is asked to use an invalid XML/RPC prefix
  145.  * 
  146.  * @category   XML
  147.  * @package    XML_RPC2
  148.  * @author     Sergio Carvalho <sergio.carvalho@portugalmail.com>  
  149.  * @copyright  2004-2006 Sergio Carvalho
  150.  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  151.  * @link       http://pear.php.net/package/XML_RPC2
  152.  */
  153. class XML_RPC2_InvalidPrefixException extends XML_RPC2_Exception
  154. {
  155. }
  156.  
  157. /**
  158.  * XML_RPC2_InvalidPrefixException is thrown whenever the XML_RPC2 client is asked to use an invalid XML/RPC debug flag
  159.  * 
  160.  * @category   XML
  161.  * @package    XML_RPC2
  162.  * @author     Sergio Carvalho <sergio.carvalho@portugalmail.com>  
  163.  * @copyright  2004-2006 Sergio Carvalho
  164.  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  165.  * @link       http://pear.php.net/package/XML_RPC2
  166.  */
  167. class XML_RPC2_InvalidDebugException extends XML_RPC2_Exception
  168. {
  169. }
  170.  
  171. /**
  172.  * XML_RPC2_InvalidSslverifyException is thrown whenever the XML_RPC2 client is asked to use an invalid XML/RPC SSL verify flag
  173.  * 
  174.  * @category   XML
  175.  * @package    XML_RPC2
  176.  * @author     Sergio Carvalho <sergio.carvalho@portugalmail.com>  
  177.  * @copyright  2004-2006 Sergio Carvalho
  178.  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  179.  * @link       http://pear.php.net/package/XML_RPC2
  180.  */
  181. class XML_RPC2_InvalidSslverifyException extends XML_RPC2_Exception
  182. {
  183. }
  184.  
  185. /**
  186.  * XML_RPC2_FaultException signals a XML-RPC response that contains a fault element instead of a regular params element.
  187.  * 
  188.  * @category   XML
  189.  * @package    XML_RPC2
  190.  * @author     Sergio Carvalho <sergio.carvalho@portugalmail.com>  
  191.  * @copyright  2004-2006 Sergio Carvalho
  192.  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  193.  * @link       http://pear.php.net/package/XML_RPC2
  194.  */
  195. class XML_RPC2_FaultException extends XML_RPC2_Exception
  196. {
  197.     
  198.     // {{{ properties
  199.     
  200.     /**
  201.     * Fault code (in the response body)
  202.     *
  203.     * @var string
  204.     */
  205.     protected $faultCode = null;
  206.     
  207.     // }}}
  208.     // {{{ constructor
  209.     
  210.     /** Construct a new XML_RPC2_FaultException with a given message string and fault code
  211.      * 
  212.      * @param string        The message string, corresponding to the faultString present in the response body
  213.      * @param string        The fault code, corresponding to the faultCode in the response body
  214.      */
  215.     function __construct($messageString, $faultCode) 
  216.     {
  217.         parent::__construct($messageString);
  218.         $this->faultCode = $faultCode;
  219.     }
  220.     
  221.     // }}}
  222.     // {{{ getFaultCode()
  223.  
  224.     /** 
  225.      * FaultCode getter 
  226.      *
  227.      * @return string fault code
  228.      */
  229.     public function getFaultCode()
  230.     {
  231.         return $this->faultCode;
  232.     }
  233.     
  234.     // }}}
  235.     // {{{ getFaultString()
  236.  
  237.     /** 
  238.      * FaultString getter 
  239.      *
  240.      * This is an alias to getMessage() in order to respect XML-RPC nomenclature for faults
  241.      *
  242.      * @return string fault code
  243.      */
  244.     public function getFaultString()
  245.     {
  246.         return $this->getMessage();
  247.     }
  248.     
  249.     // }}}
  250.     // {{{ createFromDecode()
  251.     
  252.     /**
  253.     * Create a XML_RPC2_FaultException by decoding the corresponding xml string
  254.     *
  255.     * @param string $xml
  256.     * @return object a XML_RPC2_FaultException
  257.     */
  258.     public static function createFromDecode($xml) {
  259.         require_once 'XML/RPC2/Backend/Php/Value.php';
  260.  
  261.         // This is the only way I know of creating a new Document rooted in the provided simpleXMLFragment (needed for the xpath expressions that does not segfault sometimes
  262.         $xml = simplexml_load_string($xml->asXML());
  263.         $struct = XML_RPC2_Backend_Php_Value::createFromDecode($xml->value)->getNativeValue();
  264.         if (!(is_array($struct) &&
  265.               array_key_exists('faultString', $struct) &&
  266.               array_key_exists('faultCode', $struct))) throw new XML_RPC2_DecodeException('Unable to decode XML-RPC fault payload');
  267.  
  268.         return new XML_RPC2_FaultException( $struct['faultString'], $struct['faultCode'] );
  269.     }
  270.     
  271.     // }}}
  272.     
  273. }
  274.  
  275. /**
  276.  * XML_RPC2_UnknownMethodException is thrown when a non-existent method is remote-called
  277.  * 
  278.  * @category   XML
  279.  * @package    XML_RPC2
  280.  * @author     Sergio Carvalho <sergio.carvalho@portugalmail.com>  
  281.  * @copyright  2004-2006 Sergio Carvalho
  282.  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  283.  * @link       http://pear.php.net/package/XML_RPC2
  284.  */
  285. class XML_RPC2_UnknownMethodException extends XML_RPC2_Exception
  286. {
  287. }
  288.  
  289. /**
  290.  * XML_RPC2_TransportException signal transport level exceptions that stop requests from reaching the server
  291.  * 
  292.  * @category   XML
  293.  * @package    XML_RPC2
  294.  * @author     Sergio Carvalho <sergio.carvalho@portugalmail.com>  
  295.  * @copyright  2004-2006 Sergio Carvalho
  296.  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  297.  * @link       http://pear.php.net/package/XML_RPC2
  298.  */
  299. class XML_RPC2_TransportException extends XML_RPC2_Exception
  300. {
  301. }
  302.  
  303. /**
  304.  * XML_RPC2_ReceivedInvalidStatusCodeExceptionextends is thrown whenever the XML_RPC2 response to a request does not return a 200 http status code.
  305.  * 
  306.  * @category   XML
  307.  * @package    XML_RPC2
  308.  * @author     Sergio Carvalho <sergio.carvalho@portugalmail.com>  
  309.  * @copyright  2004-2006 Sergio Carvalho
  310.  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  311.  * @link       http://pear.php.net/package/XML_RPC2
  312.  */
  313. class XML_RPC2_ReceivedInvalidStatusCodeException extends XML_RPC2_TransportException
  314. {
  315. }
  316.  
  317. /**
  318.  * XML_RPC2_CurlError is thrown whenever an error is reported by the low level HTTP cURL library
  319.  * 
  320.  * @category   XML
  321.  * @package    XML_RPC2
  322.  * @author     Sergio Carvalho <sergio.carvalho@portugalmail.com>  
  323.  * @copyright  2004-2006 Sergio Carvalho
  324.  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  325.  * @link       http://pear.php.net/package/XML_RPC2
  326.  */
  327. class XML_RPC2_CurlException extends XML_RPC2_TransportException
  328. {
  329. }
  330.  
  331. ?>
  332.