PHPC-2242, PHPC-2243, PHPC-2244: BSON class improvements #1435
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PHPC-2242
PHPC-2243
PHPC-2244
This PR cleans up the BSON class handling a bit. While working with the changes committed in #1412, I noticed that wrapping BSON values in
MongoDB\BSON\Value
instances was cumbersome and no longer necessary after changing the way int64 values are handled in raw BSON. To summarise, we decided thatMongoDB\BSON\Value::getValue()
would always return anInt64
instance, even when the value would fit within a platform-sized integer. That removed the main incentive for theMongoDB\BSON\Value
class, as we originally planned to use it to differentiate between 32-bit and 64-bit integers when the value was within the 32-bit range.With that in mind, this PR undoes some of the changes introduced in the pull request. The main change is that
Document::get
,PackedArray::get
, andIterator::current
now returnInt64
instances whenever a BSON long is encountered. For one, the raw BSON classes are designed to interact with BSON structures, so returning BSON values that can't be represented as PHP scalars as BSON class instances makes sense. Furthermore, with the recent changes to theInt64
class (see #1417), instances of that class can be used like numbers in arithmetic operations and cast to integer if a user wishes to do so.This change also applies to
Document::toPHP
andPackedArray::toPHP
, which return BSON long values asInt64
instances. The already existingMongoDB\BSON\toPHP
function retains its current behaviour, as do any other instances of where we convert BSON data to PHP. The new behaviour only applies when interacting with the new BSONDocument
andPackedArray
classes.Last but not least, the
MongoDB\BSON\Value
class was dropped without a replacement. The improvements and refactoring made during the creation of the class remain in place.