Commit f77a8f3b authored by Ondrej Sury's avatar Ondrej Sury

New upstream version 1.2.10

parent 362ffbc4
......@@ -25,7 +25,7 @@
extern zend_module_entry mongodb_module_entry;
/* FIXME: Its annoying to bump version. Move into phongo_version.h.in */
#define PHP_MONGODB_VERSION "1.2.9"
#define PHP_MONGODB_VERSION "1.2.10"
#define PHP_MONGODB_STABILITY "stable"
#ifdef PHP_WIN32
......
......@@ -142,7 +142,11 @@ static bool php_phongo_utcdatetime_init_from_date(php_phongo_utcdatetime_t *inte
/* The following assignments use the same logic as date_format() in php_date.c */
sec = datetime_obj->time->sse;
#if PHP_VERSION_ID >= 70200
usec = (int64_t) floor(datetime_obj->time->us);
#else
usec = (int64_t) floor(datetime_obj->time->f * 1000000 + 0.5);
#endif
intern->milliseconds = (sec * 1000) + (usec / 1000);
intern->initialized = true;
......@@ -273,7 +277,11 @@ PHP_METHOD(UTCDateTime, toDateTime)
php_date_initialize(datetime_obj, sec, sec_len, NULL, NULL, 0 TSRMLS_CC);
efree(sec);
#if PHP_VERSION_ID >= 70200
datetime_obj->time->us = (intern->milliseconds % 1000) * 1000;
#else
datetime_obj->time->f = (double) (intern->milliseconds % 1000) / 1000;
#endif
}
/* }}} */
......
......@@ -807,7 +807,7 @@ bool php_phongo_bson_visit_document(const bson_iter_t *iter ARG_UNUSED, const ch
case PHONGO_TYPEMAP_NATIVE_OBJECT:
default:
#if PHP_VERSION_ID >= 70000
object_and_properties_init(&state.zchild, zend_standard_class_def, Z_ARRVAL(state.zchild));
convert_to_object(&state.zchild);
if (((php_phongo_bson_state *)data)->is_visiting_array) {
add_next_index_zval(retval, &state.zchild);
} else {
......@@ -815,7 +815,7 @@ bool php_phongo_bson_visit_document(const bson_iter_t *iter ARG_UNUSED, const ch
}
Z_SET_REFCOUNT(state.zchild, 1);
#else
object_and_properties_init(state.zchild, zend_standard_class_def, Z_ARRVAL_P(state.zchild));
convert_to_object(state.zchild);
if (((php_phongo_bson_state *)data)->is_visiting_array) {
add_next_index_zval(retval, state.zchild);
} else {
......@@ -898,7 +898,7 @@ bool php_phongo_bson_visit_array(const bson_iter_t *iter ARG_UNUSED, const char
case PHONGO_TYPEMAP_NATIVE_OBJECT:
#if PHP_VERSION_ID >= 70000
object_and_properties_init(&state.zchild, zend_standard_class_def, Z_ARRVAL(state.zchild));
convert_to_object(&state.zchild);
if (((php_phongo_bson_state *)data)->is_visiting_array) {
add_next_index_zval(retval, &state.zchild);
} else {
......@@ -906,7 +906,7 @@ bool php_phongo_bson_visit_array(const bson_iter_t *iter ARG_UNUSED, const char
}
Z_SET_REFCOUNT(state.zchild, 1);
#else
object_and_properties_init(state.zchild, zend_standard_class_def, Z_ARRVAL_P(state.zchild));
convert_to_object(state.zchild);
if (((php_phongo_bson_state *)data)->is_visiting_array) {
add_next_index_zval(retval, state.zchild);
} else {
......@@ -1284,6 +1284,11 @@ void phongo_zval_to_bson(zval *data, php_phongo_bson_flags_t flags, bson_t *bson
* properties, we'll need to filter them out later. */
bool ht_data_from_properties = false;
/* If the object is an instance of MongoDB\BSON\Persistable, we will need to
* inject the PHP class name as a BSON key and ignore any existing key in
* the return value of bsonSerialize(). */
bool skip_odm_field = false;
ZVAL_UNDEF(&obj_data);
switch(Z_TYPE_P(data)) {
......@@ -1338,11 +1343,12 @@ void phongo_zval_to_bson(zval *data, php_phongo_bson_flags_t flags, bson_t *bson
if (instanceof_function(Z_OBJCE_P(data), php_phongo_persistable_ce TSRMLS_CC)) {
#if PHP_VERSION_ID >= 70000
bson_append_binary(bson, PHONGO_ODM_FIELD_NAME, -1, 0x80, (const uint8_t *)Z_OBJCE_P(data)->name->val, Z_OBJCE_P(data)->name->len);
zend_hash_str_del(ht_data, PHONGO_ODM_FIELD_NAME, sizeof(PHONGO_ODM_FIELD_NAME)-1);
#else
bson_append_binary(bson, PHONGO_ODM_FIELD_NAME, -1, 0x80, (const uint8_t *)Z_OBJCE_P(data)->name, strlen(Z_OBJCE_P(data)->name));
zend_hash_del(ht_data, PHONGO_ODM_FIELD_NAME, sizeof(PHONGO_ODM_FIELD_NAME));
#endif
/* Ensure that we ignore an existing key with the same name
* if one exists in the bsonSerialize() return value. */
skip_odm_field = true;
}
break;
......@@ -1387,6 +1393,10 @@ void phongo_zval_to_bson(zval *data, php_phongo_bson_flags_t flags, bson_t *bson
goto cleanup;
}
if (skip_odm_field && !strcmp(ZSTR_VAL(string_key), PHONGO_ODM_FIELD_NAME)) {
continue;
}
if (flags & PHONGO_BSON_ADD_ID) {
if (!strcmp(ZSTR_VAL(string_key), "_id")) {
flags &= ~PHONGO_BSON_ADD_ID;
......@@ -1439,6 +1449,10 @@ void phongo_zval_to_bson(zval *data, php_phongo_bson_flags_t flags, bson_t *bson
goto cleanup;
}
if (skip_odm_field && !strcmp(string_key, PHONGO_ODM_FIELD_NAME)) {
continue;
}
if (flags & PHONGO_BSON_ADD_ID) {
if (!strcmp(string_key, "_id")) {
flags &= ~PHONGO_BSON_ADD_ID;
......@@ -1587,9 +1601,9 @@ int phongo_bson_to_zval_ex(const unsigned char *data, int data_len, php_phongo_b
case PHONGO_TYPEMAP_NATIVE_OBJECT:
default:
#if PHP_VERSION_ID >= 70000
object_and_properties_init(&state->zchild, zend_standard_class_def, Z_ARRVAL(state->zchild));
convert_to_object(&state->zchild);
#else
object_and_properties_init(state->zchild, zend_standard_class_def, Z_ARRVAL_P(state->zchild));
convert_to_object(state->zchild);
#endif
}
......