Skip to content

Commit ca01041

Browse files
Merge v1.x into v2.x (#1715)
2 parents aaf1660 + 3d14230 commit ca01041

15 files changed

+48
-51
lines changed

php_phongo.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,6 @@ zend_object_handlers* phongo_get_std_object_handlers(void);
8282
} \
8383
} while (0)
8484

85-
#define PHONGO_ZVAL_CLASS_OR_TYPE_NAME(zv) (Z_TYPE(zv) == IS_OBJECT ? ZSTR_VAL(Z_OBJCE(zv)->name) : zend_get_type_by_const(Z_TYPE(zv)))
86-
#define PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(zvp) PHONGO_ZVAL_CLASS_OR_TYPE_NAME(*(zvp))
87-
8885
#define PHONGO_ZVAL_EXCEPTION_NAME(e) (ZSTR_VAL(e->ce->name))
8986

9087
#define PHONGO_SET_CREATED_BY_PID(intern) \

src/BSON/Document.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ static PHP_METHOD(MongoDB_BSON_Document, offsetGet)
325325
intern = Z_DOCUMENT_OBJ_P(getThis());
326326

327327
if (Z_TYPE_P(offset) != IS_STRING) {
328-
phongo_throw_exception(PHONGO_ERROR_RUNTIME, "Could not find key of type \"%s\" in BSON document", PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(offset));
328+
phongo_throw_exception(PHONGO_ERROR_RUNTIME, "Could not find key of type \"%s\" in BSON document", zend_zval_type_name(offset));
329329
return;
330330
}
331331

@@ -539,7 +539,7 @@ zval* php_phongo_document_read_dimension(zend_object* object, zval* offset, int
539539
return rv;
540540
}
541541

542-
phongo_throw_exception(PHONGO_ERROR_RUNTIME, "Could not find key of type \"%s\" in BSON document", PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(offset));
542+
phongo_throw_exception(PHONGO_ERROR_RUNTIME, "Could not find key of type \"%s\" in BSON document", zend_zval_type_name(offset));
543543
return &EG(uninitialized_zval);
544544
}
545545

src/BSON/Int64.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static PHP_METHOD(MongoDB_BSON_Int64, __construct)
101101
} else if (Z_TYPE_P(value) == IS_LONG) {
102102
php_phongo_int64_init(intern, Z_LVAL_P(value));
103103
} else {
104-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected value to be integer or string, %s given", PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(value));
104+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected value to be integer or string, %s given", zend_zval_type_name(value));
105105
}
106106
}
107107

src/BSON/Iterator.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ static bool php_phongo_iterator_init_with_zval(php_phongo_iterator_t* iterator,
5454
bson = php_phongo_iterator_get_bson_from_zval(zbson);
5555
if (!bson) {
5656
/* Should never happen, but if it does: exception */
57-
phongo_throw_exception(PHONGO_ERROR_LOGIC, "Could not create iterator for %s instance", PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(zbson));
57+
phongo_throw_exception(PHONGO_ERROR_LOGIC, "Could not create iterator for %s instance", zend_zval_type_name(zbson));
5858

5959
return false;
6060
}
6161

6262
if (!bson_iter_init(&iterator->iter, bson)) {
63-
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE, "Could not create iterator for %s instance", PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(zbson));
63+
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE, "Could not create iterator for %s instance", zend_zval_type_name(zbson));
6464

6565
return false;
6666
}

src/BSON/PackedArray.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ static PHP_METHOD(MongoDB_BSON_PackedArray, offsetGet)
352352
intern = Z_PACKEDARRAY_OBJ_P(getThis());
353353

354354
if (Z_TYPE_P(key) != IS_LONG) {
355-
phongo_throw_exception(PHONGO_ERROR_RUNTIME, "Could not find index of type \"%s\" in BSON array", PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(key));
355+
phongo_throw_exception(PHONGO_ERROR_RUNTIME, "Could not find index of type \"%s\" in BSON array", zend_zval_type_name(key));
356356
return;
357357
}
358358

@@ -529,7 +529,7 @@ zval* php_phongo_packedarray_read_dimension(zend_object* object, zval* offset, i
529529
return rv;
530530
}
531531

