2020namespace Doctrine \ODM \MongoDB \Persisters ;
2121
2222use Doctrine \Common \EventManager ;
23- use Doctrine \MongoDB \Cursor as BaseCursor ;
23+ use Doctrine \MongoDB \CursorInterface ;
2424use Doctrine \ODM \MongoDB \Cursor ;
2525use Doctrine \ODM \MongoDB \DocumentManager ;
26- use Doctrine \ODM \MongoDB \EagerCursor ;
2726use Doctrine \ODM \MongoDB \Utility \CollectionHelper ;
2827use Doctrine \ODM \MongoDB \Hydrator \HydratorFactory ;
2928use Doctrine \ODM \MongoDB \LockException ;
@@ -507,22 +506,15 @@ public function loadAll(array $criteria = array(), array $sort = null, $limit =
507506 $ baseCursor = $ this ->collection ->find ($ criteria );
508507 $ cursor = $ this ->wrapCursor ($ baseCursor );
509508
510- /* The wrapped cursor may be used if the ODM cursor becomes wrapped with
511- * an EagerCursor, so we should apply the same sort, limit, and skip
512- * options to both cursors.
513- */
514509 if (null !== $ sort ) {
515- $ baseCursor ->sort ($ this ->prepareSortOrProjection ($ sort ));
516510 $ cursor ->sort ($ sort );
517511 }
518512
519513 if (null !== $ limit ) {
520- $ baseCursor ->limit ($ limit );
521514 $ cursor ->limit ($ limit );
522515 }
523516
524517 if (null !== $ skip ) {
525- $ baseCursor ->skip ($ skip );
526518 $ cursor ->skip ($ skip );
527519 }
528520
@@ -532,10 +524,10 @@ public function loadAll(array $criteria = array(), array $sort = null, $limit =
532524 /**
533525 * Wraps the supplied base cursor in the corresponding ODM class.
534526 *
535- * @param BaseCursor $cursor
527+ * @param CursorInterface $baseCursor
536528 * @return Cursor
537529 */
538- private function wrapCursor (BaseCursor $ baseCursor )
530+ private function wrapCursor (CursorInterface $ baseCursor )
539531 {
540532 return new Cursor ($ baseCursor , $ this ->dm ->getUnitOfWork (), $ this ->class );
541533 }
@@ -795,7 +787,7 @@ private function loadReferenceManyWithRepositoryMethod(PersistentCollection $col
795787 /**
796788 * @param PersistentCollection $collection
797789 *
798- * @return Cursor|EagerCursor
790+ * @return CursorInterface
799791 */
800792 public function createReferenceManyWithRepositoryMethodCursor (PersistentCollection $ collection )
801793 {
@@ -804,25 +796,24 @@ public function createReferenceManyWithRepositoryMethodCursor(PersistentCollecti
804796 $ cursor = $ this ->dm ->getRepository ($ mapping ['targetDocument ' ])
805797 ->$ mapping ['repositoryMethod ' ]($ collection ->getOwner ());
806798
807- $ wrappedCursor = $ cursor ;
808- if ($ cursor instanceof EagerCursor) {
809- $ wrappedCursor = $ cursor ->getCursor ();
799+ if ( ! $ cursor instanceof CursorInterface) {
800+ throw new \BadMethodCallException ("Expected repository method {$ mapping ['repositoryMethod ' ]} to return a CursorInterface " );
810801 }
811802
812803 if (isset ($ mapping ['sort ' ])) {
813- $ wrappedCursor ->sort ($ mapping ['sort ' ]);
804+ $ cursor ->sort ($ mapping ['sort ' ]);
814805 }
815806 if (isset ($ mapping ['limit ' ])) {
816- $ wrappedCursor ->limit ($ mapping ['limit ' ]);
807+ $ cursor ->limit ($ mapping ['limit ' ]);
817808 }
818809 if (isset ($ mapping ['skip ' ])) {
819- $ wrappedCursor ->skip ($ mapping ['skip ' ]);
810+ $ cursor ->skip ($ mapping ['skip ' ]);
820811 }
821812 if ( ! empty ($ hints [Query::HINT_SLAVE_OKAY ])) {
822- $ wrappedCursor ->slaveOkay (true );
813+ $ cursor ->slaveOkay (true );
823814 }
824815 if ( ! empty ($ hints [Query::HINT_READ_PREFERENCE ])) {
825- $ wrappedCursor ->setReadPreference ($ hints [Query::HINT_READ_PREFERENCE ], $ hints [Query::HINT_READ_PREFERENCE_TAGS ]);
816+ $ cursor ->setReadPreference ($ hints [Query::HINT_READ_PREFERENCE ], $ hints [Query::HINT_READ_PREFERENCE_TAGS ]);
826817 }
827818
828819 return $ cursor ;
0 commit comments