@@ -36,6 +36,11 @@ final class Connection extends \Doctrine\DBAL\Connection
3636 */
3737 private $ objectGraph ;
3838
39+ /**
40+ * @var IdentityMap[]
41+ */
42+ private $ identityMap ;
43+
3944 /**
4045 * @return null|string
4146 */
@@ -74,6 +79,27 @@ public function getMapperLocator()
7479 return $ this ->mapperLocator ;
7580 }
7681
82+
83+ /**
84+ * @param $classOrObject
85+ * @return IdentityMap
86+ */
87+ public function loadIdentityMap ($ classOrObject )
88+ {
89+ if (is_object ($ classOrObject )) {
90+ $ classOrObject = get_class ($ classOrObject );
91+ }
92+
93+ if (!is_string ($ classOrObject )) {
94+ throw new \InvalidArgumentException ('Invalid data type ' . gettype ($ classOrObject ));
95+ }
96+ if (!isset ($ this ->identityMap [$ classOrObject ])){
97+ $ this ->identityMap [$ classOrObject ] = new IdentityMap ();
98+ }
99+
100+ return $ this ->identityMap [$ classOrObject ];
101+ }
102+
77103 /**
78104 * @return UnitOfWork
79105 */
@@ -94,19 +120,16 @@ public function getObjectGraph(){
94120 /**
95121 * @return array
96122 */
97- public function getIdentityStateGraph (){
98- $ mappers = $ this ->getMapperLocator ()->getMapperMap ();
123+ public function getEntityStateGraph (){
99124 $ objectGraph = $ this ->getObjectGraph ();
100125 $ graph = [];
101126
102- foreach ($ mappers as $ mapper ){
103- $ identities = $ mapper -> getIdentityMap () ->toArray ();
127+ foreach ($ this -> identityMap as $ identityMap ){
128+ $ identities = $ identityMap ->toArray ();
104129
105130 foreach ($ identities as $ id => $ object ){
106- $ identities [$ id ] = $ objectGraph ->getState ($ object );
131+ $ graph [ get_class ( $ object )] [$ id ] = $ objectGraph ->getState ($ object );
107132 }
108-
109- $ graph [$ mapper ->getEntityClass ()] = $ identities ;
110133 }
111134
112135 return $ graph ;
0 commit comments