mongo-php-driver
mongo-php-driver copied to clipboard
PHPC-2146: Refactor typemap struct and BSON encoding/decoding of zvals
PHPC-2146
Best reviewed commit by commit. This PR introduces some refactorings that I made while prototyping raw BSON support. No functional changes are introduced as part of this PR. This improves the following:
php_phongo_bson_to_zvalandphp_phongo_bson_to_zval_exnow take aconst bson_t*instead ofchar*andint. Previously, the function would create a new BSON reader to create abson_t, which is unnecessary as we start out with abson_tto begin with.php_phongo_bson_data_to_zvalandphp_phongo_bson_data_to_zval_exwere added to accept achar*before passing this on tophp_phongo_bson_to_zval_ex.- The
php_phongo_bson_typemapwas updated to no longer contain aphp_phongo_bson_typemap_typesandzend_class_entry*for each type. Instead, a newphp_phongo_bson_typemap_elementstruct containing the type and class entry was added. While better structuring data that belongs together, this also makes it easier to add new fields to the type map (in my prototype, I needed to add a potentialzval*to this struct which would've madephp_phongo_bson_typemaphave even more fields without this refactoring. - Instantiation of persistable objects in
php_phongo_bson_visit_document(including handling forenumon PHP 8.1+) was extracted tophp_phongo_bson_init_document_objectto make the code more concise. - Both
php_phongo_bson_visit_documentandphp_phongo_bson_visit_arraywere refactored to avoid the duplication of the logic adding the resulting data structure to the parent. This will make it easier to add more options to the type map. - The last commit fixes a wrong parameter name in the forward declaration of
php_phongo_bson_visit_array.