2626
2727zend_class_entry * php_phongo_readconcern_ce ;
2828
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+
2971/* {{{ proto void MongoDB\Driver\ReadConcern::__construct([string $level])
3072 Constructs a new ReadConcern */
3173static PHP_METHOD (ReadConcern , __construct )
@@ -51,6 +93,26 @@ static PHP_METHOD(ReadConcern, __construct)
5193 }
5294} /* }}} */
5395
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+
54116/* {{{ proto string|null MongoDB\Driver\ReadConcern::getLevel()
55117 Returns the ReadConcern "level" option */
56118static PHP_METHOD (ReadConcern , getLevel )
@@ -140,12 +202,17 @@ ZEND_BEGIN_ARG_INFO_EX(ai_ReadConcern___construct, 0, 0, 0)
140202 ZEND_ARG_INFO (0 , level )
141203ZEND_END_ARG_INFO ()
142204
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+
143209ZEND_BEGIN_ARG_INFO_EX (ai_ReadConcern_void , 0 , 0 , 0 )
144210ZEND_END_ARG_INFO ()
145211
146212static zend_function_entry php_phongo_readconcern_me [] = {
147213 /* clang-format off */
148214 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 )
149216 PHP_ME (ReadConcern , getLevel , ai_ReadConcern_void , ZEND_ACC_PUBLIC | ZEND_ACC_FINAL )
150217 PHP_ME (ReadConcern , isDefault , ai_ReadConcern_void , ZEND_ACC_PUBLIC | ZEND_ACC_FINAL )
151218 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
175242#if PHP_VERSION_ID < 70000
176243 efree (intern );
177244#endif
178- } /* }}} */
245+ }
179246
180247static phongo_create_object_retval php_phongo_readconcern_create_object (zend_class_entry * class_type TSRMLS_DC ) /* {{{ */
181248{
0 commit comments