@@ -48,27 +48,17 @@ public function create($data): Entity
4848 }
4949 }
5050
51- $ instance = $ this ->createInstance ();
52- foreach ($ data as $ key => $ value ) {
53- if ($ value instanceof Entity) {
54- $ value = $ value ->getRepository ()->getSpace ()->getIndex (0 )->getValue ($ value ->toArray ()) ?: null ;
55- }
56- $ instance ->$ key = $ value ;
57- }
58-
59- foreach ($ this ->getMapper ()->getPlugins () as $ plugin ) {
60- $ plugin ->afterInstantiate ($ instance , $ this ->space );
61- }
51+ $ instance = $ this ->createInstance ([], $ data );
6252
6353 return $ instance ;
6454 }
6555
66- public function createInstance (array $ tuple = []): Entity
56+ public function createInstance (array $ tuple = [], array $ data = [] ): Entity
6757 {
6858 $ class = Entity::class;
69- $ data = $ this ->getSpace ()->getMap ($ tuple );
59+ $ map = $ this ->getSpace ()->getMap ($ tuple );
7060 foreach ($ this ->getMapper ()->getPlugins () as $ plugin ) {
71- $ entityClass = $ plugin ->getEntityClass ($ this ->space , $ data );
61+ $ entityClass = $ plugin ->getEntityClass ($ this ->space , $ map );
7262 if (!$ entityClass ) {
7363 continue ;
7464 }
@@ -80,6 +70,17 @@ public function createInstance(array $tuple = []): Entity
8070
8171 $ instance = new $ class ($ this , $ tuple );
8272
73+ foreach ($ data as $ key => $ value ) {
74+ if ($ value instanceof Entity) {
75+ $ value = $ value ->getRepository ()->getSpace ()->getIndex (0 )->getValue ($ value ->toArray ()) ?: null ;
76+ }
77+ $ instance ->$ key = $ value ;
78+ }
79+
80+ foreach ($ this ->getMapper ()->getPlugins () as $ plugin ) {
81+ $ plugin ->afterInstantiate ($ instance , $ this ->space );
82+ }
83+
8384 return $ instance ;
8485 }
8586
0 commit comments