doctrine/mongodb-odm — pull request #752 by lemoinem (2014-01-09 20:57:32+00:00)
Title: [BC break!] Fix DocumentRepository to fit ObjectRepository interface

Hello,

https://github.com/doctrine/common/blob/master/lib/Doctrine/Common/Persistence/ObjectRepository.php#L60 explicitly document the `findBy()` method as returning an array of objects.

This interface spec is broken in spec and behaviour by https://github.com/doctrine/mongodb-odm/blob/master/lib/Doctrine/ODM/MongoDB/DocumentRepository.php#L164

This PR aims to fix this. It is quite a major BC break for the MongoDB ODM (as the various updated tests show), but I believe the interface shouldn't have been broken in the first place. We were able to break the interface only because PHP doesn't provide a way to check the type of the return value of a method and because Doctrine Common does not provide implementation tests for its interfaces (I don't intend this remark as a critic, but to describe a fact here :wink:). It prevents code base engineered to interact with the Doctrine\Common\Persistence interfaces to crash miserably without clean workarounds.

In order to minimize BC break. I provided the protected method `getDocumentPersister()` in the DocumentRepository so custom repositories could easily return a Cursor (For example, to load associations through custom repository methods).

If you have any ideas that could fix this without BC Break, I would be happy to ear about it and try as hard as possible to reduce BC breaks and update my PR accordingly.