+require_once 'Zend/Soap/Server.php';
+
+/**
+ * The Zend XMLRPC server but with a fault that returns debuginfo
+ */
+class moodle_zend_soap_server extends Zend_Soap_Server {
+
+ /**
+ * Generate a server fault
+ *
+ * Note that the arguments are reverse to those of SoapFault.
+ *
+ * Moodle note: the difference with the Zend server is that we throw a SoapFault exception
+ * with the debuginfo integrated to the exception message when DEBUG >= NORMAL
+ *
+ * If an exception is passed as the first argument, its message and code
+ * will be used to create the fault object if it has been registered via
+ * {@Link registerFaultException()}.
+ *
+ * @link http://www.w3.org/TR/soap12-part1/#faultcodes
+ * @param string|Exception $fault
+ * @param string $code SOAP Fault Codes
+ * @return SoapFault
+ */
+ public function fault($fault = null, $code = "Receiver")
+ {
+ //intercept any exceptions with debug info and transform it in Moodle exception
+ if ($fault instanceof Exception) {
+ //add the debuginfo to the exception message if debuginfo must be returned
+ if (debugging() and isset($fault->debuginfo)) {
+ $fault = new SoapFault('Receiver', $fault->getMessage() . ' | DEBUG INFO: ' . $fault->debuginfo);
+ }
+ }
+
+ return parent::fault($fault, $code);
+ }
+}