@@ -6,29 +6,76 @@ using namespace std;
66#include < Zend/zend.h>
77#include < Zend/zend_exceptions.h>
88#include < Zend/zend_API.h>
9+ #include < php.h>
910
1011#define ARANGODB_THROW (ex, message ) zend_throw_exception_ex(ex, 0 , message, __FILE__, __LINE__);
1112
1213
13- namespace arangodb { namespace fuerte { namespace php {
1414
15+ namespace {
1516 /*
1617 Exception hierarchy
1718
1819 \Exception
1920 \ArangoDb\Exception
2021 \ArangoDb\RuntimeException
2122 \ArangoDb\InvalidOptionException
23+ \ArangoDb\RequestFailedException
2224
2325 \Arangodb\InvalidArgumentException
2426 */
2527
2628 static zend_class_entry* _Exception;
2729 static zend_class_entry* _RuntimeException;
2830 static zend_class_entry* _InvalidOptionException;
31+ static zend_class_entry* _RequestFailedException;
2932 static zend_class_entry* _InvalidArgumentException;
3033
3134
35+ PHP_METHOD (RequestFailedException, getBody)
36+ {
37+ zval *obj, *value;
38+
39+ if (zend_parse_parameters_none () == FAILURE) {
40+ return ;
41+ }
42+
43+ obj = getThis ();
44+
45+ value = zend_read_property (_RequestFailedException, obj, " body" , sizeof (" body" ) - 1 , 1 , NULL TSRMLS_CC);
46+
47+ RETURN_ZVAL (value, 1 , 0 );
48+ }
49+
50+ PHP_METHOD (RequestFailedException, getHttpCode)
51+ {
52+ zval *obj, *value;
53+
54+ if (zend_parse_parameters_none () == FAILURE) {
55+ return ;
56+ }
57+
58+ obj = getThis ();
59+
60+ value = zend_read_property (_RequestFailedException, obj, " code" , sizeof (" code" ) - 1 , 1 , NULL TSRMLS_CC);
61+
62+ RETURN_ZVAL (value, 1 , 0 );
63+ }
64+
65+
66+ ZEND_BEGIN_ARG_INFO_EX (arginfo_void, 0 , 0 , 0 )
67+ ZEND_END_ARG_INFO ()
68+
69+ const zend_function_entry request_failed_exception_functions[] = {
70+ PHP_ME (RequestFailedException, getBody, arginfo_void, ZEND_ACC_PUBLIC)
71+ PHP_ME (RequestFailedException, getHttpCode, arginfo_void, ZEND_ACC_PUBLIC)
72+ PHP_FE_END
73+ };
74+ }
75+
76+
77+ namespace arangodb { namespace fuerte { namespace php {
78+
3279 static zend_class_entry* Exception () {
3380 zend_string *exceptionClassName = zend_string_tolower (zend_string_init (ZEND_STRL (" ArangoDb\\ Exception" ), 1 ));
3481 zend_class_entry *exceptionClass = static_cast <zend_class_entry*>(zend_hash_find_ptr (CG (class_table), exceptionClassName));
@@ -53,6 +100,29 @@ namespace arangodb { namespace fuerte { namespace php {
53100 return exceptionClass;
54101 }
55102
103+ static zend_class_entry* RequestFailedException () {
104+ zend_string *exceptionClassName = zend_string_tolower (zend_string_init (ZEND_STRL (" ArangoDb\\ RequestFailedException" ), 1 ));
105+ zend_class_entry *exceptionClass = static_cast <zend_class_entry*>(zend_hash_find_ptr (CG (class_table), exceptionClassName));
106+ zend_string_release (exceptionClassName);
107+
108+ return exceptionClass;
109+ }
110+
111+ static void throwRequestFailedException (const char * message, const int code, const char * body) {
112+ zval exObj;
113+ zend_class_entry* exceptionClass = RequestFailedException ();
114+
115+ object_init_ex (&exObj, exceptionClass);
116+
117+ // zend_declare_property_long(_RequestFailedException, "code", sizeof("code") - 1, code, ZEND_ACC_PROTECTED TSRMLS_CC);
118+
119+ zend_update_property_string (exceptionClass, &exObj, " message" , sizeof (" message" ) - 1 , message);
120+ zend_update_property_long (exceptionClass, &exObj, " code" , sizeof (" code" ) - 1 , code);
121+ zend_update_property_string (exceptionClass, &exObj, " body" , sizeof (" body" ) - 1 , body);
122+
123+ zend_throw_exception_object (&exObj);
124+ }
125+
56126 static zend_class_entry* InvalidArgumentException () {
57127 zend_string *exceptionClassName = zend_string_tolower (zend_string_init (ZEND_STRL (" ArangoDb\\ InvalidArgumentException" ), 1 ));
58128 zend_class_entry *exceptionClass = static_cast <zend_class_entry*>(zend_hash_find_ptr (CG (class_table), exceptionClassName));
@@ -83,6 +153,13 @@ namespace arangodb { namespace fuerte { namespace php {
83153 _InvalidOptionException = zend_register_internal_class_ex (&ce, _RuntimeException);
84154 }
85155
156+ static void registerRequestFailedException ()
157+ {
158+ zend_class_entry ce;
159+ INIT_CLASS_ENTRY (ce, " ArangoDb\\ RequestFailedException" , request_failed_exception_functions);
160+ _RequestFailedException = zend_register_internal_class_ex (&ce, _RuntimeException);
161+ }
162+
86163 static void registerInvalidArgumentException ()
87164 {
88165 zend_class_entry ce;
@@ -95,6 +172,7 @@ namespace arangodb { namespace fuerte { namespace php {
95172 registerException ();
96173 registerRuntimeException ();
97174 registerInvalidOptionException ();
175+ registerRequestFailedException ();
98176 registerInvalidArgumentException ();
99177 }
100178
0 commit comments