forked from brett19/php-couchbase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exception.c
48 lines (38 loc) · 1.44 KB
/
exception.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "couchbase.h"
#include <libcouchbase/couchbase.h>
zend_class_entry *default_exception_ce;
zend_class_entry *cb_exception_ce;
zval * create_exception(zend_class_entry *exception_ce, const char *message, long code TSRMLS_DC) {
zend_class_entry *default_exception_ce = zend_exception_get_default(TSRMLS_C);
zval *ex;
MAKE_STD_ZVAL(ex);
object_init_ex(ex, exception_ce);
if (message) {
zend_update_property_string(default_exception_ce, ex, "message", sizeof("message")-1, message TSRMLS_CC);
}
if (code) {
zend_update_property_long(default_exception_ce, ex, "code", sizeof("code")-1, code TSRMLS_CC);
}
return ex;
}
zval * create_pcbc_exception(const char *message, long code TSRMLS_DC) {
return create_exception(cb_exception_ce, message, code TSRMLS_CC);
}
zval * create_lcb_exception(long code TSRMLS_DC) {
const char *str = lcb_strerror(NULL, (lcb_error_t)code);
return create_exception(cb_exception_ce, str, code TSRMLS_CC);
}
#define setup(var, name, parent) \
do { \
zend_class_entry cbe; \
INIT_CLASS_ENTRY(cbe, name, NULL); \
var = zend_register_internal_class_ex(&cbe, parent, NULL TSRMLS_CC); \
} while(0)
void couchbase_init_exceptions(INIT_FUNC_ARGS) {
#if ZEND_MODULE_API_NO >= 20060613
default_exception_ce = (zend_class_entry *)zend_exception_get_default(TSRMLS_C);
#else
default_exception_ce = (zend_class_entry *)zend_exception_get_default();
#endif
setup(cb_exception_ce, "CouchbaseException", default_exception_ce);
}