File tree Expand file tree Collapse file tree 3 files changed +9
-8
lines changed Expand file tree Collapse file tree 3 files changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ public function __construct(string $name)
16
16
$ this ->createdAt = new MongoDB \BSON \UTCDateTime ;
17
17
}
18
18
19
- function bsonSerialize ()
19
+ public function bsonSerialize (): array
20
20
{
21
21
return [
22
22
'_id ' => $ this ->id ,
@@ -25,7 +25,7 @@ function bsonSerialize()
25
25
];
26
26
}
27
27
28
- function bsonUnserialize (array $ data )
28
+ public function bsonUnserialize (array $ data ): void
29
29
{
30
30
$ this ->id = $ data ['_id ' ];
31
31
$ this ->name = $ data ['name ' ];
Original file line number Diff line number Diff line change @@ -9,7 +9,8 @@ public function __construct(
9
9
private string $ username ,
10
10
private Role $ role ,
11
11
private MongoDB \BSON \ObjectId $ _id = new MongoDB \BSON \ObjectId (),
12
- ) {}
12
+ ) {
13
+ }
13
14
14
15
public function bsonSerialize (): array
15
16
{
Original file line number Diff line number Diff line change 3
3
require 'vendor/autoload.php ' ;
4
4
5
5
use Bson \Person ;
6
- use Bson \User ;
7
6
use Bson \Role ;
7
+ use Bson \User ;
8
8
9
9
$ uri = getenv ('MONGODB_URI ' ) ?: throw new RuntimeException ('Set the MONGODB_URI variable to your Atlas URI that connects to the sample dataset ' );
10
10
$ client = new MongoDB \Client ($ uri );
14
14
$ document = [
15
15
'address ' => [
16
16
'street ' => 'Pizza St ' ,
17
- 'zipcode ' => '10003 '
17
+ 'zipcode ' => '10003 ' ,
18
18
],
19
19
'coord ' => [-73.982419 , 41.579505 ],
20
20
'cuisine ' => 'Pizza ' ,
21
- 'name ' => 'Planet Pizza '
21
+ 'name ' => 'Planet Pizza ' ,
22
22
];
23
23
// end-create-doc
24
24
31
31
$ options = [
32
32
'typeMap ' => [
33
33
'array ' => 'MongoDB\Model\BSONDocument ' ,
34
- 'root ' => 'MongoDB\Model\BSONDocument ' ,
34
+ 'root ' => 'MongoDB\Model\BSONDocument ' ,
35
35
'document ' => 'MongoDB\Model\BSONDocument ' ,
36
36
],
37
37
];
53
53
$ person = $ collection ->findOne (['_id ' => $ result ->getInsertedId ()]);
54
54
55
55
var_dump ($ person );
56
- // end-enum-serialize
56
+ // end-enum-serialize
You can’t perform that action at this time.
0 commit comments