1
- ===================
2
- Persistable classes
3
- ===================
1
+ ==================
2
+ Modeling BSON Data
3
+ ==================
4
4
5
5
.. default-domain:: mongodb
6
6
@@ -11,6 +11,45 @@ Persistable classes
11
11
:class: singlecol
12
12
13
13
14
+ Type Maps
15
+ ---------
16
+
17
+ Most methods that read data from MongoDB support a ``typeMap`` option, which
18
+ allows control over how BSON is converted to PHP. Additionally,
19
+ the :phpclass:`MongoDB\\Client`, :phpclass:`MongoDB\\Database`, and
20
+ :phpclass:`MongoDB\\Collection` classes accept a ``typeMap`` option, which can
21
+ be used to specify a default type map to apply to any supporting methods and
22
+ selected classes (e.g. :phpmethod:`MongoDB\\Client::selectDatabase()`).
23
+
24
+ The :phpclass:`MongoDB\\Client`, :phpclass:`MongoDB\\Database`, and
25
+ :phpclass:`MongoDB\\Collection` classes use the following type map by
26
+ default:
27
+
28
+ .. code-block:: php
29
+
30
+ [
31
+ 'array' => 'MongoDB\Model\BSONArray',
32
+ 'document' => 'MongoDB\Model\BSONDocument',
33
+ 'root' => 'MongoDB\Model\BSONDocument',
34
+ ]
35
+
36
+ The type map above will convert BSON documents and arrays to
37
+ :phpclass:`MongoDB\\Model\\BSONDocument` and
38
+ :phpclass:`MongoDB\\Model\\BSONArray` objects, respectively. The ``root`` and
39
+ ``document`` keys are used to distinguish the top-level BSON document from
40
+ embedded documents, respectively.
41
+
42
+ A type map may specify any class that implements
43
+ :php:`MongoDB\\BSON\\Unserializable <mongodb-bson-unserializable>` as well as
44
+ ``"array"``, ``"stdClass``", and ``"object"`` (``"stdClass``" and ``"object"``
45
+ are aliases of one another).
46
+
47
+ .. seealso:: :php:`Deserialization from BSON <manual/en/mongodb.persistence.deserialization.php>` in the PHP manual
48
+
49
+
50
+ Persistable Classes
51
+ -------------------
52
+
14
53
The driver's :php:`persistence specification <mongodb.persistence>` outlines how
15
54
classes implementing its :php:`MongoDB\\BSON\\Persistable
16
55
<mongodb-bson-persistable>` interface are serialized to and deserialized from
@@ -117,38 +156,3 @@ The same document in the MongoDB shell might display as:
117
156
:php:`MongoDB\\BSON\\Persistable <mongodb-bson-persistable>` may only be used
118
157
for root and embedded BSON documents. It may not be used for BSON arrays.
119
158
.. _php-type-map:
120
-
121
- Type Maps
122
- ---------
123
-
124
- Most methods that read data from MongoDB support a ``typeMap`` option, which
125
- allows control over how BSON is converted to PHP. Additionally,
126
- the :phpclass:`MongoDB\\Client`, :phpclass:`MongoDB\\Database`, and
127
- :phpclass:`MongoDB\\Collection` classes accept a ``typeMap`` option, which can
128
- be used to specify a default type map to apply to any supporting methods and
129
- selected classes (e.g. :phpmethod:`MongoDB\\Client::selectDatabase()`).
130
-
131
- The :phpclass:`MongoDB\\Client`, :phpclass:`MongoDB\\Database`, and
132
- :phpclass:`MongoDB\\Collection` classes use the following type map by
133
- default:
134
-
135
- .. code-block:: php
136
-
137
- [
138
- 'array' => 'MongoDB\Model\BSONArray',
139
- 'document' => 'MongoDB\Model\BSONDocument',
140
- 'root' => 'MongoDB\Model\BSONDocument',
141
- ]
142
-
143
- The type map above will convert BSON documents and arrays to
144
- :phpclass:`MongoDB\\Model\\BSONDocument` and
145
- :phpclass:`MongoDB\\Model\\BSONArray` objects, respectively. The ``root`` and
146
- ``document`` keys are used to distinguish the top-level BSON document from
147
- embedded documents, respectively.
148
-
149
- A type map may specify any class that implements
150
- :php:`MongoDB\\BSON\\Unserializable <mongodb-bson-unserializable>` as well as
151
- ``"array"``, ``"stdClass``", and ``"object"`` (``"stdClass``" and ``"object"``
152
- are aliases of one another).
153
-
154
- .. seealso:: :php:`Deserialization from BSON <manual/en/mongodb.persistence.deserialization.php>` in the PHP manual
0 commit comments