MessageException.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * The Exception class is the internal static class used to output user defined
  4. * exceptions to the output stream.
  5. *
  6. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  7. * @copyright (c) 2003 amfphp.org
  8. * @package flashservices
  9. * @subpackage exception
  10. * @author Justin Watkins Original Design
  11. * @version $Id: AMFException.php,v 1.2 2005/04/02 18:37:23 pmineault Exp $
  12. */
  13. /**
  14. * Linked classes
  15. */
  16. require_once(AMFPHP_BASE . "shared/app/Constants.php");
  17. /**
  18. * Remove the html formatting of the error messages so they can be easily formatted
  19. * inside flash.
  20. */
  21. @ini_set("html_errors", 0);
  22. class MessageException {
  23. /**
  24. * Constructor for the Exception class. This is how you build a new
  25. * error instance.
  26. *
  27. * @param string $code The code string to return to the flash client :: THIS SHOULD PROBABLY BE SET AUTOMATICALLY ::
  28. * @param string $description A short reason why the error occured
  29. * @param string $file The file name that the error occured
  30. * @param int $line The line number where the error was detected
  31. */
  32. function MessageException ($code, $description, $file, $line, $detailCode = 'AMFPHP_RUNTIME_ERROR') {
  33. $this->code = $detailCode;
  34. $this->description = $description; // pass the description
  35. $this->details = $file; // pass the details
  36. $this->level = MessageException::getFriendlyError($code);
  37. $this->line = $line; // pass the line number
  38. }
  39. /**
  40. * throwException provides the means to raise an exception. This method will
  41. * stop the further execution of the remote method, but not hault the execution
  42. * of the entire process. Using the built in PHP exception system will stop
  43. * the entire process and not allow us to report very detailed information back
  44. * to the client, especially if there are multiple methods.
  45. *
  46. * When we upgrade to PHP 5, using the try...catch syntax will make this much easier.
  47. *
  48. * @static
  49. * @param AMFBody $body The AMFBody object to apply the exception to.
  50. * @param AMFException @exception The exception object to throw
  51. * @see AMFBody
  52. */
  53. function throwException (&$body, $exception) {
  54. $body->responseURI = $body->responseIndex . "/onStatus";
  55. $results = &$body->getResults();
  56. if($GLOBALS['amfphp']['encoding'] == 'amf3')
  57. {
  58. $results = new ErrorMessage();
  59. $results->correlationId = $GLOBALS['amfphp']['lastMessageId'];
  60. $results->faultCode = $exception->code;
  61. $results->faultDetail = $exception->details . ' on line ' . $exception->line;
  62. $results->faultString = $exception->description;
  63. }
  64. elseif($GLOBALS['amfphp']['encoding'] == 'amf0')
  65. {
  66. $results["description"] = $exception->description;
  67. $results["details"] = $exception->details;
  68. $results["level"] = $exception->level;
  69. $results["line"] = $exception->line;
  70. $results["code"] = $exception->code;
  71. }
  72. else
  73. {
  74. $results['faultCode'] = $exception->code;
  75. $results['faultDetail'] = $exception->details . ' on line ' . $exception->line;
  76. $results['faultString'] = $exception->description;
  77. }
  78. }
  79. function getFriendlyError ($err) {
  80. $errortype = array (1 => "Error",
  81. 2 => "Warning",
  82. 4 => "Parsing Error",
  83. 8 => "Notice",
  84. 16 => "Core Error",
  85. 32 => "Core Warning",
  86. 64 => "Compile Error",
  87. 128 => "Compile Warning",
  88. 256 => "User Error",
  89. 512 => "User Warning",
  90. 1024 => "User Notice",
  91. 2048 => "Strict error",
  92. );
  93. if(isset($errortype[$err]))
  94. {
  95. return $errortype[$err];
  96. }
  97. else
  98. {
  99. return "Unknown error type";
  100. }
  101. }
  102. }
  103. ?>