532-
phongo_throw_exception(PHONGO_ERROR_RUNTIME, "Could not find index of type \"%s\" in BSON array", PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(offset));
532+
phongo_throw_exception(PHONGO_ERROR_RUNTIME, "Could not find index of type \"%s\" in BSON array", zend_zval_type_name(offset));
533533
return &EG(uninitialized_zval);
534534
}
535535

src/BSON/Timestamp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ static PHP_METHOD(MongoDB_BSON_Timestamp, __construct)
142142
}
143143

144144
if (Z_TYPE_P(increment) != IS_STRING) {
145-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected increment to be an unsigned 32-bit integer or string, %s given", PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(increment));
145+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected increment to be an unsigned 32-bit integer or string, %s given", zend_zval_type_name(increment));
146146
return;
147147
}
148148

@@ -151,7 +151,7 @@ static PHP_METHOD(MongoDB_BSON_Timestamp, __construct)
151151
}
152152

153153
if (Z_TYPE_P(timestamp) != IS_STRING) {
154-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected timestamp to be an unsigned 32-bit integer or string, %s given", PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(timestamp));
154+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected timestamp to be an unsigned 32-bit integer or string, %s given", zend_zval_type_name(timestamp));
155155
return;
156156
}
157157

src/BSON/UTCDateTime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ static PHP_METHOD(MongoDB_BSON_UTCDateTime, __construct)
206206
return;
207207
}
208208

209-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected integer or object, %s given", PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(milliseconds));
209+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected integer or object, %s given", zend_zval_type_name(milliseconds));
210210
}
211211

212212
static PHP_METHOD(MongoDB_BSON_UTCDateTime, __set_state)

src/MongoDB/ClientEncryption.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ static PHP_METHOD(MongoDB_Driver_ClientEncryption, rewrapManyDataKey)
429429
zval* zmasterkey = php_array_fetchc_deref(options, "masterKey");
430430

431431
if (Z_TYPE_P(zmasterkey) != IS_OBJECT && Z_TYPE_P(zmasterkey) != IS_ARRAY) {
432-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"masterKey\" option to be array or object, %s given", PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(zmasterkey));
432+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"masterKey\" option to be array or object, %s given", zend_zval_type_name(zmasterkey));
433433
goto cleanup;
434434
}
435435

@@ -552,7 +552,7 @@ static mongoc_client_encryption_opts_t* phongo_clientencryption_opts_from_zval(z
552552
zval* key_vault_client = php_array_fetchc_deref(options, "keyVaultClient");
553553

554554
if (Z_TYPE_P(key_vault_client) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(key_vault_client), php_phongo_manager_ce)) {
555-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"keyVaultClient\" option to be %s, %s given", ZSTR_VAL(php_phongo_manager_ce->name), PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(key_vault_client));
555+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"keyVaultClient\" option to be %s, %s given", ZSTR_VAL(php_phongo_manager_ce->name), zend_zval_type_name(key_vault_client));
556556
goto cleanup;
557557
}
558558

@@ -601,7 +601,7 @@ static mongoc_client_encryption_opts_t* phongo_clientencryption_opts_from_zval(z
601601
bson_t bson_providers = BSON_INITIALIZER;
602602

603603
if (Z_TYPE_P(kms_providers) != IS_ARRAY && Z_TYPE_P(kms_providers) != IS_OBJECT) {
604-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"kmsProviders\" option to be an array or object, %s given", PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(kms_providers));
604+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"kmsProviders\" option to be an array or object, %s given", zend_zval_type_name(kms_providers));
605605
goto cleanup;
606606
}
607607

@@ -619,7 +619,7 @@ static mongoc_client_encryption_opts_t* phongo_clientencryption_opts_from_zval(z
619619
bson_t bson_options = BSON_INITIALIZER;
620620

621621
if (Z_TYPE_P(tls_options) != IS_ARRAY && Z_TYPE_P(tls_options) != IS_OBJECT) {
622-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"tlsOptions\" option to be an array or object, %s given", PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(tls_options));
622+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"tlsOptions\" option to be an array or object, %s given", zend_zval_type_name(tls_options));
623623
goto cleanup;
624624
}
625625

@@ -715,7 +715,7 @@ static mongoc_client_encryption_datakey_opts_t* phongo_clientencryption_datakey_
715715
bool failed = false;
716716

