Skip to content

Commit

Permalink
PHPC-2248: Remove Serializable implementations (#1663)
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Sep 19, 2024
1 parent a2c7252 commit 46c6055
Show file tree
Hide file tree
Showing 92 changed files with 130 additions and 2,159 deletions.
8 changes: 4 additions & 4 deletions UPGRADE-2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ UPGRADE FROM 1.x to 2.0
`MongoDB\Driver\Cursor::getId()` and
`MongoDB\Driver\CursorInterface::getId()` now return a `MongoDB\BSON\Int64`
instance.

* The `--with-libbson` and `--with-libmongoc` configure options have been
removed. Use `--with-mongodb-system-libs` instead.

* The `--with-libbson` and `--with-libmongoc` configure options have been
removed. Use `--with-mongodb-system-libs` instead.
* All classes that previously implemented the `Serializable` interface no
longer implement this interface.
58 changes: 1 addition & 57 deletions src/BSON/Binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
*/

#include <php.h>
#include <zend_smart_str.h>
#include <ext/standard/base64.h>
#include <ext/standard/php_var.h>
#include <Zend/zend_interfaces.h>

#include "php_phongo.h"
Expand Down Expand Up @@ -184,60 +182,6 @@ static PHP_METHOD(MongoDB_BSON_Binary, jsonSerialize)
ADD_ASSOC_STRINGL(return_value, "$type", type, type_len);
}

static PHP_METHOD(MongoDB_BSON_Binary, serialize)
{
php_phongo_binary_t* intern;
zval retval;
php_serialize_data_t var_hash;
smart_str buf = { 0 };

intern = Z_BINARY_OBJ_P(getThis());

PHONGO_PARSE_PARAMETERS_NONE();

array_init_size(&retval, 2);
ADD_ASSOC_STRINGL(&retval, "data", intern->data, intern->data_len);
ADD_ASSOC_LONG_EX(&retval, "type", intern->type);

PHP_VAR_SERIALIZE_INIT(var_hash);
php_var_serialize(&buf, &retval, &var_hash);
smart_str_0(&buf);
PHP_VAR_SERIALIZE_DESTROY(var_hash);

PHONGO_RETVAL_SMART_STR(buf);

smart_str_free(&buf);
zval_ptr_dtor(&retval);
}

static PHP_METHOD(MongoDB_BSON_Binary, unserialize)
{
php_phongo_binary_t* intern;
char* serialized;
size_t serialized_len;
zval props;
php_unserialize_data_t var_hash;

intern = Z_BINARY_OBJ_P(getThis());

PHONGO_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STRING(serialized, serialized_len)
PHONGO_PARSE_PARAMETERS_END();

PHP_VAR_UNSERIALIZE_INIT(var_hash);
if (!php_var_unserialize(&props, (const unsigned char**) &serialized, (unsigned char*) serialized + serialized_len, &var_hash)) {
zval_ptr_dtor(&props);
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE, "%s unserialization failed", ZSTR_VAL(php_phongo_binary_ce->name));

PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
return;
}
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);

php_phongo_binary_init_from_hash(intern, HASH_OF(&props));
zval_ptr_dtor(&props);
}

