|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Doctrine\ODM\MongoDB\Benchmark\Document; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\ODM\MongoDB\Benchmark\BaseBench; |
|
8
|
|
|
use Doctrine\ODM\MongoDB\Hydrator\HydratorInterface; |
|
9
|
|
|
use Documents\User; |
|
10
|
|
|
use MongoDB\BSON\ObjectId; |
|
11
|
|
|
use MongoDB\BSON\UTCDateTime; |
|
12
|
|
|
use PhpBench\Benchmark\Metadata\Annotations\BeforeMethods; |
|
13
|
|
|
use PhpBench\Benchmark\Metadata\Annotations\Warmup; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @BeforeMethods({"init"}, extend=true) |
|
17
|
|
|
*/ |
|
18
|
|
|
final class HydrateDocumentBench extends BaseBench |
|
19
|
|
|
{ |
|
20
|
|
|
/** @var array */ |
|
21
|
|
|
private static $data; |
|
22
|
|
|
|
|
23
|
|
|
/** @var array */ |
|
24
|
|
|
private static $embedOneData; |
|
25
|
|
|
|
|
26
|
|
|
/** @var array */ |
|
27
|
|
|
private static $embedManyData; |
|
28
|
|
|
|
|
29
|
|
|
/** @var array */ |
|
30
|
|
|
private static $referenceOneData; |
|
31
|
|
|
|
|
32
|
|
|
/** @var array */ |
|
33
|
|
|
private static $referenceManyData; |
|
34
|
|
|
|
|
35
|
|
|
/** @var HydratorInterface */ |
|
36
|
|
|
private static $hydrator; |
|
37
|
|
|
|
|
38
|
|
|
public function init() |
|
39
|
|
|
{ |
|
40
|
|
|
self::$data = [ |
|
41
|
|
|
'_id' => new ObjectId(), |
|
42
|
|
|
'username' => 'alcaeus', |
|
43
|
|
|
'createdAt' => new UTCDateTime(), |
|
44
|
|
|
]; |
|
45
|
|
|
|
|
46
|
|
|
self::$embedOneData = [ |
|
47
|
|
|
'address' => ['city' => 'Munich'], |
|
48
|
|
|
]; |
|
49
|
|
|
|
|
50
|
|
|
self::$embedManyData = [ |
|
51
|
|
|
'phonenumbers' => [ |
|
52
|
|
|
['phonenumber' => '12345678'], |
|
53
|
|
|
['phonenumber' => '12345678'], |
|
54
|
|
|
], |
|
55
|
|
|
]; |
|
56
|
|
|
|
|
57
|
|
|
self::$referenceOneData = [ |
|
58
|
|
|
'account' => [ |
|
59
|
|
|
'$ref' => 'Account', |
|
60
|
|
|
'$id' => new ObjectId(), |
|
61
|
|
|
], |
|
62
|
|
|
]; |
|
63
|
|
|
|
|
64
|
|
|
self::$referenceManyData = [ |
|
65
|
|
|
'groups' => [ |
|
66
|
|
|
[ |
|
67
|
|
|
'$ref' => 'Group', |
|
68
|
|
|
'$id' => new ObjectId(), |
|
69
|
|
|
], |
|
70
|
|
|
[ |
|
71
|
|
|
'$ref' => 'Group', |
|
72
|
|
|
'$id' => new ObjectId(), |
|
73
|
|
|
], |
|
74
|
|
|
], |
|
75
|
|
|
]; |
|
76
|
|
|
|
|
77
|
|
|
self::$hydrator = $this |
|
78
|
|
|
->getDocumentManager() |
|
79
|
|
|
->getHydratorFactory() |
|
80
|
|
|
->getHydratorFor(User::class); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @Warmup(2) |
|
85
|
|
|
*/ |
|
86
|
|
|
public function benchHydrateDocument() |
|
87
|
|
|
{ |
|
88
|
|
|
self::$hydrator->hydrate(new User(), self::$data); |
|
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @Warmup(2) |
|
93
|
|
|
*/ |
|
94
|
|
|
public function benchHydrateDocumentWithEmbedOne() |
|
95
|
|
|
{ |
|
96
|
|
|
self::$hydrator->hydrate(new User(), self::$data + self::$embedOneData); |
|
|
|
|
|
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @Warmup(2) |
|
101
|
|
|
*/ |
|
102
|
|
|
public function benchHydrateDocumentWithEmbedMany() |
|
103
|
|
|
{ |
|
104
|
|
|
self::$hydrator->hydrate(new User(), self::$data + self::$embedManyData); |
|
|
|
|
|
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @Warmup(2) |
|
109
|
|
|
*/ |
|
110
|
|
|
public function benchHydrateDocumentWithReferenceOne() |
|
111
|
|
|
{ |
|
112
|
|
|
self::$hydrator->hydrate(new User(), self::$data + self::$referenceOneData); |
|
|
|
|
|
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @Warmup(2) |
|
117
|
|
|
*/ |
|
118
|
|
|
public function benchHydrateDocumentWithReferenceMany() |
|
119
|
|
|
{ |
|
120
|
|
|
self::$hydrator->hydrate(new User(), self::$data + self::$referenceManyData); |
|
|
|
|
|
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: