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 TSRMLS_DC
)
25 zval
*m
= zend_read_property(Z_OBJCE_P(ex
), ex
, "message", lenof("message"), 0 TSRMLS_CC
);
26 fprintf(stderr
, "*** Threw exception '%s'\n", Z_STRVAL_P(m
));
28 fprintf(stderr
, "*** Threw NULL exception\n");
33 zend_class_entry
*php_http_exception_interface_class_entry
;
34 zend_class_entry
*php_http_exception_runtime_class_entry
;
35 zend_class_entry
*php_http_exception_unexpected_val_class_entry
;
36 zend_class_entry
*php_http_exception_bad_method_call_class_entry
;
37 zend_class_entry
*php_http_exception_invalid_arg_class_entry
;
38 zend_class_entry
*php_http_exception_bad_header_class_entry
;
39 zend_class_entry
*php_http_exception_bad_url_class_entry
;
40 zend_class_entry
*php_http_exception_bad_message_class_entry
;
41 zend_class_entry
*php_http_exception_bad_conversion_class_entry
;
42 zend_class_entry
*php_http_exception_bad_querystring_class_entry
;
44 PHP_MINIT_FUNCTION(http_exception
)
46 zend_class_entry
*cep
, ce
= {0};
48 INIT_NS_CLASS_ENTRY(ce
, "http", "Exception", NULL
);
49 php_http_exception_interface_class_entry
= zend_register_internal_interface(&ce TSRMLS_CC
);
52 * Would be great to only have a few exceptions and rather more identifying
53 * error codes, but zend_replace_error_handling() does not accept any codes.
56 memset(&ce
, 0, sizeof(ce
));
57 INIT_NS_CLASS_ENTRY(ce
, "http\\Exception", "RuntimeException", NULL
);
58 cep
= zend_register_internal_class_ex(&ce
, spl_ce_RuntimeException
, NULL TSRMLS_CC
);
59 zend_class_implements(cep TSRMLS_CC
, 1, php_http_exception_interface_class_entry
);
60 php_http_exception_runtime_class_entry
= cep
;
62 memset(&ce
, 0, sizeof(ce
));
63 INIT_NS_CLASS_ENTRY(ce
, "http\\Exception", "UnexpectedValueException", NULL
);
64 cep
= zend_register_internal_class_ex(&ce
, spl_ce_UnexpectedValueException
, NULL TSRMLS_CC
);
65 zend_class_implements(cep TSRMLS_CC
, 1, php_http_exception_interface_class_entry
);
66 php_http_exception_unexpected_val_class_entry
= cep
;
68 memset(&ce
, 0, sizeof(ce
));
69 INIT_NS_CLASS_ENTRY(ce
, "http\\Exception", "BadMethodCallException", NULL
);
70 cep
= zend_register_internal_class_ex(&ce
, spl_ce_BadMethodCallException
, NULL TSRMLS_CC
);
71 zend_class_implements(cep TSRMLS_CC
, 1, php_http_exception_interface_class_entry
);
72 php_http_exception_bad_method_call_class_entry
= cep
;
74 memset(&ce
, 0, sizeof(ce
));
75 INIT_NS_CLASS_ENTRY(ce
, "http\\Exception", "InvalidArgumentException", NULL
);
76 cep
= zend_register_internal_class_ex(&ce
, spl_ce_InvalidArgumentException
, NULL TSRMLS_CC
);
77 zend_class_implements(cep TSRMLS_CC
, 1, php_http_exception_interface_class_entry
);
78 php_http_exception_invalid_arg_class_entry
= cep
;
80 memset(&ce
, 0, sizeof(ce
));
81 INIT_NS_CLASS_ENTRY(ce
, "http\\Exception", "BadHeaderException", NULL
);
82 cep
= zend_register_internal_class_ex(&ce
, spl_ce_DomainException
, NULL TSRMLS_CC
);
83 zend_class_implements(cep TSRMLS_CC
, 1, php_http_exception_interface_class_entry
);
84 php_http_exception_bad_header_class_entry
= cep
;
86 memset(&ce
, 0, sizeof(ce
));
87 INIT_NS_CLASS_ENTRY(ce
, "http\\Exception", "BadUrlException", NULL
);
88 cep
= zend_register_internal_class_ex(&ce
, spl_ce_DomainException
, NULL TSRMLS_CC
);
89 zend_class_implements(cep TSRMLS_CC
, 1, php_http_exception_interface_class_entry
);
90 php_http_exception_bad_url_class_entry
= cep
;
92 memset(&ce
, 0, sizeof(ce
));
93 INIT_NS_CLASS_ENTRY(ce
, "http\\Exception", "BadMessageException", NULL
);
94 cep
= zend_register_internal_class_ex(&ce
, spl_ce_DomainException
, NULL TSRMLS_CC
);
95 zend_class_implements(cep TSRMLS_CC
, 1, php_http_exception_interface_class_entry
);
96 php_http_exception_bad_message_class_entry
= cep
;
98 memset(&ce
, 0, sizeof(ce
));
99 INIT_NS_CLASS_ENTRY(ce
, "http\\Exception", "BadConversionException", NULL
);
100 cep
= zend_register_internal_class_ex(&ce
, spl_ce_DomainException
, NULL TSRMLS_CC
);
101 zend_class_implements(cep TSRMLS_CC
, 1, php_http_exception_interface_class_entry
);
102 php_http_exception_bad_conversion_class_entry
= cep
;
104 memset(&ce
, 0, sizeof(ce
));
105 INIT_NS_CLASS_ENTRY(ce
, "http\\Exception", "BadQueryStringException", NULL
);
106 cep
= zend_register_internal_class_ex(&ce
, spl_ce_DomainException
, NULL TSRMLS_CC
);
107 zend_class_implements(cep TSRMLS_CC
, 1, php_http_exception_interface_class_entry
);
108 php_http_exception_bad_querystring_class_entry
= cep
;
110 #if PHP_HTTP_DBG_EXCEPTIONS
111 zend_throw_exception_hook
= php_http_exception_hook
;
122 * vim600: noet sw=4 ts=4 fdm=marker
123 * vim<600: noet sw=4 ts=4