@@ -1201,6 +1201,78 @@ static bool php_phongo_bson_state_parse_type(zval* options, const char* name, ph
1201
1201
return retval ;
1202
1202
} /* }}} */
1203
1203
1204
+ /* Loops over each element in the fieldPaths array (if exists, and is an
1205
+ * array), and then checks whether each element is a valid type mapping */
1206
+ bool php_phongo_bson_state_parse_fieldpaths (zval * typemap , php_phongo_bson_typemap * map TSRMLS_DC ) /* {{{ */
1207
+ {
1208
+ zval * fieldpaths = NULL ;
1209
+ HashTable * ht_data ;
1210
+
1211
+ if (!php_array_existsc (typemap , "fieldPaths" )) {
1212
+ return true;
1213
+ }
1214
+
1215
+ fieldpaths = php_array_fetchc_array (typemap , "fieldPaths" );
1216
+
1217
+ if (!fieldpaths ) {
1218
+ phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "The 'fieldPaths' element is not an array" );
1219
+ return false;
1220
+ }
1221
+
1222
+ ht_data = HASH_OF (fieldpaths );
1223
+
1224
+ #if PHP_VERSION_ID >= 70000
1225
+ {
1226
+ zend_string * string_key = NULL ;
1227
+ zend_ulong num_key = 0 ;
1228
+ zval * property ;
1229
+
1230
+ ZEND_HASH_FOREACH_KEY_VAL (ht_data , num_key , string_key , property )
1231
+ {
1232
+ zend_class_entry * map_ce = NULL ;
1233
+ php_phongo_bson_typemap_types map_type ;
1234
+
1235
+ if (!string_key ) {
1236
+ phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "The 'fieldPaths' element is not an associative array" );
1237
+ return false;
1238
+ }
1239
+
1240
+ if (!php_phongo_bson_state_parse_type (fieldpaths , ZSTR_VAL (string_key ), & map_type , & map_ce TSRMLS_CC )) {
1241
+ return false;
1242
+ }
1243
+ }
1244
+ ZEND_HASH_FOREACH_END ();
1245
+ }
1246
+ #else
1247
+ {
1248
+ HashPosition pos ;
1249
+ zval * * property ;
1250
+
1251
+ for (
1252
+ zend_hash_internal_pointer_reset_ex (ht_data , & pos );
1253
+ zend_hash_get_current_data_ex (ht_data , (void * * ) & property , & pos ) == SUCCESS ;
1254
+ zend_hash_move_forward_ex (ht_data , & pos )) {
1255
+
1256
+ char * string_key = NULL ;
1257
+ uint string_key_len = 0 ;
1258
+ ulong num_key = 0 ;
1259
+ zend_class_entry * map_ce = NULL ;
1260
+ php_phongo_bson_typemap_types map_type ;
1261
+
1262
+ if (HASH_KEY_IS_STRING != zend_hash_get_current_key_ex (ht_data , & string_key , & string_key_len , & num_key , 0 , & pos )) {
1263
+ phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "The 'fieldPaths' element is not an associative array" );
1264
+ return false;
1265
+ }
1266
+
1267
+ if (!php_phongo_bson_state_parse_type (fieldpaths , string_key , & map_type , & map_ce TSRMLS_CC )) {
1268
+ return false;
1269
+ }
1270
+ }
1271
+ }
1272
+ #endif /* PHP_VERSION_ID >= 70000 */
1273
+ return true;
1274
+ } /* }}} */
1275
+
1204
1276
/* Applies the array argument to a typemap struct. Returns true on success;
1205
1277
* otherwise, false is returned an an exception is thrown. */
1206
1278
bool php_phongo_bson_typemap_to_state (zval * typemap , php_phongo_bson_typemap * map TSRMLS_DC ) /* {{{ */
@@ -1211,7 +1283,8 @@ bool php_phongo_bson_typemap_to_state(zval* typemap, php_phongo_bson_typemap* ma
1211
1283
1212
1284
if (!php_phongo_bson_state_parse_type (typemap , "array" , & map -> array_type , & map -> array TSRMLS_CC ) ||
1213
1285
!php_phongo_bson_state_parse_type (typemap , "document" , & map -> document_type , & map -> document TSRMLS_CC ) ||
1214
- !php_phongo_bson_state_parse_type (typemap , "root" , & map -> root_type , & map -> root TSRMLS_CC )) {
1286
+ !php_phongo_bson_state_parse_type (typemap , "root" , & map -> root_type , & map -> root TSRMLS_CC ) ||
1287
+ !php_phongo_bson_state_parse_fieldpaths (typemap , map TSRMLS_CC )) {
1215
1288
1216
1289
/* Exception should already have been thrown */
1217
1290
return false;
0 commit comments