release 2.4.0
[m6w6/ext-http] / php_http_exception.c
index 8b5800e2d4a08862a6599ee541407fa4f2115b0b..25a33e6f9c93e80d7126c3dc0ca6b6f1337fa677 100644 (file)
@@ -6,26 +6,18 @@
     | modification, are permitted provided that the conditions mentioned |
     | in the accompanying LICENSE file are met.                          |
     +--------------------------------------------------------------------+
-    | Copyright (c) 2004-2010, Michael Wallner <mike@php.net>            |
+    | Copyright (c) 2004-2014, Michael Wallner <mike@php.net>            |
     +--------------------------------------------------------------------+
 */
 
-/* $Id: http_exception_object.c 292841 2009-12-31 08:48:57Z mike $ */
+#include "php_http_api.h"
 
-#include "php_http.h"
-
-#include <Zend/zend_exceptions.h>
+#include <ext/spl/spl_exceptions.h>
 
 #ifndef PHP_HTTP_DBG_EXCEPTIONS
 #      define PHP_HTTP_DBG_EXCEPTIONS 0
 #endif
 
-zend_class_entry *php_http_exception_class_entry;
-
-zend_function_entry php_http_exception_method_entry[] = {
-       EMPTY_FUNCTION_ENTRY
-};
-
 #if PHP_HTTP_DBG_EXCEPTIONS
 static void php_http_exception_hook(zval *ex TSRMLS_DC)
 {
@@ -38,30 +30,83 @@ static void php_http_exception_hook(zval *ex TSRMLS_DC)
 }
 #endif
 
+zend_class_entry *php_http_exception_interface_class_entry;
+zend_class_entry *php_http_exception_runtime_class_entry;
+zend_class_entry *php_http_exception_unexpected_val_class_entry;
+zend_class_entry *php_http_exception_bad_method_call_class_entry;
+zend_class_entry *php_http_exception_invalid_arg_class_entry;
+zend_class_entry *php_http_exception_bad_header_class_entry;
+zend_class_entry *php_http_exception_bad_url_class_entry;
+zend_class_entry *php_http_exception_bad_message_class_entry;
+zend_class_entry *php_http_exception_bad_conversion_class_entry;
+zend_class_entry *php_http_exception_bad_querystring_class_entry;
+
 PHP_MINIT_FUNCTION(http_exception)
 {
-       PHP_HTTP_REGISTER_EXCEPTION(Exception, php_http_exception_class_entry, zend_exception_get_default(TSRMLS_C));
-       
-       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_UNKNOWN"), PHP_HTTP_E_UNKNOWN TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_RUNTIME"), PHP_HTTP_E_RUNTIME TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_INVALID_PARAM"), PHP_HTTP_E_INVALID_PARAM TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_HEADER"), PHP_HTTP_E_HEADER TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_MALFORMED_HEADERS"), PHP_HTTP_E_MALFORMED_HEADERS TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_MESSAGE"), PHP_HTTP_E_MESSAGE TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_MESSAGE_TYPE"), PHP_HTTP_E_MESSAGE_TYPE TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_MESSAGE_BODY"), PHP_HTTP_E_MESSAGE_BODY TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_ENCODING"), PHP_HTTP_E_ENCODING TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_REQUEST"), PHP_HTTP_E_REQUEST TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_REQUEST_POOL"), PHP_HTTP_E_REQUEST_POOL TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_REQUEST_DATASHARE"), PHP_HTTP_E_REQUEST_DATASHARE TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_REQUEST_FACTORY"), PHP_HTTP_E_REQUEST_FACTORY TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_REQUEST_METHOD"), PHP_HTTP_E_REQUEST_METHOD TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_SOCKET"), PHP_HTTP_E_SOCKET TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_RESPONSE"), PHP_HTTP_E_RESPONSE TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_URL"), PHP_HTTP_E_URL TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_QUERYSTRING"), PHP_HTTP_E_QUERYSTRING TSRMLS_CC);
-       zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_COOKIE"), PHP_HTTP_E_COOKIE TSRMLS_CC);
+       zend_class_entry *cep, ce = {0};
+
+       INIT_NS_CLASS_ENTRY(ce, "http", "Exception", NULL);
+       php_http_exception_interface_class_entry = zend_register_internal_interface(&ce TSRMLS_CC);
        
