Skip to content

PHPC-761: Remove BSON_NAMESPACE constant #369

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 3 commits into from
Aug 5, 2016
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
7 changes: 0 additions & 7 deletions php_bson.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@
/* PHP Core stuff */
#include <php.h>

/* Check if we are part of pecl/mongodb or standalone (pecl/bson) */
#ifdef HAVE_MONGOC
#define BSON_NAMESPACE "MongoDB\\BSON"
#else
#define BSON_NAMESPACE "BSON"
#endif

#define BSON_UNSERIALIZE_FUNC_NAME "bsonUnserialize"
#define BSON_SERIALIZE_FUNC_NAME "bsonSerialize"

Expand Down
9 changes: 4 additions & 5 deletions php_phongo.c
Original file line number Diff line number Diff line change
Expand Up @@ -2507,7 +2507,6 @@ PHP_MINIT_FUNCTION(mongodb)

REGISTER_STRING_CONSTANT("MONGODB_VERSION", (char *)MONGODB_VERSION_S, CONST_CS | CONST_PERSISTENT);
REGISTER_STRING_CONSTANT("MONGODB_STABILITY", (char *)MONGODB_STABILITY_S, CONST_CS | CONST_PERSISTENT);
REGISTER_STRING_CONSTANT("BSON_NAMESPACE", (char *)BSON_NAMESPACE, CONST_CS | CONST_PERSISTENT);

return SUCCESS;
}
Expand Down Expand Up @@ -2586,10 +2585,10 @@ ZEND_BEGIN_ARG_INFO_EX(ai_bson_fromJSON, 0, 0, 1)
ZEND_END_ARG_INFO();

const zend_function_entry mongodb_functions[] = {
ZEND_NS_FE(BSON_NAMESPACE, fromPHP, ai_bson_fromPHP)
ZEND_NS_FE(BSON_NAMESPACE, toPHP, ai_bson_toPHP)
ZEND_NS_FE(BSON_NAMESPACE, toJSON, ai_bson_toJSON)
ZEND_NS_FE(BSON_NAMESPACE, fromJSON, ai_bson_fromJSON)
ZEND_NS_FE("MongoDB\\BSON", fromPHP, ai_bson_fromPHP)
ZEND_NS_FE("MongoDB\\BSON", toPHP, ai_bson_toPHP)
ZEND_NS_FE("MongoDB\\BSON", toJSON, ai_bson_toJSON)
ZEND_NS_FE("MongoDB\\BSON", fromJSON, ai_bson_fromJSON)
PHP_FE_END
};
/* }}} */
Expand Down
2 changes: 1 addition & 1 deletion src/BSON/Binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ PHP_MINIT_FUNCTION(Binary)
zend_class_entry ce;
(void)type;(void)module_number;

INIT_NS_CLASS_ENTRY(ce, BSON_NAMESPACE, "Binary", php_phongo_binary_me);
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "Binary", php_phongo_binary_me);
php_phongo_binary_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_binary_ce->create_object = php_phongo_binary_create_object;
PHONGO_CE_FINAL(php_phongo_binary_ce);
Expand Down
2 changes: 1 addition & 1 deletion src/BSON/Decimal128.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ PHP_MINIT_FUNCTION(Decimal128)
zend_class_entry ce;
(void)type;(void)module_number;

INIT_NS_CLASS_ENTRY(ce, BSON_NAMESPACE, "Decimal128", php_phongo_decimal128_me);
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "Decimal128", php_phongo_decimal128_me);
php_phongo_decimal128_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_decimal128_ce->create_object = php_phongo_decimal128_create_object;
PHONGO_CE_FINAL(php_phongo_decimal128_ce);
Expand Down
2 changes: 1 addition & 1 deletion src/BSON/Javascript.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ PHP_MINIT_FUNCTION(Javascript)
(void)type;(void)module_number;


INIT_NS_CLASS_ENTRY(ce, BSON_NAMESPACE, "Javascript", php_phongo_javascript_me);
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "Javascript", php_phongo_javascript_me);
php_phongo_javascript_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_javascript_ce->create_object = php_phongo_javascript_create_object;
PHONGO_CE_FINAL(php_phongo_javascript_ce);
Expand Down
2 changes: 1 addition & 1 deletion src/BSON/MaxKey.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ PHP_MINIT_FUNCTION(MaxKey)
(void)type;(void)module_number;


