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) 2013, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
19 #include <Zend/zend_exceptions.h>
20 #include <ext/spl/spl_exceptions.h>
23 #include "php_pq_object.h"
24 #include "php_pqexc.h"
26 static zend_class_entry
*php_pqexc_interface_class_entry
;
27 static zend_class_entry
*php_pqexc_invalid_argument_class_entry
;
28 static zend_class_entry
*php_pqexc_runtime_class_entry
;
29 static zend_class_entry
*php_pqexc_bad_methodcall_class_entry
;
30 static zend_class_entry
*php_pqexc_domain_class_entry
;
32 static zend_function_entry php_pqexc_methods
[] = {
36 zend_class_entry
*exce(php_pqexc_type_t type
)
40 case EX_INVALID_ARGUMENT
:
41 return php_pqexc_invalid_argument_class_entry
;
43 case EX_CONNECTION_FAILED
:
46 return php_pqexc_runtime_class_entry
;
47 case EX_UNINITIALIZED
:
48 case EX_BAD_METHODCALL
:
49 return php_pqexc_bad_methodcall_class_entry
;
52 return php_pqexc_domain_class_entry
;
56 zend_object
*throw_exce(php_pqexc_type_t type
, const char *fmt
, ...)
63 vspprintf(&msg
, 0, fmt
, argv
);
66 zexc
= zend_throw_exception(exce(type
), msg
, type
);
72 PHP_MINIT_FUNCTION(pqexc
)
74 zend_class_entry ce
= {0};
76 INIT_NS_CLASS_ENTRY(ce
, "pq", "Exception", php_pqexc_methods
);
77 php_pqexc_interface_class_entry
= zend_register_internal_interface(&ce
);
78 zend_class_implements(php_pqexc_interface_class_entry
, 1, zend_ce_throwable
);
80 zend_declare_class_constant_long(php_pqexc_interface_class_entry
, ZEND_STRL("INVALID_ARGUMENT"), EX_INVALID_ARGUMENT
);
81 zend_declare_class_constant_long(php_pqexc_interface_class_entry
, ZEND_STRL("RUNTIME"), EX_RUNTIME
);
82 zend_declare_class_constant_long(php_pqexc_interface_class_entry
, ZEND_STRL("CONNECTION_FAILED"), EX_CONNECTION_FAILED
);
83 zend_declare_class_constant_long(php_pqexc_interface_class_entry
, ZEND_STRL("IO"), EX_IO
);
84 zend_declare_class_constant_long(php_pqexc_interface_class_entry
, ZEND_STRL("ESCAPE"), EX_ESCAPE
);
85 zend_declare_class_constant_long(php_pqexc_interface_class_entry
, ZEND_STRL("BAD_METHODCALL"), EX_BAD_METHODCALL
);
86 zend_declare_class_constant_long(php_pqexc_interface_class_entry
, ZEND_STRL("UNINITIALIZED"), EX_UNINITIALIZED
);
87 zend_declare_class_constant_long(php_pqexc_interface_class_entry
, ZEND_STRL("DOMAIN"), EX_DOMAIN
);
88 zend_declare_class_constant_long(php_pqexc_interface_class_entry
, ZEND_STRL("SQL"), EX_SQL
);
90 memset(&ce
, 0, sizeof(ce
));
91 INIT_NS_CLASS_ENTRY(ce
, "pq\\Exception", "InvalidArgumentException", php_pqexc_methods
);
92 php_pqexc_invalid_argument_class_entry
= zend_register_internal_class_ex(&ce
, spl_ce_InvalidArgumentException
);
93 zend_class_implements(php_pqexc_invalid_argument_class_entry
, 1, php_pqexc_interface_class_entry
);
95 memset(&ce
, 0, sizeof(ce
));
96 INIT_NS_CLASS_ENTRY(ce
, "pq\\Exception", "RuntimeException", php_pqexc_methods
);
97 php_pqexc_runtime_class_entry
= zend_register_internal_class_ex(&ce
, spl_ce_RuntimeException
);
98 zend_class_implements(php_pqexc_runtime_class_entry
, 1, php_pqexc_interface_class_entry
);
100 memset(&ce
, 0, sizeof(ce
));
101 INIT_NS_CLASS_ENTRY(ce
, "pq\\Exception", "BadMethodCallException", php_pqexc_methods
);
102 php_pqexc_bad_methodcall_class_entry
= zend_register_internal_class_ex(&ce
, spl_ce_BadMethodCallException
);
103 zend_class_implements(php_pqexc_bad_methodcall_class_entry
, 1, php_pqexc_interface_class_entry
);
105 memset(&ce
, 0, sizeof(ce
));
106 INIT_NS_CLASS_ENTRY(ce
, "pq\\Exception", "DomainException", php_pqexc_methods
);
107 php_pqexc_domain_class_entry
= zend_register_internal_class_ex(&ce
, spl_ce_DomainException
);
108 zend_class_implements(php_pqexc_domain_class_entry
, 1, php_pqexc_interface_class_entry
);
109 zend_declare_property_null(php_pqexc_domain_class_entry
, ZEND_STRL("sqlstate"), ZEND_ACC_PUBLIC
);
119 * vim600: noet sw=4 ts=4 fdm=marker
120 * vim<600: noet sw=4 ts=4