-
-
Notifications
You must be signed in to change notification settings - Fork 504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use CursorInterface type instead of Cursor #2546
Conversation
My guess is that at the time a |
Actually I'd love to change the lmk if these changes are possible, thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My guess is that at the time a Cursor was the only thing the underlying library could have returned.
I'm not sure how much this question pertains to the Aggregate operation itself, but I can point out that it historically returned a Traversable. That was recently changed in mongodb/mongo-php-library@5aff53f since a non-cursor response is no longer possible on MongoDB 3.6+ (required by the current driver/library version).
Also, nothing has historically implemented CursorInterface (apart from MongoDB\Driver\Cursor), but that will change once codecs are implemented (see: mongodb/mongo-php-library#1140).
With that in mind, I think it may make sense to use CursorInterface instead of Cursor in ODM, although there's likely no rush as alternative implementations won't be returned until ODM (or any other library) starts making use of codecs, which would be a separate initiative.
@alcaeus can speak more to this once he's back from holiday next week.
@@ -58,7 +59,7 @@ public function getIterator(): Iterator | |||
return $this->prepareIterator($cursor); | |||
} | |||
|
|||
private function prepareIterator(Cursor $cursor): Iterator | |||
private function prepareIterator(CursorInterface $cursor): Iterator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will note that while Cursor does implement both CursorInterface and Iterator, CursorInterface itself is only Traversable. Depending how ODM uses the $cursor
object here, this change might conflict with static analysis checks.
Yes, absolutely. We haven't had a reason for making this change, but this reason is coming with the addition of codecs in PHPLIB, which will result in return values that are not |
I did the change, do you think that we could also get rid of the |
Yes - the assertion can be removed. IIRC this was there for static analysis reasons. |
bumped and rebased against 2.6, lmk if it needs to target something else |
Hello, Can this be pushed forward and reviewed please? It’s me who reported this issue with the APP in api-platform/core#5705. MongoDB works great for our project but this depreciation notices is a bit scary to use in a stable framework. Thanks! |
|
||
return $this->prepareIterator($cursor); | ||
} | ||
|
||
private function prepareIterator(Cursor $cursor): Iterator | ||
private function prepareIterator(CursorInterface&Iterator $cursor): Iterator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW branch 2.6.x requires php ^8.0 while this is valid starting with 8.1. But maybe we could bump requirement to 8.1, 8.0 usage in 2.5.x is rather minimal: https://packagist.org/packages/doctrine/mongodb-odm/php-stats#2.5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No objections to bumping to PHP 8.1 from my end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bumped in #2556
The change itself looks good, but static analysis is not too happy. We might have to leave the assertions in place to quiet down PHPStan. |
sure, should I update this? |
Summary
I still have the same issue, I want to move from
execute()
togetAggregation()->getIterator()
but this class is completely locked in and we have no way to unit test this:https://github.com/api-platform/core/blob/92a81f024541054b9322e7457b75c721261e14e0/src/Doctrine/Odm/State/ItemProvider.php#L74
The assertion above is fine I can disable it, but in fact I wonder why you wouldn't do
instanceof CursorInterface
, what if someone implements another Cursor? We can't use theAggregation
type, nor theAggregationBuilder
(as the signature ofgetAggregation
forces the use of the final classAggregation
) nor theDocumentRepository
, which forces the use of theAggregationBuilder
...Can you help providing a solution for library maintainers? Thanks!