INIT_NS_CLASS_ENTRY(ce, BSON_NAMESPACE, "MaxKey", php_phongo_maxkey_me);
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "MaxKey", php_phongo_maxkey_me);
php_phongo_maxkey_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_maxkey_ce->create_object = php_phongo_maxkey_create_object;
PHONGO_CE_FINAL(php_phongo_maxkey_ce);
Expand Down
2 changes: 1 addition & 1 deletion src/BSON/MinKey.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ PHP_MINIT_FUNCTION(MinKey)
(void)type;(void)module_number;


INIT_NS_CLASS_ENTRY(ce, BSON_NAMESPACE, "MinKey", php_phongo_minkey_me);
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "MinKey", php_phongo_minkey_me);
php_phongo_minkey_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_minkey_ce->create_object = php_phongo_minkey_create_object;
PHONGO_CE_FINAL(php_phongo_minkey_ce);
Expand Down
2 changes: 1 addition & 1 deletion src/BSON/ObjectID.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ PHP_MINIT_FUNCTION(ObjectID)
zend_class_entry ce;
(void)type;(void)module_number;

INIT_NS_CLASS_ENTRY(ce, BSON_NAMESPACE, "ObjectID", php_phongo_objectid_me);
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "ObjectID", php_phongo_objectid_me);
php_phongo_objectid_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_objectid_ce->create_object = php_phongo_objectid_create_object;
PHONGO_CE_FINAL(php_phongo_objectid_ce);
Expand Down
2 changes: 1 addition & 1 deletion src/BSON/Persistable.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ PHP_MINIT_FUNCTION(Persistable)
zend_class_entry ce;
(void)type;(void)module_number;

INIT_NS_CLASS_ENTRY(ce, BSON_NAMESPACE, "Persistable", php_phongo_persistable_me);
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "Persistable", php_phongo_persistable_me);
php_phongo_persistable_ce = zend_register_internal_interface(&ce TSRMLS_CC);
zend_class_implements(php_phongo_persistable_ce TSRMLS_CC, 2, php_phongo_unserializable_ce, php_phongo_serializable_ce);

Expand Down
2 changes: 1 addition & 1 deletion src/BSON/Regex.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ PHP_MINIT_FUNCTION(Regex)
zend_class_entry ce;
(void)type;(void)module_number;

INIT_NS_CLASS_ENTRY(ce, BSON_NAMESPACE, "Regex", php_phongo_regex_me);
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "Regex", php_phongo_regex_me);
php_phongo_regex_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_regex_ce->create_object = php_phongo_regex_create_object;
PHONGO_CE_FINAL(php_phongo_regex_ce);
Expand Down
2 changes: 1 addition & 1 deletion src/BSON/Serializable.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ PHP_MINIT_FUNCTION(Serializable)
zend_class_entry ce;
(void)type;(void)module_number;

INIT_NS_CLASS_ENTRY(ce, BSON_NAMESPACE, "Serializable", php_phongo_serializable_me);
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "Serializable", php_phongo_serializable_me);
php_phongo_serializable_ce = zend_register_internal_interface(&ce TSRMLS_CC);
zend_class_implements(php_phongo_serializable_ce TSRMLS_CC, 1, php_phongo_type_ce);

Expand Down
2 changes: 1 addition & 1 deletion src/BSON/Timestamp.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ PHP_MINIT_FUNCTION(Timestamp)
zend_class_entry ce;
(void)type;(void)module_number;

INIT_NS_CLASS_ENTRY(ce, BSON_NAMESPACE, "Timestamp", php_phongo_timestamp_me);
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "Timestamp", php_phongo_timestamp_me);
php_phongo_timestamp_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_timestamp_ce->create_object = php_phongo_timestamp_create_object;
PHONGO_CE_FINAL(php_phongo_timestamp_ce);
Expand Down
2 changes: 1 addition & 1 deletion src/BSON/Type.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ PHP_MINIT_FUNCTION(Type)
zend_class_entry ce;
(void)type;(void)module_number;

INIT_NS_CLASS_ENTRY(ce, BSON_NAMESPACE, "Type", php_phongo_type_me);
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "Type", php_phongo_type_me);
php_phongo_type_ce = zend_register_internal_interface(&ce TSRMLS_CC);

return SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion src/BSON/UTCDateTime.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ PHP_MINIT_FUNCTION(UTCDateTime)
zend_class_entry ce;
(void)type;(void)module_number;

