2 +--------------------------------------------------------------------+
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2014, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
13 #include "php_http_api.h"
15 #include "ext/spl/spl_exceptions.h"
17 #ifndef PHP_HTTP_DBG_EXCEPTIONS
18 # define PHP_HTTP_DBG_EXCEPTIONS 0
21 #if PHP_HTTP_DBG_EXCEPTIONS
22 static void php_http_exception_hook(zval
*ex
)
25 zval
*m
= zend_read_property(Z_OBJCE_P(ex
), ex
, "message", lenof("message"), 0);
26 fprintf(stderr
, "*** Threw exception '%s'\n", Z_STRVAL_P(m
));
28 fprintf(stderr
, "*** Threw NULL exception\n");
33 static zend_class_entry
*php_http_exception_interface_class_entry
;
34 zend_class_entry
*php_http_get_exception_interface_class_entry(void)
36 return php_http_exception_interface_class_entry
;
38 static zend_class_entry
*php_http_exception_runtime_class_entry
;
39 zend_class_entry
*php_http_get_exception_runtime_class_entry(void)
41 return php_http_exception_runtime_class_entry
;
43 static zend_class_entry
*php_http_exception_unexpected_val_class_entry
;
44 zend_class_entry
*php_http_get_exception_unexpected_val_class_entry(void)
46 return php_http_exception_unexpected_val_class_entry
;
48 static zend_class_entry
*php_http_exception_bad_method_call_class_entry
;
49 zend_class_entry
*php_http_get_exception_bad_method_call_class_entry(void)
51 return php_http_exception_bad_method_call_class_entry
;
53 static zend_class_entry
*php_http_exception_invalid_arg_class_entry
;
54 zend_class_entry
*php_http_get_exception_invalid_arg_class_entry(void)
56 return php_http_exception_invalid_arg_class_entry
;
58 static zend_class_entry
*php_http_exception_bad_header_class_entry
;
59 zend_class_entry
*php_http_get_exception_bad_header_class_entry(void)
61 return php_http_exception_bad_header_class_entry
;
63 static zend_class_entry
*php_http_exception_bad_url_class_entry
;
64 zend_class_entry
*php_http_get_exception_bad_url_class_entry(void)
66 return php_http_exception_bad_url_class_entry
;
68 static zend_class_entry
*php_http_exception_bad_message_class_entry
;
69 zend_class_entry
*php_http_get_exception_bad_message_class_entry(void)
71 return php_http_exception_bad_message_class_entry
;
73 static zend_class_entry
*php_http_exception_bad_conversion_class_entry
;
74 zend_class_entry
*php_http_get_exception_bad_conversion_class_entry(void)
76 return php_http_exception_bad_conversion_class_entry
;
78 static zend_class_entry
*php_http_exception_bad_querystring_class_entry
;
79 zend_class_entry
*php_http_get_exception_bad_querystring_class_entry(void)
81 return php_http_exception_bad_querystring_class_entry
;
84 PHP_MINIT_FUNCTION(http_exception
)
86 zend_class_entry
*cep
, ce
= {0};
88 INIT_NS_CLASS_ENTRY(ce
, "http", "Exception", NULL
);
89 php_http_exception_interface_class_entry
= zend_register_internal_interface(&ce
);
92 * Would be great to only have a few exceptions and rather more identifying
93 * error codes, but zend_replace_error_handling() does not accept any codes.
96 memset(&ce
, 0, sizeof(ce
));
97 INIT_NS_CLASS_ENTRY(ce
, "http\\Exception", "RuntimeException", NULL
);
98 cep
= zend_register_internal_class_ex(&ce
, spl_ce_RuntimeException
);
99 zend_class_implements(cep
, 1, php_http_exception_interface_class_entry
);
100 php_http_exception_runtime_class_entry
= cep
;
102 memset(&ce
, 0, sizeof(ce
));
103 INIT_NS_CLASS_ENTRY(ce
, "http\\Exception", "UnexpectedValueException", NULL
);
104 cep
= zend_register_internal_class_ex(&ce
, spl_ce_UnexpectedValueException
);
105 zend_class_implements(cep
, 1, php_http_exception_interface_class_entry
);
106 php_http_exception_unexpected_val_class_entry
= cep
;
108 memset(&ce
, 0, sizeof(ce
));
109 INIT_NS_CLASS_ENTRY(ce
, "http\\Exception", "BadMethodCallException", NULL
);
110 cep
= zend_register_internal_class_ex(&ce
, spl_ce_BadMethodCallException
);
111 zend_class_implements(cep
, 1, php_http_exception_interface_class_entry
);
112 php_http_exception_bad_method_call_class_entry
= cep
;
114 memset(&ce
, 0, sizeof(ce
));
115 INIT_NS_CLASS_ENTRY(ce
, "http\\Exception", "InvalidArgumentException", NULL
);
116 cep
= zend_register_internal_class_ex(&ce
, spl_ce_InvalidArgumentException
);
117 zend_class_implements(cep
, 1, php_http_exception_interface_class_entry
);
118 php_http_exception_invalid_arg_class_entry
= cep
;
120 memset(&ce
, 0, sizeof(ce
));
121 INIT_NS_CLASS_ENTRY(ce
, "http\\Exception", "BadHeaderException", NULL
);
122 cep
= zend_register_internal_class_ex(&ce
, spl_ce_DomainException
);
123 zend_class_implements(cep
, 1, php_http_exception_interface_class_entry
);
124 php_http_exception_bad_header_class_entry
= cep
;
126 memset(&ce
, 0, sizeof(ce
));
127 INIT_NS_CLASS_ENTRY(ce
, "http\\Exception", "BadUrlException", NULL
);
128 cep
= zend_register_internal_class_ex(&ce
, spl_ce_DomainException
);
129 zend_class_implements(cep
, 1, php_http_exception_interface_class_entry
);
130 php_http_exception_bad_url_class_entry
= cep
;
132 memset(&ce
, 0, sizeof(ce
));
133 INIT_NS_CLASS_ENTRY(ce
, "http\\Exception", "BadMessageException", NULL
);
134 cep
= zend_register_internal_class_ex(&ce
, spl_ce_DomainException
);
135 zend_class_implements(cep
, 1, php_http_exception_interface_class_entry
);
136 php_http_exception_bad_message_class_entry
= cep
;
138 memset(&ce
, 0, sizeof(ce
));
139 INIT_NS_CLASS_ENTRY(ce
, "http\\Exception", "BadConversionException", NULL
);
140 cep
= zend_register_internal_class_ex(&ce
, spl_ce_DomainException
);
141 zend_class_implements(cep
, 1, php_http_exception_interface_class_entry
);
142 php_http_exception_bad_conversion_class_entry
= cep
;
144 memset(&ce
, 0, sizeof(ce
));
145 INIT_NS_CLASS_ENTRY(ce
, "http\\Exception", "BadQueryStringException", NULL
);
146 cep
= zend_register_internal_class_ex(&ce
, spl_ce_DomainException
);
147 zend_class_implements(cep
, 1, php_http_exception_interface_class_entry
);
148 php_http_exception_bad_querystring_class_entry
= cep
;
150 #if PHP_HTTP_DBG_EXCEPTIONS
151 zend_throw_exception_hook
= php_http_exception_hook
;
162 * vim600: noet sw=4 ts=4 fdm=marker
163 * vim<600: noet sw=4 ts=4