mongo-php-driver icon indicating copy to clipboard operation
mongo-php-driver copied to clipboard

PHPC-2146: Refactor typemap struct and BSON encoding/decoding of zvals

Open alcaeus opened this issue 3 years ago • 0 comments

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_zval and php_phongo_bson_to_zval_ex now take a const bson_t* instead of char* and int. Previously, the function would create a new BSON reader to create a bson_t, which is unnecessary as we start out with a bson_t to begin with. php_phongo_bson_data_to_zval and php_phongo_bson_data_to_zval_ex were added to accept a char* before passing this on to php_phongo_bson_to_zval_ex.
  • The php_phongo_bson_typemap was updated to no longer contain a php_phongo_bson_typemap_types and zend_class_entry* for each type. Instead, a new php_phongo_bson_typemap_element struct 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 potential zval* to this struct which would've made php_phongo_bson_typemap have even more fields without this refactoring.
  • Instantiation of persistable objects in php_phongo_bson_visit_document (including handling for enum on PHP 8.1+) was extracted to php_phongo_bson_init_document_object to make the code more concise.
  • Both php_phongo_bson_visit_document and php_phongo_bson_visit_array were 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.

alcaeus avatar Oct 13 '22 06:10 alcaeus