static PHP_METHOD(MongoDB_BSON_Binary, __serialize)
{
PHONGO_PARSE_PARAMETERS_NONE();
Expand Down Expand Up @@ -339,7 +283,7 @@ static HashTable* php_phongo_binary_get_properties(zend_object* object)

void php_phongo_binary_init_ce(INIT_FUNC_ARGS)
{
php_phongo_binary_ce = register_class_MongoDB_BSON_Binary(php_phongo_binary_interface_ce, php_phongo_json_serializable_ce, php_phongo_type_ce, zend_ce_serializable, zend_ce_stringable);
php_phongo_binary_ce = register_class_MongoDB_BSON_Binary(php_phongo_binary_interface_ce, php_phongo_json_serializable_ce, php_phongo_type_ce, zend_ce_stringable);
php_phongo_binary_ce->create_object = php_phongo_binary_create_object;

memcpy(&php_phongo_handler_binary, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
Expand Down
6 changes: 1 addition & 5 deletions src/BSON/Binary.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace MongoDB\BSON;

final class Binary implements BinaryInterface, \JsonSerializable, Type, \Serializable, \Stringable
final class Binary implements BinaryInterface, \JsonSerializable, Type, \Stringable
{
/**
* @var int
Expand Down Expand Up @@ -79,10 +79,6 @@ final public static function __set_state(array $properties): Binary {}

final public function __toString(): string {}

final public function serialize(): string {}

final public function unserialize(string $data): void {}

final public function __unserialize(array $data): void {}

final public function __serialize(): array {}
Expand Down
16 changes: 3 additions & 13 deletions src/BSON/Binary_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 1 addition & 57 deletions src/BSON/DBPointer.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
#include "bson/bson.h"

#include <php.h>
#include <zend_smart_str.h>
#include <ext/standard/php_var.h>
#include <Zend/zend_interfaces.h>

#include "php_phongo.h"
Expand Down Expand Up @@ -147,60 +145,6 @@ static PHP_METHOD(MongoDB_BSON_DBPointer, jsonSerialize)
ADD_ASSOC_ZVAL(return_value, "$dbPointer", &zdb_pointer);
}

static PHP_METHOD(MongoDB_BSON_DBPointer, serialize)
{
php_phongo_dbpointer_t* intern;
zval retval;
php_serialize_data_t var_hash;
smart_str buf = { 0 };

intern = Z_DBPOINTER_OBJ_P(getThis());

PHONGO_PARSE_PARAMETERS_NONE();

array_init_size(&retval, 2);
ADD_ASSOC_STRINGL(&retval, "ref", intern->ref, intern->ref_len);
ADD_ASSOC_STRING(&retval, "id", intern->id);

PHP_VAR_SERIALIZE_INIT(var_hash);
php_var_serialize(&buf, &retval, &var_hash);
smart_str_0(&buf);
PHP_VAR_SERIALIZE_DESTROY(var_hash);

PHONGO_RETVAL_SMART_STR(buf);

smart_str_free(&buf);
zval_ptr_dtor(&retval);
}

static PHP_METHOD(MongoDB_BSON_DBPointer, unserialize)
{
php_phongo_dbpointer_t* intern;
char* serialized;
size_t serialized_len;
zval props;
php_unserialize_data_t var_hash;

intern = Z_DBPOINTER_OBJ_P(getThis());

PHONGO_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STRING(serialized, serialized_len)
PHONGO_PARSE_PARAMETERS_END();

PHP_VAR_UNSERIALIZE_INIT(var_hash);
if (!php_var_unserialize(&props, (const unsigned char**) &serialized, (unsigned char*) serialized + serialized_len, &var_hash)) {
zval_ptr_dtor(&props);
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE, "%s unserialization failed", ZSTR_VAL(php_phongo_dbpointer_ce->name));

PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
return;
}
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);

php_phongo_dbpointer_init_from_hash(intern, HASH_OF(&props));
zval_ptr_dtor(&props);
}

static PHP_METHOD(MongoDB_BSON_DBPointer, __serialize)
{
PHONGO_PARSE_PARAMETERS_NONE();
Expand Down Expand Up @@ -299,7 +243,7 @@ static HashTable* php_phongo_dbpointer_get_properties(zend_object* object)

void php_phongo_dbpointer_init_ce(INIT_FUNC_ARGS)
{
php_phongo_dbpointer_ce = register_class_MongoDB_BSON_DBPointer(php_phongo_json_serializable_ce, php_phongo_type_ce, zend_ce_serializable, zend_ce_stringable);
php_phongo_dbpointer_ce = register_class_MongoDB_BSON_DBPointer(php_phongo_json_serializable_ce, php_phongo_type_ce, zend_ce_stringable);
php_phongo_dbpointer_ce->create_object = php_phongo_dbpointer_create_object;

memcpy(&php_phongo_handler_dbpointer, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
Expand Down
6 changes: 1 addition & 5 deletions src/BSON/DBPointer.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@
*/

namespace MongoDB\BSON;
final class DBPointer implements \JsonSerializable, Type, \Serializable, \Stringable
final class DBPointer implements \JsonSerializable, Type, \Stringable
{
final private function __construct() {}

final public static function __set_state(array $properties): DBPointer {}

final public function __toString(): string {}

final public function serialize(): string {}

final public function unserialize(string $data): void {}

final public function __unserialize(array $data): void {}

final public function __serialize(): array {}
Expand Down
16 changes: 3 additions & 13 deletions src/BSON/DBPointer_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 1 addition & 58 deletions src/BSON/Decimal128.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
#include "bson/bson.h"

#include <php.h>
#include <zend_smart_str.h>
#include <ext/standard/php_var.h>
#include <Zend/zend_interfaces.h>

#include "php_phongo.h"
Expand Down Expand Up @@ -143,61 +141,6 @@ static PHP_METHOD(MongoDB_BSON_Decimal128, jsonSerialize)
ADD_ASSOC_STRING(return_value, "$numberDecimal", outbuf);
}

static PHP_METHOD(MongoDB_BSON_Decimal128, serialize)
{
php_phongo_decimal128_t* intern;
zval retval;
php_serialize_data_t var_hash;
smart_str buf = { 0 };
char outbuf[BSON_DECIMAL128_STRING];

intern = Z_DECIMAL128_OBJ_P(getThis());

PHONGO_PARSE_PARAMETERS_NONE();

bson_decimal128_to_string(&intern->decimal, outbuf);
array_init_size(&retval, 1);
ADD_ASSOC_STRING(&retval, "dec", outbuf);

PHP_VAR_SERIALIZE_INIT(var_hash);
php_var_serialize(&buf, &retval, &var_hash);
smart_str_0(&buf);
PHP_VAR_SERIALIZE_DESTROY(var_hash);

PHONGO_RETVAL_SMART_STR(buf);

smart_str_free(&buf);
zval_ptr_dtor(&retval);
}

static PHP_METHOD(MongoDB_BSON_Decimal128, unserialize)
{
php_phongo_decimal128_t* intern;
char* serialized;
size_t serialized_len;
zval props;
php_unserialize_data_t var_hash;

intern = Z_DECIMAL128_OBJ_P(getThis());

PHONGO_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STRING(serialized, serialized_len)
PHONGO_PARSE_PARAMETERS_END();

PHP_VAR_UNSERIALIZE_INIT(var_hash);
if (!php_var_unserialize(&props, (const unsigned char**) &serialized, (unsigned char*) serialized + serialized_len, &var_hash)) {
zval_ptr_dtor(&props);
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE, "%s unserialization failed", ZSTR_VAL(php_phongo_decimal128_ce->name));

PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
return;
}
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);

php_phongo_decimal128_init_from_hash(intern, HASH_OF(&props));
zval_ptr_dtor(&props);
}

static PHP_METHOD(MongoDB_BSON_Decimal128, __serialize)
{
PHONGO_PARSE_PARAMETERS_NONE();
Expand Down Expand Up @@ -275,7 +218,7 @@ static HashTable* php_phongo_decimal128_get_properties(zend_object* object)

void php_phongo_decimal128_init_ce(INIT_FUNC_ARGS)
{
php_phongo_decimal128_ce = register_class_MongoDB_BSON_Decimal128(php_phongo_decimal128_interface_ce, php_phongo_json_serializable_ce, php_phongo_type_ce, zend_ce_serializable, zend_ce_stringable);
php_phongo_decimal128_ce = register_class_MongoDB_BSON_Decimal128(php_phongo_decimal128_interface_ce, php_phongo_json_serializable_ce, php_phongo_type_ce, zend_ce_stringable);
php_phongo_decimal128_ce->create_object = php_phongo_decimal128_create_object;

memcpy(&php_phongo_handler_decimal128, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
Expand Down
Loading

0 comments on commit 46c6055

Please sign in to comment.