19
19
20
20
namespace Doctrine \ODM \MongoDB \Mapping ;
21
21
22
+ use Doctrine \Instantiator \Instantiator ;
22
23
use Doctrine \ODM \MongoDB \LockException ;
23
24
24
25
/**
@@ -49,11 +50,9 @@ class ClassMetadata extends ClassMetadataInfo
49
50
public $ reflFields = array ();
50
51
51
52
/**
52
- * The prototype from which new instances of the mapped class are created.
53
- *
54
- * @var object
53
+ * @var \Doctrine\Instantiator\InstantiatorInterface|null
55
54
*/
56
- private $ prototype ;
55
+ private $ instantiator ;
57
56
58
57
/**
59
58
* Initializes a new ClassMetadata instance that will hold the object-document mapping
@@ -67,6 +66,7 @@ public function __construct($documentName)
67
66
$ this ->reflClass = new \ReflectionClass ($ documentName );
68
67
$ this ->namespace = $ this ->reflClass ->getNamespaceName ();
69
68
$ this ->setCollection ($ this ->reflClass ->getShortName ());
69
+ $ this ->instantiator = new Instantiator ();
70
70
}
71
71
72
72
/**
@@ -176,6 +176,7 @@ public function __wakeup()
176
176
{
177
177
// Restore ReflectionClass and properties
178
178
$ this ->reflClass = new \ReflectionClass ($ this ->name );
179
+ $ this ->instantiator = $ this ->instantiator ?: new Instantiator ();
179
180
180
181
foreach ($ this ->fieldMappings as $ field => $ mapping ) {
181
182
if (isset ($ mapping ['declared ' ])) {
@@ -195,12 +196,6 @@ public function __wakeup()
195
196
*/
196
197
public function newInstance ()
197
198
{
198
- if ($ this ->prototype === null ) {
199
- $ this ->prototype = version_compare (PHP_VERSION , '5.4.0 ' , '>= ' )
200
- ? $ this ->reflClass ->newInstanceWithoutConstructor ()
201
- : unserialize (sprintf ('O:%d:"%s":0:{} ' , strlen ($ this ->name ), $ this ->name ));
202
- }
203
-
204
- return clone $ this ->prototype ;
199
+ return $ this ->instantiator ->instantiate ($ this ->name );
205
200
}
206
201
}
0 commit comments