Skip to content

PHPC-1027: Introduce classes for deprecated BSON types #700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ if test "$MONGODB" != "no"; then
src/bson-encode.c \
src/BSON/Binary.c \
src/BSON/BinaryInterface.c \
src/BSON/DBPointer.c \
src/BSON/Decimal128.c \
src/BSON/Decimal128Interface.c \
src/BSON/Javascript.c \
Expand All @@ -171,9 +172,11 @@ if test "$MONGODB" != "no"; then
src/BSON/Regex.c \
src/BSON/RegexInterface.c \
src/BSON/Serializable.c \
src/BSON/Symbol.c \
src/BSON/Timestamp.c \
src/BSON/TimestampInterface.c \
src/BSON/Type.c \
src/BSON/Undefined.c \
src/BSON/Unserializable.c \
src/BSON/UTCDateTime.c \
src/BSON/UTCDateTimeInterface.c \
Expand Down
2 changes: 1 addition & 1 deletion config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ if (PHP_MONGODB != "no") {

EXTENSION("mongodb", "php_phongo.c phongo_compat.c", null, PHP_MONGODB_CFLAGS);
ADD_SOURCES(configure_module_dirname + "/src", "bson.c bson-encode.c", "mongodb");
ADD_SOURCES(configure_module_dirname + "/src/BSON", "Binary.c BinaryInterface.c Decimal128.c Decimal128Interface.c Javascript.c JavascriptInterface.c MaxKey.c MaxKeyInterface.c MinKey.c MinKeyInterface.c ObjectId.c ObjectIdInterface.c Persistable.c Regex.c RegexInterface.c Serializable.c Timestamp.c TimestampInterface.c Type.c Unserializable.c UTCDateTime.c UTCDateTimeInterface.c functions.c", "mongodb");
ADD_SOURCES(configure_module_dirname + "/src/BSON", "Binary.c BinaryInterface.c DBPointer.c Decimal128.c Decimal128Interface.c Javascript.c JavascriptInterface.c MaxKey.c MaxKeyInterface.c MinKey.c MinKeyInterface.c ObjectId.c ObjectIdInterface.c Persistable.c Regex.c RegexInterface.c Serializable.c Symbol.c Timestamp.c TimestampInterface.c Type.c Undefined.c Unserializable.c UTCDateTime.c UTCDateTimeInterface.c functions.c", "mongodb");
ADD_SOURCES(configure_module_dirname + "/src/MongoDB", "BulkWrite.c Command.c Cursor.c CursorId.c Manager.c Query.c ReadConcern.c ReadPreference.c Server.c WriteConcern.c WriteConcernError.c WriteError.c WriteResult.c", "mongodb");
ADD_SOURCES(configure_module_dirname + "/src/MongoDB/Exception", "AuthenticationException.c BulkWriteException.c ConnectionException.c ConnectionTimeoutException.c Exception.c ExecutionTimeoutException.c InvalidArgumentException.c LogicException.c RuntimeException.c SSLConnectionException.c UnexpectedValueException.c WriteException.c", "mongodb");
ADD_SOURCES(configure_module_dirname + "/src/MongoDB/Monitoring", "CommandFailedEvent.c CommandStartedEvent.c CommandSubscriber.c CommandSucceededEvent.c Subscriber.c functions.c", "mongodb");
Expand Down
26 changes: 26 additions & 0 deletions php_phongo.c
Original file line number Diff line number Diff line change
Expand Up @@ -2386,6 +2386,29 @@ void php_phongo_new_regex_from_regex_and_options(zval *object, const char *patte
qsort((void *) intern->flags, intern->flags_len, 1, php_phongo_regex_compare_flags);
} /* }}} */

void php_phongo_new_symbol(zval *object, const char *symbol, size_t symbol_len TSRMLS_DC) /* {{{ */
{
php_phongo_symbol_t *intern;

object_init_ex(object, php_phongo_symbol_ce);

intern = Z_SYMBOL_OBJ_P(object);
intern->symbol = estrndup(symbol, symbol_len);
intern->symbol_len = symbol_len;
} /* }}} */

void php_phongo_new_dbpointer(zval *object, const char *ref, size_t ref_len, const bson_oid_t *oid TSRMLS_DC) /* {{{ */
{
php_phongo_dbpointer_t *intern;

object_init_ex(object, php_phongo_dbpointer_ce);

intern = Z_DBPOINTER_OBJ_P(object);
intern->ref = estrndup(ref, ref_len);
intern->ref_len = ref_len;
bson_oid_to_string(oid, intern->id);
} /* }}} */

/* {{{ Memory allocation wrappers */
static void* php_phongo_malloc(size_t num_bytes) /* {{{ */
{
Expand Down Expand Up @@ -2647,14 +2670,17 @@ PHP_MINIT_FUNCTION(mongodb)
php_phongo_utcdatetime_interface_init_ce(INIT_FUNC_ARGS_PASSTHRU);

php_phongo_binary_init_ce(INIT_FUNC_ARGS_PASSTHRU);
php_phongo_dbpointer_init_ce(INIT_FUNC_ARGS_PASSTHRU);
php_phongo_decimal128_init_ce(INIT_FUNC_ARGS_PASSTHRU);
php_phongo_javascript_init_ce(INIT_FUNC_ARGS_PASSTHRU);
php_phongo_maxkey_init_ce(INIT_FUNC_ARGS_PASSTHRU);
php_phongo_minkey_init_ce(INIT_FUNC_ARGS_PASSTHRU);
php_phongo_objectid_init_ce(INIT_FUNC_ARGS_PASSTHRU);
php_phongo_persistable_init_ce(INIT_FUNC_ARGS_PASSTHRU);
php_phongo_regex_init_ce(INIT_FUNC_ARGS_PASSTHRU);
php_phongo_symbol_init_ce(INIT_FUNC_ARGS_PASSTHRU);
php_phongo_timestamp_init_ce(INIT_FUNC_ARGS_PASSTHRU);
php_phongo_undefined_init_ce(INIT_FUNC_ARGS_PASSTHRU);
php_phongo_utcdatetime_init_ce(INIT_FUNC_ARGS_PASSTHRU);

php_phongo_bulkwrite_init_ce(INIT_FUNC_ARGS_PASSTHRU);
Expand Down
2 changes: 2 additions & 0 deletions php_phongo.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ void php_phongo_new_javascript_from_javascript_and_scope(int init, zval *object,
void php_phongo_new_binary_from_binary_and_type(zval *object, const char *data, size_t data_len, bson_subtype_t type TSRMLS_DC);
void php_phongo_new_decimal128(zval *object, const bson_decimal128_t *decimal TSRMLS_DC);
void php_phongo_new_regex_from_regex_and_options(zval *object, const char *pattern, const char *flags TSRMLS_DC);
void php_phongo_new_symbol(zval *object, const char *symbol, size_t symbol_len TSRMLS_DC);
void php_phongo_new_dbpointer(zval *object, const char *namespace, size_t namespace_len, const bson_oid_t *oid TSRMLS_DC);

zend_bool phongo_writeerror_init(zval *return_value, bson_t *bson TSRMLS_DC);
zend_bool phongo_writeconcernerror_init(zval *return_value, bson_t *bson TSRMLS_DC);
Expand Down
29 changes: 28 additions & 1 deletion php_phongo_classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ static inline php_phongo_writeresult_t* php_writeresult_fetch_object(zend_object
static inline php_phongo_binary_t* php_binary_fetch_object(zend_object *obj) {
return (php_phongo_binary_t *)((char *)obj - XtOffsetOf(php_phongo_binary_t, std));
}
static inline php_phongo_dbpointer_t* php_dbpointer_fetch_object(zend_object *obj) {
return (php_phongo_dbpointer_t *)((char *)obj - XtOffsetOf(php_phongo_dbpointer_t, std));
}
static inline php_phongo_decimal128_t* php_decimal128_fetch_object(zend_object *obj) {
return (php_phongo_decimal128_t *)((char *)obj - XtOffsetOf(php_phongo_decimal128_t, std));
}
Expand All @@ -85,9 +88,15 @@ static inline php_phongo_objectid_t* php_objectid_fetch_object(zend_object *obj)
static inline php_phongo_regex_t* php_regex_fetch_object(zend_object *obj) {
return (php_phongo_regex_t *)((char *)obj - XtOffsetOf(php_phongo_regex_t, std));
}
static inline php_phongo_symbol_t* php_symbol_fetch_object(zend_object *obj) {
return (php_phongo_symbol_t *)((char *)obj - XtOffsetOf(php_phongo_symbol_t, std));
}
static inline php_phongo_timestamp_t* php_timestamp_fetch_object(zend_object *obj) {
return (php_phongo_timestamp_t *)((char *)obj - XtOffsetOf(php_phongo_timestamp_t, std));
}
static inline php_phongo_undefined_t* php_undefined_fetch_object(zend_object *obj) {
return (php_phongo_undefined_t *)((char *)obj - XtOffsetOf(php_phongo_undefined_t, std));
}
static inline php_phongo_utcdatetime_t* php_utcdatetime_fetch_object(zend_object *obj) {
return (php_phongo_utcdatetime_t *)((char *)obj - XtOffsetOf(php_phongo_utcdatetime_t, std));
}
Expand Down Expand Up @@ -115,13 +124,16 @@ static inline php_phongo_commandsucceededevent_t* php_commandsucceededevent_fetc
# define Z_WRITEERROR_OBJ_P(zv) (php_writeerror_fetch_object(Z_OBJ_P(zv)))
# define Z_WRITERESULT_OBJ_P(zv) (php_writeresult_fetch_object(Z_OBJ_P(zv)))
# define Z_BINARY_OBJ_P(zv) (php_binary_fetch_object(Z_OBJ_P(zv)))
# define Z_DBPOINTER_OBJ_P(zv) (php_dbpointer_fetch_object(Z_OBJ_P(zv)))
# define Z_DECIMAL128_OBJ_P(zv) (php_decimal128_fetch_object(Z_OBJ_P(zv)))
# define Z_JAVASCRIPT_OBJ_P(zv) (php_javascript_fetch_object(Z_OBJ_P(zv)))
# define Z_MAXKEY_OBJ_P(zv) (php_maxkey_fetch_object(Z_OBJ_P(zv)))
# define Z_MINKEY_OBJ_P(zv) (php_minkey_fetch_object(Z_OBJ_P(zv)))
# define Z_OBJECTID_OBJ_P(zv) (php_objectid_fetch_object(Z_OBJ_P(zv)))
# define Z_REGEX_OBJ_P(zv) (php_regex_fetch_object(Z_OBJ_P(zv)))
# define Z_SYMBOL_OBJ_P(zv) (php_symbol_fetch_object(Z_OBJ_P(zv)))
# define Z_TIMESTAMP_OBJ_P(zv) (php_timestamp_fetch_object(Z_OBJ_P(zv)))
# define Z_UNDEFINED_OBJ_P(zv) (php_undefined_fetch_object(Z_OBJ_P(zv)))
# define Z_UTCDATETIME_OBJ_P(zv) (php_utcdatetime_fetch_object(Z_OBJ_P(zv)))
# define Z_COMMANDFAILEDEVENT_OBJ_P(zv) (php_commandfailedevent_fetch_object(Z_OBJ_P(zv)))
# define Z_COMMANDSTARTEDEVENT_OBJ_P(zv) (php_commandstartedevent_fetch_object(Z_OBJ_P(zv)))
Expand All @@ -141,13 +153,16 @@ static inline php_phongo_commandsucceededevent_t* php_commandsucceededevent_fetc
# define Z_OBJ_WRITEERROR(zo) (php_writeerror_fetch_object(zo))
# define Z_OBJ_WRITERESULT(zo) (php_writeresult_fetch_object(zo))
# define Z_OBJ_BINARY(zo) (php_binary_fetch_object(zo))
# define Z_OBJ_DBPOINTER(zo) (php_dbpointer_fetch_object(zo))
# define Z_OBJ_DECIMAL128(zo) (php_decimal128_fetch_object(zo))
# define Z_OBJ_JAVASCRIPT(zo) (php_javascript_fetch_object(zo))
# define Z_OBJ_MAXKEY(zo) (php_maxkey_fetch_object(zo))
# define Z_OBJ_MINKEY(zo) (php_minkey_fetch_object(zo))
# define Z_OBJ_OBJECTID(zo) (php_objectid_fetch_object(zo))
# define Z_OBJ_REGEX(zo) (php_regex_fetch_object(zo))
# define Z_OBJ_SYMBOL(zo) (php_symbol_fetch_object(zo))
# define Z_OBJ_TIMESTAMP(zo) (php_timestamp_fetch_object(zo))
# define Z_OBJ_UNDEFINED(zo) (php_undefined_fetch_object(zo))
# define Z_OBJ_UTCDATETIME(zo) (php_utcdatetime_fetch_object(zo))
# define Z_OBJ_COMMANDFAILEDEVENT(zo) (php_commandfailedevent_fetch_object(zo))
# define Z_OBJ_COMMANDSTARTEDEVENT(zo) (php_commandstartedevent_fetch_object(zo))
Expand All @@ -169,13 +184,16 @@ static inline php_phongo_commandsucceededevent_t* php_commandsucceededevent_fetc
# define Z_WRITEERROR_OBJ_P(zv) ((php_phongo_writeerror_t *)zend_object_store_get_object(zv TSRMLS_CC))
# define Z_WRITERESULT_OBJ_P(zv) ((php_phongo_writeresult_t *)zend_object_store_get_object(zv TSRMLS_CC))
# define Z_BINARY_OBJ_P(zv) ((php_phongo_binary_t *)zend_object_store_get_object(zv TSRMLS_CC))
# define Z_DBPOINTER_OBJ_P(zv) ((php_phongo_dbpointer_t *)zend_object_store_get_object(zv TSRMLS_CC))
# define Z_DECIMAL128_OBJ_P(zv) ((php_phongo_decimal128_t *)zend_object_store_get_object(zv TSRMLS_CC))
# define Z_JAVASCRIPT_OBJ_P(zv) ((php_phongo_javascript_t *)zend_object_store_get_object(zv TSRMLS_CC))
# define Z_MAXKEY_OBJ_P(zv) ((php_phongo_maxkey_t *)zend_object_store_get_object(zv TSRMLS_CC))
# define Z_MINKEY_OBJ_P(zv) ((php_phongo_minkey_t *)zend_object_store_get_object(zv TSRMLS_CC))
# define Z_OBJECTID_OBJ_P(zv) ((php_phongo_objectid_t *)zend_object_store_get_object(zv TSRMLS_CC))
# define Z_REGEX_OBJ_P(zv) ((php_phongo_regex_t *)zend_object_store_get_object(zv TSRMLS_CC))
# define Z_SYMBOL_OBJ_P(zv) ((php_phongo_symbol_t *)zend_object_store_get_object(zv TSRMLS_CC))
# define Z_TIMESTAMP_OBJ_P(zv) ((php_phongo_timestamp_t *)zend_object_store_get_object(zv TSRMLS_CC))
# define Z_UNDEFINED_OBJ_P(zv) ((php_phongo_undefined_t *)zend_object_store_get_object(zv TSRMLS_CC))
# define Z_UTCDATETIME_OBJ_P(zv) ((php_phongo_utcdatetime_t *)zend_object_store_get_object(zv TSRMLS_CC))
# define Z_COMMANDFAILEDEVENT_OBJ_P(zv) ((php_phongo_commandfailedevent_t *)zend_object_store_get_object(zv TSRMLS_CC))
# define Z_COMMANDSTARTEDEVENT_OBJ_P(zv) ((php_phongo_commandstartedevent_t *)zend_object_store_get_object(zv TSRMLS_CC))
Expand All @@ -195,13 +213,16 @@ static inline php_phongo_commandsucceededevent_t* php_commandsucceededevent_fetc
# define Z_OBJ_WRITEERROR(zo) ((php_phongo_writeerror_t *)zo)
# define Z_OBJ_WRITERESULT(zo) ((php_phongo_writeresult_t *)zo)
# define Z_OBJ_BINARY(zo) ((php_phongo_binary_t *)zo)
# define Z_OBJ_DBPOINTER(zo) ((php_phongo_dbpointer_t *)zo)
# define Z_OBJ_DECIMAL128(zo) ((php_phongo_decimal128_t *)zo)
# define Z_OBJ_JAVASCRIPT(zo) ((php_phongo_javascript_t *)zo)
# define Z_OBJ_MAXKEY(zo) ((php_phongo_maxkey_t *)zo)
# define Z_OBJ_MINKEY(zo) ((php_phongo_minkey_t *)zo)
# define Z_OBJ_OBJECTID(zo) ((php_phongo_objectid_t *)zo)
# define Z_OBJ_REGEX(zo) ((php_phongo_regex_t *)zo)
# define Z_OBJ_SYMBOL(zo) ((php_phongo_symbol_t *)zo)
# define Z_OBJ_TIMESTAMP(zo) ((php_phongo_timestamp_t *)zo)
# define Z_OBJ_UNDEFINED(zo) ((php_phongo_undefined_t *)zo)
# define Z_OBJ_UTCDATETIME(zo) ((php_phongo_utcdatetime_t *)zo)
# define Z_OBJ_COMMANDFAILEDEVENT(zo) ((php_phongo_commandfailedevent_t *)zo)
# define Z_OBJ_COMMANDSTARTEDEVENT(zo) ((php_phongo_commandstartedevent_t *)zo)
Expand Down Expand Up @@ -247,13 +268,16 @@ extern zend_class_entry *php_phongo_persistable_ce;
extern zend_class_entry *php_phongo_unserializable_ce;
extern zend_class_entry *php_phongo_serializable_ce;
extern zend_class_entry *php_phongo_binary_ce;
extern zend_class_entry *php_phongo_dbpointer_ce;
extern zend_class_entry *php_phongo_decimal128_ce;
extern zend_class_entry *php_phongo_javascript_ce;
extern zend_class_entry *php_phongo_maxkey_ce;
extern zend_class_entry *php_phongo_minkey_ce;
extern zend_class_entry *php_phongo_objectid_ce;
extern zend_class_entry *php_phongo_regex_ce;
extern zend_class_entry *php_phongo_symbol_ce;
extern zend_class_entry *php_phongo_timestamp_ce;
extern zend_class_entry *php_phongo_undefined_ce;
extern zend_class_entry *php_phongo_utcdatetime_ce;

extern zend_class_entry *php_phongo_binary_interface_ce;
Expand All @@ -273,6 +297,7 @@ extern zend_class_entry *php_phongo_commandsucceededevent_ce;
extern zend_class_entry *php_phongo_subscriber_ce;

extern void php_phongo_binary_init_ce(INIT_FUNC_ARGS);
extern void php_phongo_dbpointer_init_ce(INIT_FUNC_ARGS);
extern void php_phongo_decimal128_init_ce(INIT_FUNC_ARGS);
extern void php_phongo_javascript_init_ce(INIT_FUNC_ARGS);
extern void php_phongo_maxkey_init_ce(INIT_FUNC_ARGS);
Expand All @@ -281,10 +306,12 @@ extern void php_phongo_objectid_init_ce(INIT_FUNC_ARGS);
extern void php_phongo_persistable_init_ce(INIT_FUNC_ARGS);
extern void php_phongo_regex_init_ce(INIT_FUNC_ARGS);
extern void php_phongo_serializable_init_ce(INIT_FUNC_ARGS);
extern void php_phongo_symbol_init_ce(INIT_FUNC_ARGS);
extern void php_phongo_timestamp_init_ce(INIT_FUNC_ARGS);
extern void php_phongo_type_init_ce(INIT_FUNC_ARGS);
extern void php_phongo_utcdatetime_init_ce(INIT_FUNC_ARGS);
extern void php_phongo_undefined_init_ce(INIT_FUNC_ARGS);
extern void php_phongo_unserializable_init_ce(INIT_FUNC_ARGS);
extern void php_phongo_utcdatetime_init_ce(INIT_FUNC_ARGS);

extern void php_phongo_binary_interface_init_ce(INIT_FUNC_ARGS);
extern void php_phongo_decimal128_interface_init_ce(INIT_FUNC_ARGS);
Expand Down
22 changes: 22 additions & 0 deletions php_phongo_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ typedef struct {
PHONGO_ZEND_OBJECT_POST
} php_phongo_binary_t;

typedef struct {
PHONGO_ZEND_OBJECT_PRE
char *ref;
size_t ref_len;
char id[25];
HashTable *properties;
PHONGO_ZEND_OBJECT_POST
} php_phongo_dbpointer_t;

typedef struct {
PHONGO_ZEND_OBJECT_PRE
bool initialized;
Expand Down Expand Up @@ -192,6 +201,14 @@ typedef struct {
PHONGO_ZEND_OBJECT_POST
} php_phongo_regex_t;

typedef struct {
PHONGO_ZEND_OBJECT_PRE
char *symbol;
size_t symbol_len;
HashTable *properties;
PHONGO_ZEND_OBJECT_POST
} php_phongo_symbol_t;

typedef struct {
PHONGO_ZEND_OBJECT_PRE
bool initialized;
Expand All @@ -201,6 +218,11 @@ typedef struct {
PHONGO_ZEND_OBJECT_POST
} php_phongo_timestamp_t;

typedef struct {
PHONGO_ZEND_OBJECT_PRE
PHONGO_ZEND_OBJECT_POST
} php_phongo_undefined_t;

typedef struct {
PHONGO_ZEND_OBJECT_PRE
bool initialized;
Expand Down
Loading