717717
if (!zkeyaltnames || Z_TYPE_P(zkeyaltnames) != IS_ARRAY) {
718-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected keyAltNames to be array, %s given", PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(zkeyaltnames));
718+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected keyAltNames to be array, %s given", zend_zval_type_name(zkeyaltnames));
719719
goto cleanup;
720720
}
721721

@@ -738,9 +738,9 @@ static mongoc_client_encryption_datakey_opts_t* phongo_clientencryption_datakey_
738738

739739
if (Z_TYPE_P(keyaltname) != IS_STRING) {
740740
if (string_key) {
741-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected keyAltName with index \"%s\" to be string, %s given", ZSTR_VAL(string_key), PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(keyaltname));
741+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected keyAltName with index \"%s\" to be string, %s given", ZSTR_VAL(string_key), zend_zval_type_name(keyaltname));
742742
} else {
743-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected keyAltName with index \"%lu\" to be string, %s given", num_key, PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(keyaltname));
743+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected keyAltName with index \"%lu\" to be string, %s given", num_key, zend_zval_type_name(keyaltname));
744744
}
745745

746746
failed = true;
@@ -771,7 +771,7 @@ static mongoc_client_encryption_datakey_opts_t* phongo_clientencryption_datakey_
771771
zval* keyMaterial = php_array_fetchc_deref(options, "keyMaterial");
772772

773773
if (Z_TYPE_P(keyMaterial) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(keyMaterial), php_phongo_binary_ce)) {
774-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"keyMaterial\" option to be %s, %s given", ZSTR_VAL(php_phongo_binary_ce->name), PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(keyMaterial));
774+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"keyMaterial\" option to be %s, %s given", ZSTR_VAL(php_phongo_binary_ce->name), zend_zval_type_name(keyMaterial));
775775
goto cleanup;
776776
}
777777

@@ -783,7 +783,7 @@ static mongoc_client_encryption_datakey_opts_t* phongo_clientencryption_datakey_
783783
bson_t masterkey = BSON_INITIALIZER;
784784

785785
if (Z_TYPE_P(zmasterkey) != IS_OBJECT && Z_TYPE_P(zmasterkey) != IS_ARRAY) {
786-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"masterKey\" option to be array or object, %s given", PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(zmasterkey));
786+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"masterKey\" option to be array or object, %s given", zend_zval_type_name(zmasterkey));
787787
goto cleanup;
788788
}
789789

src/MongoDB/Manager.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ static PHP_METHOD(MongoDB_Driver_Manager, startSession)
741741
phongo_throw_exception(
742742
PHONGO_ERROR_INVALID_ARGUMENT,
743743
"Expected \"defaultTransactionOptions\" option to be an array, %s given",
744-
PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(txn_options));
744+
zend_zval_type_name(txn_options));
745745
goto cleanup;
746746
}
747747

src/MongoDB/Query.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static bool php_phongo_query_opts_append_string(bson_t* opts, const char* opts_k
3939
zval* value = php_array_fetch_deref(zarr, zarr_key);
4040

4141
if (Z_TYPE_P(value) != IS_STRING) {
42-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"%s\" option to be string, %s given", zarr_key, PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(value));
42+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"%s\" option to be string, %s given", zarr_key, zend_zval_type_name(value));
4343
return false;
4444
}
4545

@@ -59,7 +59,7 @@ static bool php_phongo_query_opts_append_document(bson_t* opts, const char* opts
5959
bson_t b = BSON_INITIALIZER;
6060

6161
if (Z_TYPE_P(value) != IS_OBJECT && Z_TYPE_P(value) != IS_ARRAY) {
62-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"%s\" option to be array or object, %s given", zarr_key, PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(value));
62+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"%s\" option to be array or object, %s given", zarr_key, zend_zval_type_name(value));
6363
return false;
6464
}
6565

@@ -188,7 +188,7 @@ static bool php_phongo_query_init_readconcern(php_phongo_query_t* intern, zval*
188188
read_concern = php_array_fetchc_deref(options, "readConcern");
189189

190190
if (Z_TYPE_P(read_concern) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(read_concern), php_phongo_readconcern_ce)) {
191-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"readConcern\" option to be %s, %s given", ZSTR_VAL(php_phongo_readconcern_ce->name), PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(read_concern));
191+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"readConcern\" option to be %s, %s given", ZSTR_VAL(php_phongo_readconcern_ce->name), zend_zval_type_name(read_concern));
192192
return false;
193193
}
194194

