11
11
use Doctrine \ODM \MongoDB \UnitOfWork ;
12
12
use Doctrine \ODM \MongoDB \Utility \CollectionHelper ;
13
13
14
- use function array_udiff ;
14
+ use function array_combine ;
15
+ use function array_diff_key ;
16
+ use function array_map ;
15
17
use function array_udiff_assoc ;
16
18
use function array_values ;
17
19
use function count ;
18
20
use function get_class ;
19
21
use function is_object ;
20
- use function spl_object_hash ;
21
22
22
23
/**
23
24
* Trait with methods needed to implement PersistentCollectionInterface.
@@ -255,18 +256,11 @@ static function ($a, $b) {
255
256
/** {@inheritdoc} */
256
257
public function getDeletedDocuments ()
257
258
{
258
- $ compare = static function ( $ a , $ b ) {
259
- $ compareA = is_object ( $ a ) ? spl_object_hash ( $ a ) : $ a ;
260
- $ compareb = is_object ( $ b ) ? spl_object_hash ( $ b ) : $ b ;
259
+ $ coll = $ this -> coll -> toArray ();
260
+ $ loadedObjectsByOid = array_combine ( array_map ( ' spl_object_id ' , $ this -> snapshot ), $ this -> snapshot ) ;
261
+ $ newObjectsByOid = array_combine ( array_map ( ' spl_object_id ' , $ coll ), $ coll ) ;
261
262
262
- return $ compareA === $ compareb ? 0 : ($ compareA > $ compareb ? 1 : -1 );
263
- };
264
-
265
- return array_values (array_udiff (
266
- $ this ->snapshot ,
267
- $ this ->coll ->toArray (),
268
- $ compare
269
- ));
263
+ return array_values (array_diff_key ($ loadedObjectsByOid , $ newObjectsByOid ));
270
264
}
271
265
272
266
/** {@inheritdoc} */
@@ -284,18 +278,11 @@ static function ($a, $b) {
284
278
/** {@inheritdoc} */
285
279
public function getInsertedDocuments ()
286
280
{
287
- $ compare = static function ( $ a , $ b ) {
288
- $ compareA = is_object ( $ a ) ? spl_object_hash ( $ a ) : $ a ;
289
- $ compareb = is_object ( $ b ) ? spl_object_hash ( $ b ) : $ b ;
281
+ $ coll = $ this -> coll -> toArray ();
282
+ $ newObjectsByOid = array_combine ( array_map ( ' spl_object_id ' , $ coll ), $ coll ) ;
283
+ $ loadedObjectsByOid = array_combine ( array_map ( ' spl_object_id ' , $ this -> snapshot ), $ this -> snapshot ) ;
290
284
291
- return $ compareA === $ compareb ? 0 : ($ compareA > $ compareb ? 1 : -1 );
292
- };
293
-
294
- return array_values (array_udiff (
295
- $ this ->coll ->toArray (),
296
- $ this ->snapshot ,
297
- $ compare
298
- ));
285
+ return array_values (array_diff_key ($ newObjectsByOid , $ loadedObjectsByOid ));
299
286
}
300
287
301
288
/** {@inheritdoc} */
0 commit comments