+       /*
+        * Would be great to only have a few exceptions and rather more identifying
+        * error codes, but zend_replace_error_handling() does not accept any codes.
+        */
+
+       memset(&ce, 0, sizeof(ce));
+       INIT_NS_CLASS_ENTRY(ce, "http\\Exception", "RuntimeException", NULL);
+       cep = zend_register_internal_class_ex(&ce, spl_ce_RuntimeException, NULL TSRMLS_CC);
+       zend_class_implements(cep TSRMLS_CC, 1, php_http_exception_interface_class_entry);
+       php_http_exception_runtime_class_entry = cep;
+
+       memset(&ce, 0, sizeof(ce));
+       INIT_NS_CLASS_ENTRY(ce, "http\\Exception", "UnexpectedValueException", NULL);
+       cep = zend_register_internal_class_ex(&ce, spl_ce_UnexpectedValueException, NULL TSRMLS_CC);
+       zend_class_implements(cep TSRMLS_CC, 1, php_http_exception_interface_class_entry);
+       php_http_exception_unexpected_val_class_entry = cep;
+
+       memset(&ce, 0, sizeof(ce));
+       INIT_NS_CLASS_ENTRY(ce, "http\\Exception", "BadMethodCallException", NULL);
+       cep = zend_register_internal_class_ex(&ce, spl_ce_BadMethodCallException, NULL TSRMLS_CC);
+       zend_class_implements(cep TSRMLS_CC, 1, php_http_exception_interface_class_entry);
+       php_http_exception_bad_method_call_class_entry = cep;
+
+       memset(&ce, 0, sizeof(ce));
+       INIT_NS_CLASS_ENTRY(ce, "http\\Exception", "InvalidArgumentException", NULL);
+       cep = zend_register_internal_class_ex(&ce, spl_ce_InvalidArgumentException, NULL TSRMLS_CC);
+       zend_class_implements(cep TSRMLS_CC, 1, php_http_exception_interface_class_entry);
+       php_http_exception_invalid_arg_class_entry = cep;
+
+       memset(&ce, 0, sizeof(ce));
+       INIT_NS_CLASS_ENTRY(ce, "http\\Exception", "BadHeaderException", NULL);
+       cep = zend_register_internal_class_ex(&ce, spl_ce_DomainException, NULL TSRMLS_CC);
+       zend_class_implements(cep TSRMLS_CC, 1, php_http_exception_interface_class_entry);
+       php_http_exception_bad_header_class_entry = cep;
+
+       memset(&ce, 0, sizeof(ce));
+       INIT_NS_CLASS_ENTRY(ce, "http\\Exception", "BadUrlException", NULL);
+       cep = zend_register_internal_class_ex(&ce, spl_ce_DomainException, NULL TSRMLS_CC);
+       zend_class_implements(cep TSRMLS_CC, 1, php_http_exception_interface_class_entry);
+       php_http_exception_bad_url_class_entry = cep;
+
+       memset(&ce, 0, sizeof(ce));
+       INIT_NS_CLASS_ENTRY(ce, "http\\Exception", "BadMessageException", NULL);
+       cep = zend_register_internal_class_ex(&ce, spl_ce_DomainException, NULL TSRMLS_CC);
+       zend_class_implements(cep TSRMLS_CC, 1, php_http_exception_interface_class_entry);
+       php_http_exception_bad_message_class_entry = cep;
+
+       memset(&ce, 0, sizeof(ce));
+       INIT_NS_CLASS_ENTRY(ce, "http\\Exception", "BadConversionException", NULL);
+       cep = zend_register_internal_class_ex(&ce, spl_ce_DomainException, NULL TSRMLS_CC);
+       zend_class_implements(cep TSRMLS_CC, 1, php_http_exception_interface_class_entry);
+       php_http_exception_bad_conversion_class_entry = cep;
+
+       memset(&ce, 0, sizeof(ce));
+       INIT_NS_CLASS_ENTRY(ce, "http\\Exception", "BadQueryStringException", NULL);
+       cep = zend_register_internal_class_ex(&ce, spl_ce_DomainException, NULL TSRMLS_CC);
+       zend_class_implements(cep TSRMLS_CC, 1, php_http_exception_interface_class_entry);
+       php_http_exception_bad_querystring_class_entry = cep;
+
 #if PHP_HTTP_DBG_EXCEPTIONS
        zend_throw_exception_hook = php_http_exception_hook;
 #endif