@@ -238,7 +238,7 @@ bool phongo_query_init(zval* return_value, zval* filter, zval* options)
238238
}
239239

240240
if (Z_TYPE_P(return_value) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(return_value), php_phongo_query_ce)) {
241-
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE, "Expected initialization object to be %s, %s given", ZSTR_VAL(php_phongo_query_ce->name), PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(return_value));
241+
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE, "Expected initialization object to be %s, %s given", ZSTR_VAL(php_phongo_query_ce->name), zend_zval_type_name(return_value));
242242
return false;
243243
}
244244

src/MongoDB/Session.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ mongoc_transaction_opt_t* php_mongodb_session_parse_transaction_options(zval* op
381381
zval* read_concern = php_array_fetchc_deref(options, "readConcern");
382382

383383
if (Z_TYPE_P(read_concern) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(read_concern), php_phongo_readconcern_ce)) {
384-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"readConcern\" option to be %s, %s given", ZSTR_VAL(php_phongo_readconcern_ce->name), PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(read_concern));
384+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"readConcern\" option to be %s, %s given", ZSTR_VAL(php_phongo_readconcern_ce->name), zend_zval_type_name(read_concern));
385385
if (opts) {
386386
mongoc_transaction_opts_destroy(opts);
387387
}
@@ -399,7 +399,7 @@ mongoc_transaction_opt_t* php_mongodb_session_parse_transaction_options(zval* op
399399
zval* read_preference = php_array_fetchc_deref(options, "readPreference");
400400

401401
if (Z_TYPE_P(read_preference) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(read_preference), php_phongo_readpreference_ce)) {
402-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"readPreference\" option to be %s, %s given", ZSTR_VAL(php_phongo_readpreference_ce->name), PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(read_preference));
402+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"readPreference\" option to be %s, %s given", ZSTR_VAL(php_phongo_readpreference_ce->name), zend_zval_type_name(read_preference));
403403
if (opts) {
404404
mongoc_transaction_opts_destroy(opts);
405405
}
@@ -417,7 +417,7 @@ mongoc_transaction_opt_t* php_mongodb_session_parse_transaction_options(zval* op
417417
zval* write_concern = php_array_fetchc_deref(options, "writeConcern");
418418

419419
if (Z_TYPE_P(write_concern) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(write_concern), php_phongo_writeconcern_ce)) {
420-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"writeConcern\" option to be %s, %s given", ZSTR_VAL(php_phongo_writeconcern_ce->name), PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(write_concern));
420+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"writeConcern\" option to be %s, %s given", ZSTR_VAL(php_phongo_writeconcern_ce->name), zend_zval_type_name(write_concern));
421421
if (opts) {
422422
mongoc_transaction_opts_destroy(opts);
423423
}

src/MongoDB/WriteConcern.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ static PHP_METHOD(MongoDB_Driver_WriteConcern, __construct)
136136
mongoc_write_concern_set_wtag(intern->write_concern, Z_STRVAL_P(w));
137137
}
138138
} else {
139-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected w to be integer or string, %s given", PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(w));
139+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected w to be integer or string, %s given", zend_zval_type_name(w));
140140
return;
141141
}
142142

src/phongo_bson_encode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static inline bool phongo_check_bson_serialize_return_type(zval* retval, zend_cl
104104
ZSTR_VAL(ce->name),
105105
BSON_SERIALIZE_FUNC_NAME,
106106
ZSTR_VAL(php_phongo_document_ce->name),
107-
PHONGO_ZVAL_CLASS_OR_TYPE_NAME(*retval));
107+
zend_zval_type_name(retval));
108108
return false;
109109
}
110110

@@ -121,7 +121,7 @@ static inline bool phongo_check_bson_serialize_return_type(zval* retval, zend_cl
121121
BSON_SERIALIZE_FUNC_NAME,
122122
ZSTR_VAL(php_phongo_document_ce->name),
123123
ZSTR_VAL(php_phongo_packedarray_ce->name),
124-
PHONGO_ZVAL_CLASS_OR_TYPE_NAME(*retval));
124+
zend_zval_type_name(retval));
125125
return false;
126126
}
127127

0 commit comments

Comments
 (0)