Fault.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4 |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license, |
  9. // | that is bundled with this package in the file LICENSE, and is |
  10. // | available at through the world-wide-web at |
  11. // | http://www.php.net/license/2_02.txt. |
  12. // | If you did not receive a copy of the PHP license and are unable to |
  13. // | obtain it through the world-wide-web, please send a note to |
  14. // | license@php.net so we can mail you a copy immediately. |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Shane Caraveo <Shane@Caraveo.com> Port to PEAR and more |
  17. // | Authors: Dietrich Ayala <dietrich@ganx4.com> Original Author |
  18. // +----------------------------------------------------------------------+
  19. //
  20. // $Id: Fault.php,v 1.13 2003/04/13 21:38:58 shane Exp $
  21. //
  22. require_once('PEAR.php');
  23. /**
  24. * SOAP_Fault
  25. * PEAR::Error wrapper used to match SOAP Faults to PEAR Errors
  26. *
  27. * @package SOAP
  28. * @access public
  29. * @author Shane Caraveo <Shane@Caraveo.com> Port to PEAR and more
  30. * @author Dietrich Ayala <dietrich@ganx4.com> Original Author
  31. * @version $Id: Fault.php,v 1.13 2003/04/13 21:38:58 shane Exp $
  32. */
  33. class SOAP_Fault extends PEAR_Error
  34. {
  35. /**
  36. * Constructor
  37. *
  38. * @param string message string for fault
  39. * @param mixed the faultcode
  40. * @param mixed see PEAR::ERROR
  41. * @param mixed see PEAR::ERROR
  42. * @param array the userinfo array is used to pass in the
  43. * SOAP actor and detail for the fault
  44. */
  45. function SOAP_Fault($faultstring = 'unknown error', $faultcode = 'Client', $faultactor=NULL, $detail=NULL, $mode = null, $options = null)
  46. {
  47. parent::PEAR_Error($faultstring, $faultcode, $mode, $options, $detail);
  48. if ($faultactor) $this->error_message_prefix = $faultactor;
  49. }
  50. /**
  51. * message
  52. *
  53. * returns a SOAP_Message class that can be sent as a server response
  54. *
  55. * @return SOAP_Message
  56. * @access public
  57. */
  58. function message()
  59. {
  60. $msg =& new SOAP_Base();
  61. $params = array();
  62. $params[] =& new SOAP_Value('faultcode', 'QName', 'SOAP-ENV:'.$this->code);
  63. $params[] =& new SOAP_Value('faultstring', 'string', $this->message);
  64. $params[] =& new SOAP_Value('faultactor', 'anyURI', $this->error_message_prefix);
  65. if (isset($this->backtrace)) {
  66. $params[] =& new SOAP_Value('detail', 'string', $this->backtrace);
  67. } else {
  68. $params[] =& new SOAP_Value('detail', 'string', $this->userinfo);
  69. }
  70. $methodValue =& new SOAP_Value('{'.SOAP_ENVELOP.'}Fault', 'Struct', $params);
  71. $headers = NULL;
  72. return $msg->_makeEnvelope($methodValue, $headers);
  73. }
  74. /**
  75. * getFault
  76. *
  77. * returns a simple native php array containing the fault data
  78. *
  79. * @return array
  80. * @access public
  81. */
  82. function getFault()
  83. {
  84. global $SOAP_OBJECT_STRUCT;
  85. if ($SOAP_OBJECT_STRUCT) {
  86. $fault =& new stdClass();
  87. $fault->faultcode = $this->code;
  88. $fault->faultstring = $this->message;
  89. $fault->faultactor = $this->error_message_prefix;
  90. $fault->detail = $this->userinfo;
  91. return $fault;
  92. }
  93. return array(
  94. 'faultcode' => $this->code,
  95. 'faultstring' => $this->message,
  96. 'faultactor' => $this->error_message_prefix,
  97. 'detail' => $this->userinfo
  98. );
  99. }
  100. /**
  101. * getActor
  102. *
  103. * returns the SOAP actor for the fault
  104. *
  105. * @return string
  106. * @access public
  107. */
  108. function getActor()
  109. {
  110. return $this->error_message_prefix;
  111. }
  112. /**
  113. * getDetail
  114. *
  115. * returns the fault detail
  116. *
  117. * @return string
  118. * @access public
  119. */
  120. function getDetail()
  121. {
  122. return $this->userinfo;
  123. }
  124. }
  125. ?>