26
26
27
27
zend_class_entry * php_phongo_readconcern_ce ;
28
28
29
+ /* Initialize the object from a HashTable and return whether it was successful.
30
+ * An exception will be thrown on error. */
31
+ static bool php_phongo_readconcern_init_from_hash (php_phongo_readconcern_t * intern , HashTable * props TSRMLS_DC ) /* {{{ */
32
+ {
33
+ #if PHP_VERSION_ID >= 70000
34
+ zval * level ;
35
+
36
+ intern -> read_concern = mongoc_read_concern_new ();
37
+
38
+ if ((level = zend_hash_str_find (props , "level" , sizeof ("level" ) - 1 ))) {
39
+ if (Z_TYPE_P (level ) == IS_STRING ) {
40
+ mongoc_read_concern_set_level (intern -> read_concern , Z_STRVAL_P (level ));
41
+ return true;
42
+ }
43
+
44
+ phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "%s initialization requires \"level\" string field" , ZSTR_VAL (php_phongo_readconcern_ce -> name ));
45
+ goto failure ;
46
+ }
47
+ #else
48
+ zval * * level ;
49
+
50
+ intern -> read_concern = mongoc_read_concern_new ();
51
+
52
+ if (zend_hash_find (props , "level" , sizeof ("level" ), (void * * ) & level ) == SUCCESS ) {
53
+ if (Z_TYPE_PP (level ) == IS_STRING ) {
54
+ mongoc_read_concern_set_level (intern -> read_concern , Z_STRVAL_PP (level ));
55
+ return true;
56
+ }
57
+
58
+ phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "%s initialization requires \"level\" string field" , ZSTR_VAL (php_phongo_readconcern_ce -> name ));
59
+ goto failure ;
60
+ }
61
+ #endif
62
+
63
+ return true;
64
+
65
+ failure :
66
+ mongoc_read_concern_destroy (intern -> read_concern );
67
+ intern -> read_concern = NULL ;
68
+ return false;
69
+ } /* }}} */
70
+
29
71
/* {{{ proto void MongoDB\Driver\ReadConcern::__construct([string $level])
30
72
Constructs a new ReadConcern */
31
73
static PHP_METHOD (ReadConcern , __construct )
@@ -51,6 +93,26 @@ static PHP_METHOD(ReadConcern, __construct)
51
93
}
52
94
} /* }}} */
53
95
96
+ /* {{{ proto void MongoDB\BSON\ReadConcern::__set_state(array $properties)
97
+ */
98
+ static PHP_METHOD (ReadConcern , __set_state )
99
+ {
100
+ php_phongo_readconcern_t * intern ;
101
+ HashTable * props ;
102
+ zval * array ;
103
+
104
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "a" , & array ) == FAILURE ) {
105
+ RETURN_FALSE ;
106
+ }
107
+
108
+ object_init_ex (return_value , php_phongo_readconcern_ce );
109
+
110
+ intern = Z_READCONCERN_OBJ_P (return_value );
111
+ props = Z_ARRVAL_P (array );
112
+
113
+ php_phongo_readconcern_init_from_hash (intern , props TSRMLS_CC );
114
+ } /* }}} */
115
+
54
116
/* {{{ proto string|null MongoDB\Driver\ReadConcern::getLevel()
55
117
Returns the ReadConcern "level" option */
56
118
static PHP_METHOD (ReadConcern , getLevel )
@@ -140,12 +202,17 @@ ZEND_BEGIN_ARG_INFO_EX(ai_ReadConcern___construct, 0, 0, 0)
140
202
ZEND_ARG_INFO (0 , level )
141
203
ZEND_END_ARG_INFO ()
142
204
205
+ ZEND_BEGIN_ARG_INFO_EX (ai_ReadConcern___set_state , 0 , 0 , 1 )
206
+ ZEND_ARG_ARRAY_INFO (0 , properties , 0 )
207
+ ZEND_END_ARG_INFO ()
208
+
143
209
ZEND_BEGIN_ARG_INFO_EX (ai_ReadConcern_void , 0 , 0 , 0 )
144
210
ZEND_END_ARG_INFO ()
145
211
146
212
static zend_function_entry php_phongo_readconcern_me [] = {
147
213
/* clang-format off */
148
214
PHP_ME (ReadConcern , __construct , ai_ReadConcern___construct , ZEND_ACC_PUBLIC | ZEND_ACC_FINAL )
215
+ PHP_ME (ReadConcern , __set_state , ai_ReadConcern___set_state , ZEND_ACC_PUBLIC | ZEND_ACC_STATIC )
149
216
PHP_ME (ReadConcern , getLevel , ai_ReadConcern_void , ZEND_ACC_PUBLIC | ZEND_ACC_FINAL )
150
217
PHP_ME (ReadConcern , isDefault , ai_ReadConcern_void , ZEND_ACC_PUBLIC | ZEND_ACC_FINAL )
151
218
PHP_ME (ReadConcern , bsonSerialize , ai_ReadConcern_void , ZEND_ACC_PUBLIC | ZEND_ACC_FINAL )
@@ -175,7 +242,7 @@ static void php_phongo_readconcern_free_object(phongo_free_object_arg* object TS
175
242
#if PHP_VERSION_ID < 70000
176
243
efree (intern );
177
244
#endif
178
- } /* }}} */
245
+ }
179
246
180
247
static phongo_create_object_retval php_phongo_readconcern_create_object (zend_class_entry * class_type TSRMLS_DC ) /* {{{ */
181
248
{
0 commit comments