domexception.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Copyright (c) The PHP Group |
  4. +----------------------------------------------------------------------+
  5. | This source file is subject to version 3.01 of the PHP license, |
  6. | that is bundled with this package in the file LICENSE, and is |
  7. | available through the world-wide-web at the following url: |
  8. | https://www.php.net/license/3_01.txt |
  9. | If you did not receive a copy of the PHP license and are unable to |
  10. | obtain it through the world-wide-web, please send a note to |
  11. | license@php.net so we can mail you a copy immediately. |
  12. +----------------------------------------------------------------------+
  13. | Authors: Christian Stocker <chregu@php.net> |
  14. | Rob Richards <rrichards@php.net> |
  15. +----------------------------------------------------------------------+
  16. */
  17. #ifdef HAVE_CONFIG_H
  18. #include "config.h"
  19. #endif
  20. #include "php.h"
  21. #if defined(HAVE_LIBXML) && defined(HAVE_DOM)
  22. #include "php_dom.h"
  23. /*
  24. * class DOMException
  25. *
  26. * URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-17189187
  27. * Since:
  28. */
  29. extern zend_class_entry *dom_domexception_class_entry;
  30. void php_dom_throw_error_with_message(int error_code, char *error_message, int strict_error) /* {{{ */
  31. {
  32. if (strict_error == 1) {
  33. zend_throw_exception(dom_domexception_class_entry, error_message, error_code);
  34. } else {
  35. php_libxml_issue_error(E_WARNING, error_message);
  36. }
  37. }
  38. /* }}} */
  39. /* {{{ php_dom_throw_error */
  40. void php_dom_throw_error(int error_code, int strict_error)
  41. {
  42. char *error_message;
  43. switch (error_code)
  44. {
  45. case INDEX_SIZE_ERR:
  46. error_message = "Index Size Error";
  47. break;
  48. case DOMSTRING_SIZE_ERR:
  49. error_message = "DOM String Size Error";
  50. break;
  51. case HIERARCHY_REQUEST_ERR:
  52. error_message = "Hierarchy Request Error";
  53. break;
  54. case WRONG_DOCUMENT_ERR:
  55. error_message = "Wrong Document Error";
  56. break;
  57. case INVALID_CHARACTER_ERR:
  58. error_message = "Invalid Character Error";
  59. break;
  60. case NO_DATA_ALLOWED_ERR:
  61. error_message = "No Data Allowed Error";
  62. break;
  63. case NO_MODIFICATION_ALLOWED_ERR:
  64. error_message = "No Modification Allowed Error";
  65. break;
  66. case NOT_FOUND_ERR:
  67. error_message = "Not Found Error";
  68. break;
  69. case NOT_SUPPORTED_ERR:
  70. error_message = "Not Supported Error";
  71. break;
  72. case INUSE_ATTRIBUTE_ERR:
  73. error_message = "Inuse Attribute Error";
  74. break;
  75. case INVALID_STATE_ERR:
  76. error_message = "Invalid State Error";
  77. break;
  78. case SYNTAX_ERR:
  79. error_message = "Syntax Error";
  80. break;
  81. case INVALID_MODIFICATION_ERR:
  82. error_message = "Invalid Modification Error";
  83. break;
  84. case NAMESPACE_ERR:
  85. error_message = "Namespace Error";
  86. break;
  87. case INVALID_ACCESS_ERR:
  88. error_message = "Invalid Access Error";
  89. break;
  90. case VALIDATION_ERR:
  91. error_message = "Validation Error";
  92. break;
  93. default:
  94. error_message = "Unhandled Error";
  95. }
  96. php_dom_throw_error_with_message(error_code, error_message, strict_error);
  97. }
  98. /* }}} end php_dom_throw_error */
  99. #endif /* HAVE_LIBXML && HAVE_DOM */