INIT_NS_CLASS_ENTRY(ce, BSON_NAMESPACE, "UTCDateTime", php_phongo_utcdatetime_me);
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "UTCDateTime", php_phongo_utcdatetime_me);
php_phongo_utcdatetime_ce = zend_register_internal_class(&ce TSRMLS_CC);
php_phongo_utcdatetime_ce->create_object = php_phongo_utcdatetime_create_object;
PHONGO_CE_FINAL(php_phongo_utcdatetime_ce);
Expand Down
2 changes: 1 addition & 1 deletion src/BSON/Unserializable.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ PHP_MINIT_FUNCTION(Unserializable)
zend_class_entry ce;
(void)type;(void)module_number;

INIT_NS_CLASS_ENTRY(ce, BSON_NAMESPACE, "Unserializable", php_phongo_unserializable_me);
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\BSON", "Unserializable", php_phongo_unserializable_me);
php_phongo_unserializable_ce = zend_register_internal_interface(&ce TSRMLS_CC);

return SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion src/bson.c
Original file line number Diff line number Diff line change
Expand Up @@ -1552,7 +1552,7 @@ static void apply_classname_to_state(const char *classname, int classname_len, p
} else if (!PHONGO_IS_CLASS_INSTANTIATABLE(found_ce)) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Class %s is not instantiatable", classname);
} else if (!instanceof_function(found_ce, php_phongo_unserializable_ce TSRMLS_CC)) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Class %s does not implement %s\\Unserializable", classname, BSON_NAMESPACE);
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Class %s does not implement %s", classname, ZSTR_VAL(php_phongo_unserializable_ce->name));
} else {
*type = PHONGO_TYPEMAP_CLASS;
*type_ce = found_ce;
Expand Down
22 changes: 10 additions & 12 deletions tests/bson/bson-binary-001.phpt
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
--TEST--
BSON BSON\Binary #001
MongoDB\BSON\Binary #001
--FILE--
<?php

require_once __DIR__ . '/../utils/tools.php';

$classname = BSON_NAMESPACE . "\\Binary";

$types = array(
$classname::TYPE_GENERIC,
$classname::TYPE_FUNCTION,
$classname::TYPE_OLD_BINARY,
$classname::TYPE_OLD_UUID,
$classname::TYPE_UUID,
$classname::TYPE_MD5,
$classname::TYPE_USER_DEFINED,
$classname::TYPE_USER_DEFINED+5,
MongoDB\BSON\Binary::TYPE_GENERIC,
MongoDB\BSON\Binary::TYPE_FUNCTION,
MongoDB\BSON\Binary::TYPE_OLD_BINARY,
MongoDB\BSON\Binary::TYPE_OLD_UUID,
MongoDB\BSON\Binary::TYPE_UUID,
MongoDB\BSON\Binary::TYPE_MD5,
MongoDB\BSON\Binary::TYPE_USER_DEFINED,
MongoDB\BSON\Binary::TYPE_USER_DEFINED+5,
);
$tests = array();
foreach($types as $type) {
$binary = new $classname("random binary data", $type);
$binary = new MongoDB\BSON\Binary("random binary data", $type);
var_dump($binary->getData() == "random binary data");
var_dump($binary->getType() == $type);
$tests[] = array("binary" => $binary);
Expand Down
14 changes: 6 additions & 8 deletions tests/bson/bson-binary_error-001.phpt
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
--TEST--
BSON BSON\Binary #001 error
MongoDB\BSON\Binary #001 error
--SKIPIF--
<?php if (defined("HHVM_VERSION_ID")) exit("skip HHVM handles parameter parsing differently"); ?>
--FILE--
<?php

require_once __DIR__ . '/../utils/tools.php';

$classname = BSON_NAMESPACE . "\\Binary";

$binary = new $classname("random binary data", $classname::TYPE_GENERIC);
$binary = new MongoDB\BSON\Binary("random binary data", MongoDB\BSON\Binary::TYPE_GENERIC);
$binary->getData(2);
$binary->getType(2);

throws(function() use($classname) {
new $classname("random binary data without type");
throws(function() {
new MongoDB\BSON\Binary("random binary data without type");
}, "MongoDB\\Driver\\Exception\\InvalidArgumentException");

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
Warning: %s\Binary::getData() expects exactly 0 parameters, 1 given in %s on line %d
Warning: MongoDB\BSON\Binary::getData() expects exactly 0 parameters, 1 given in %s on line %d

Warning: %s\Binary::getType() expects exactly 0 parameters, 1 given in %s on line %d
Warning: MongoDB\BSON\Binary::getType() expects exactly 0 parameters, 1 given in %s on line %d
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
===DONE===

8 changes: 3 additions & 5 deletions tests/bson/bson-binary_error-002.phpt
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
--TEST--
BSON BSON\Binary cannot be extended
MongoDB\BSON\Binary cannot be extended
--FILE--
<?php

use MongoDB\BSON as BSON;

class MyBinary extends BSON\Binary {}
class MyBinary extends MongoDB\BSON\Binary {}

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
Fatal error: Class MyBinary may not inherit from final class (%SBSON\Binary) in %s on line %d
Fatal error: Class MyBinary may not inherit from final class (MongoDB\BSON\Binary) in %s on line %d
8 changes: 3 additions & 5 deletions tests/bson/bson-binary_error-003.phpt
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
--TEST--
BSON BSON\Binary constructor requires unsigned 8-bit integer for type
MongoDB\BSON\Binary constructor requires unsigned 8-bit integer for type
--FILE--
<?php

require_once __DIR__ . '/../utils/tools.php';

use MongoDB\BSON as BSON;

echo throws(function() {
new BSON\Binary('foo', -1);
new MongoDB\BSON\Binary('foo', -1);
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";

echo throws(function() {
new BSON\Binary('foo', 256);
new MongoDB\BSON\Binary('foo', 256);
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";

?>
Expand Down
2 changes: 1 addition & 1 deletion tests/bson/bson-decimal128-001.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
BSON\Decimal128
MongoDB\BSON\Decimal128
--SKIPIF--
<?php if (!class_exists('MongoDB\BSON\Decimal128')) { die('skip MongoDB\BSON\Decimal128 is not available'); } ?>
--FILE--
Expand Down
2 changes: 1 addition & 1 deletion tests/bson/bson-decimal128-002.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
BSON\Decimal128 NaN values
MongoDB\BSON\Decimal128 NaN values
--SKIPIF--
<?php if (!class_exists('MongoDB\BSON\Decimal128')) { die('skip MongoDB\BSON\Decimal128 is not available'); } ?>
--FILE--
Expand Down
2 changes: 1 addition & 1 deletion tests/bson/bson-decimal128-003.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
BSON\Decimal128 Infinity values
MongoDB\BSON\Decimal128 Infinity values
--SKIPIF--
<?php if (!class_exists('MongoDB\BSON\Decimal128')) { die('skip MongoDB\BSON\Decimal128 is not available'); } ?>
--FILE--
Expand Down
2 changes: 1 addition & 1 deletion tests/bson/bson-decimal128-004.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
BSON\Decimal128 debug handler
MongoDB\BSON\Decimal128 debug handler
--SKIPIF--
<?php if (!class_exists('MongoDB\BSON\Decimal128')) { die('skip MongoDB\BSON\Decimal128 is not available'); } ?>
--FILE--
Expand Down
3 changes: 1 addition & 2 deletions tests/bson/bson-decode-002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
BSON encoding: Encoding object/arrays data into user specificied classes
--FILE--
<?php
use MongoDB\BSON as BSON;

require_once __DIR__ . '/../utils/tools.php';

class MyArrayObject extends ArrayObject implements BSON\Unserializable {
class MyArrayObject extends ArrayObject implements MongoDB\BSON\Unserializable {
function bsonUnserialize(array $data) {
parent::__construct($data);
}
Expand Down
1 change: 0 additions & 1 deletion tests/bson/bson-encode-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
BSON encoding: Encoding data into BSON representation, and BSON into Extended JSON
--FILE--
<?php
use MongoDB\BSON as BSON;

require_once __DIR__ . '/../utils/tools.php';

Expand Down
5 changes: 2 additions & 3 deletions tests/bson/bson-encode-002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
BSON encoding: Encoding objects into BSON representation
--FILE--
<?php
use MongoDB\BSON as BSON;

require_once __DIR__ . '/../utils/tools.php';

class AssociativeArray implements BSON\Serializable, BSON\Unserializable
class AssociativeArray implements MongoDB\BSON\Serializable, MongoDB\BSON\Unserializable
{
public function bsonSerialize()
{
Expand All @@ -20,7 +19,7 @@ class AssociativeArray implements BSON\Serializable, BSON\Unserializable
}
}

class NumericArray implements BSON\Serializable, BSON\Unserializable
class NumericArray implements MongoDB\BSON\Serializable, MongoDB\BSON\Unserializable
{
public function bsonSerialize()
{
Expand Down
Loading