domexception.c 3.6 KB

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