Skip to content

Commit 30f722e

Browse files
committed
Merge branch 'v1.5'
2 parents 17aae96 + 09116d5 commit 30f722e

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

docs/upgrade.txt

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,88 @@ implements the `mongo extension <http://php.net/mongo>`_ API using this library
2424
and the new driver. While this adapter library is not officially supported by
2525
MongoDB, it does bear mentioning.
2626

27+
BSON Type Classes
28+
-----------------
29+
30+
When upgrading from the legacy driver,
31+
`type classes <https://www.php.net/manual/en/mongo.types.php>`_ such as
32+
:php:`MongoId <mongoid>` must be replaced with classes in the
33+
`MongoDB\\BSON namespace <https://www.php.net/manual/en/book.bson.php>`_. The
34+
new driver also introduces interfaces for its BSON types, which should be
35+
preferred if applications need to type hint against BSON values.
36+
37+
The following table lists all legacy classes alongside the equivalent class in
38+
the new driver.
39+
40+
.. list-table::
41+
:header-rows: 1
42+
43+
* - Legacy class
44+
- BSON type class
45+
- BSON type interface
46+
47+
* - :php:`MongoId <mongoid>`
48+
- :php:`MongoDB\\BSON\\ObjectId <mongodb_bson_objectid>`
49+
- :php:`MongoDB\\BSON\\ObjectIdInterface <mongodb_bson_objectidinterface>`
50+
51+
* - :php:`MongoCode <mongocode>`
52+
- :php:`MongoDB\\BSON\\Javascript <mongodb_bson_javascript>`
53+
- :php:`MongoDB\\BSON\\JavascriptInterface <mongodb_bson_javascriptinterface>`
54+
55+
* - :php:`MongoDate <mongodate>`
56+
- :php:`MongoDB\\BSON\\UTCDateTime <mongodb_bson_utcdatetime>`
57+
- :php:`MongoDB\\BSON\\UTCDateTimeInterface <mongodb_bson_utcdatetimeinterface>`
58+
59+
* - :php:`MongoRegex <mongoregex>`
60+
- :php:`MongoDB\\BSON\\Regex <mongodb_bson_regex>`
61+
- :php:`MongoDB\\BSON\\RegexInterface <mongodb_bson_regexinterface>`
62+
63+
* - :php:`MongoBinData <mongobindata>`
64+
- :php:`MongoDB\\BSON\\Binary <mongodb_bson_binary>`
65+
- :php:`MongoDB\\BSON\\BinaryInterface <mongodb_bson_binaryinterface>`
66+
67+
* - :php:`MongoInt32 <mongoint32>`
68+
- Not implemented. [1]_
69+
-
70+
71+
* - :php:`MongoInt64 <mongoint64>`
72+
- :php:`MongoDB\\BSON\\Int64 <mongodb_bson_int64>`
73+
- Not implemented. [2]_
74+
75+
* - :php:`MongoDBRef <mongodbref>`
76+
- Not implemented. [3]_
77+
-
78+
79+
* - :php:`MongoMinKey <mongominkey>`
80+
- :php:`MongoDB\\BSON\\MinKey <mongodb_bson_minkey>`
81+
- :php:`MongoDB\\BSON\\MinKeyInterface <mongodb_bson_minkeyinterface>`
82+
83+
* - :php:`MongoMaxKey <mongomaxkey>`
84+
- :php:`MongoDB\\BSON\\MaxKey <mongodb_bson_maxkey>`
85+
- :php:`MongoDB\\BSON\\MaxKeyInterface <mongodb_bson_maxkeyinterface>`
86+
87+
* - :php:`MongoTimestamp <mongotimestamp>`
88+
- :php:`MongoDB\\BSON\\Timestamp <mongodb_bson_timestamp>`
89+
- :php:`MongoDB\\BSON\\TimestampInterface <mongodb_bson_timestampinterface>`
90+
91+
.. [1] The new driver does not implement an equivalent class for
92+
:php:`MongoInt32 <mongoint32>`. When decoding BSON, 32-bit integers will
93+
always be represented as a PHP integer. When encoding BSON, PHP integers will
94+
encode as either a 32-bit or 64-bit integer depending on their value.
95+
96+
.. [2] :php:`MongoDB\\BSON\\Int64 <mongodb_bson_int64>` does not have an
97+
interface defined. The new driver does not allow applications to instantiate
98+
this type (i.e. its constructor is private) and it is only created during
99+
BSON decoding when a 64-bit integer cannot be represented as a PHP integer on
100+
a 32-bit platform.
101+
102+
.. [3] The new driver does not implement an equivalent class for
103+
:php:`MongoDBRef <mongodbref>` since
104+
:manual:`DBRefs </reference/database-references>` are merely a BSON document
105+
with a particular structure and not a proper BSON type. The new driver also
106+
does not provide any helpers for working with DBRef objects, since their use
107+
is not encouraged.
108+
27109
Collection API
28110
--------------
29111

tests/SpecTests/ErrorExpectation.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ public static function fromChangeStreams(stdClass $result)
7575
return $o;
7676
}
7777

78+
public static function fromCrud(stdClass $result)
79+
{
80+
$o = new self();
81+
82+
if (isset($result->error)) {
83+
$o->isExpected = $result->error;
84+
}
85+
86+
return $o;
87+
}
88+
7889
public static function fromRetryableReads(stdClass $operation)
7990
{
8091
$o = new self();

tests/SpecTests/Operation.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ public static function fromCrud(stdClass $operation)
158158
{
159159
$o = new self($operation);
160160

161+
$o->errorExpectation = ErrorExpectation::fromCrud($operation);
161162
$o->resultExpectation = ResultExpectation::fromCrud($operation, $o->getResultAssertionType());
162163

163164
if (isset($operation->collectionOptions)) {

0 commit comments

Comments
 (0)