Warning, file /webapps/ocs-webserver/library/Zend/XmlRpc/Server/Fault.php was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_XmlRpc
0017  * @subpackage Server
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 /**
0024  * Zend_XmlRpc_Fault
0025  */
0026 // require_once 'Zend/XmlRpc/Fault.php';
0027 
0028 
0029 /**
0030  * XMLRPC Server Faults
0031  *
0032  * Encapsulates an exception for use as an XMLRPC fault response. Valid
0033  * exception classes that may be used for generating the fault code and fault
0034  * string can be attached using {@link attachFaultException()}; all others use a
0035  * generic '404 Unknown error' response.
0036  *
0037  * You may also attach fault observers, which would allow you to monitor
0038  * particular fault cases; this is done via {@link attachObserver()}. Observers
0039  * need only implement a static 'observe' method.
0040  *
0041  * To allow method chaining, you may use the {@link getInstance()} factory
0042  * to instantiate a Zend_XmlRpc_Server_Fault.
0043  *
0044  * @category   Zend
0045  * @package    Zend_XmlRpc
0046  * @subpackage Server
0047  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0048  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0049  */
0050 class Zend_XmlRpc_Server_Fault extends Zend_XmlRpc_Fault
0051 {
0052     /**
0053      * @var Exception
0054      */
0055     protected $_exception;
0056 
0057     /**
0058      * @var array Array of exception classes that may define xmlrpc faults
0059      */
0060     protected static $_faultExceptionClasses = array('Zend_XmlRpc_Server_Exception' => true);
0061 
0062     /**
0063      * @var array Array of fault observers
0064      */
0065     protected static $_observers = array();
0066 
0067     /**
0068      * Constructor
0069      *
0070      * @param Exception $e
0071      * @return Zend_XmlRpc_Server_Fault
0072      */
0073     public function __construct(Exception $e)
0074     {
0075         $this->_exception = $e;
0076         $code             = 404;
0077         $message          = 'Unknown error';
0078         $exceptionClass   = get_class($e);
0079 
0080         foreach (array_keys(self::$_faultExceptionClasses) as $class) {
0081             if ($e instanceof $class) {
0082                 $code    = $e->getCode();
0083                 $message = $e->getMessage();
0084                 break;
0085             }
0086         }
0087 
0088         parent::__construct($code, $message);
0089 
0090         // Notify exception observers, if present
0091         if (!empty(self::$_observers)) {
0092             foreach (array_keys(self::$_observers) as $observer) {
0093                 call_user_func(array($observer, 'observe'), $this);
0094             }
0095         }
0096     }
0097 
0098     /**
0099      * Return Zend_XmlRpc_Server_Fault instance
0100      *
0101      * @param Exception $e
0102      * @return Zend_XmlRpc_Server_Fault
0103      */
0104     public static function getInstance(Exception $e)
0105     {
0106         return new self($e);
0107     }
0108 
0109     /**
0110      * Attach valid exceptions that can be used to define xmlrpc faults
0111      *
0112      * @param string|array $classes Class name or array of class names
0113      * @return void
0114      */
0115     public static function attachFaultException($classes)
0116     {
0117         if (!is_array($classes)) {
0118             $classes = (array) $classes;
0119         }
0120 
0121         foreach ($classes as $class) {
0122             if (is_string($class) && class_exists($class)) {
0123                 self::$_faultExceptionClasses[$class] = true;
0124             }
0125         }
0126     }
0127 
0128     /**
0129      * Detach fault exception classes
0130      *
0131      * @param string|array $classes Class name or array of class names
0132      * @return void
0133      */
0134     public static function detachFaultException($classes)
0135     {
0136         if (!is_array($classes)) {
0137             $classes = (array) $classes;
0138         }
0139 
0140         foreach ($classes as $class) {
0141             if (is_string($class) && isset(self::$_faultExceptionClasses[$class])) {
0142                 unset(self::$_faultExceptionClasses[$class]);
0143             }
0144         }
0145     }
0146 
0147     /**
0148      * Attach an observer class
0149      *
0150      * Allows observation of xmlrpc server faults, thus allowing logging or mail
0151      * notification of fault responses on the xmlrpc server.
0152      *
0153      * Expects a valid class name; that class must have a public static method
0154      * 'observe' that accepts an exception as its sole argument.
0155      *
0156      * @param string $class
0157      * @return boolean
0158      */
0159     public static function attachObserver($class)
0160     {
0161         if (!is_string($class)
0162             || !class_exists($class)
0163             || !is_callable(array($class, 'observe')))
0164         {
0165             return false;
0166         }
0167 
0168         if (!isset(self::$_observers[$class])) {
0169             self::$_observers[$class] = true;
0170         }
0171 
0172         return true;
0173     }
0174 
0175     /**
0176      * Detach an observer
0177      *
0178      * @param string $class
0179      * @return boolean
0180      */
0181     public static function detachObserver($class)
0182     {
0183         if (!isset(self::$_observers[$class])) {
0184             return false;
0185         }
0186 
0187         unset(self::$_observers[$class]);
0188         return true;
0189     }
0190 
0191     /**
0192      * Retrieve the exception
0193      *
0194      * @access public
0195      * @return Exception
0196      */
0197     public function getException()
0198     {
0199         return $this->_exception;
0200     }
0201 }