phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE,"Expected %s for field path \"%s\" to be <= %"PRId32" bytes, %zu given",description,path_string,(int32_t)PHONGO_BSON_MAX_LENGTH,length);
efree(path_string);
returnfalse;
}
/* Determines whether the argument should be serialized as a BSON array or
* document. IS_ARRAY is returned if the argument's keys are a sequence of
* integers starting at zero; otherwise, IS_OBJECT is returned. */
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE,"Non-backed enum %s cannot be serialized for field path \"%s\"",ZSTR_VAL(Z_OBJCE_P(object)->name),path_string);
/* A key longer than BSON_MAX_SIZE wraps a size_t/long length to a small
* non-negative int in the libbson append, silently truncating the field
* name to a prefix (SECBUG-4150). Reject before narrowing. The key is not
* included in the message or the field path, as it may be gigabytes. */
if(key_len>PHONGO_BSON_MAX_LENGTH){
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE,"Expected key length to be <= %"PRId32" bytes, %zu given",(int32_t)PHONGO_BSON_MAX_LENGTH,(size_t)key_len);
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE,"Detected unsupported PHP type for field path \"%s\": %d (%s)",path_string,Z_TYPE_P(entry),zend_get_type_by_const(Z_TYPE_P(entry)));
efree(path_string);
}
}
}
/* This is based on bson_copy_to_excluding_noinit() and is necessary because
* bson_copy_to() cannot be used with a bson_t allocated with bson_new(). */
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE,"Could not append \"%s\" field to encoded document. The document may exceed the maximum BSON size of %zu bytes.",PHONGO_ODM_FIELD_NAME,(size_t)BSON_MAX_SIZE);
gotocleanup;
}
/* Ensure that we ignore an existing key with the same name
* if one exists in the bsonSerialize() return value. */
skip_odm_field=true;
}
// If bsonSerialize() returns a BSON document or packedArray instance, recurse to copy data over directly
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE,"%s instance %s cannot be serialized as a root element",ZSTR_VAL(phongo_type_ce->name),ZSTR_VAL(Z_OBJCE_P(data)->name));
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE,"Could not append \"_id\" field to encoded document. The document may exceed the maximum BSON size of %zu bytes.",(size_t)BSON_MAX_SIZE);
gotocleanup;
}
}
if(flags&PHONGO_BSON_RETURN_ID&&bson_out){
bson_iter_titer;
/* This should not be able to happen since we are copying from
* within a valid bson_t. */
if(!bson_iter_init_find(&iter,bson,"_id")){
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE,"Error copying \"_id\" field from encoded document");
gotocleanup;
}
*bson_out=bson_new();
if(!bson_append_iter(*bson_out,NULL,0,&iter)){
/* This should not be able to happen since we are copying from
* within a valid bson_t. */
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE,"Error copying \"_id\" field from encoded document");
bson_clear(bson_out);
gotocleanup;
}
}
cleanup:
if(!Z_ISUNDEF(obj_data)){
zval_ptr_dtor(&obj_data);
}
}
/* Converts the array or object argument to a BSON document. If the object is an
* instance of MongoDB\BSON\Serializable, the return value of bsonSerialize()
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE,"Expected string to be <= %"PRId32" bytes, %zu given",(int32_t)PHONGO_BSON_MAX_LENGTH,Z_STRLEN_P(data));