Support automatic forward-paging of entity collections #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As a developer using the drupal.org API, it's common to have to load multiple pages of results. This PR adds a new class that transparently loads new pages as you iterate over a collection.
Highlights
Catching errors when decoding
json_decode()
relies on manually checking error codes viajson_last_error()
. Guzzle used have a function to do this, but it was removed in Guzzle 6. 28929cf pulls insymfony/serializer
so we can use it's JSON decoder. I know, it would be nice if it was it's own package, but I think the benefits of familiarity to Drupal developers outweighs the (small) cost of additional code invendor
.A trait for rel link handling
44e6685 lets us share methods between the existing collection class and the new one.
A new interface for collections
e938b8c adds a new interface to the existing collection class. Technically there's a small BC break here because I added return typehinting to the
\Iterator
methods. I personally don't think it's worth rolling a new major release just for this given that code is likely broken if it breaks this contract anyways. If there's disagreement there, I'd be open to removing it or doing a little more refactoring that does break BC more directly.Remaining Tasks
DeprecateI decided against this - I think being explicit about class mappings is more robust, but it isn't strictly required for this feature.\Hussainweb\DrupalApi\Request\Request::getEntityClass()
and move the responsibility to the request object. As is, it's brittle to extend this since it relies on specific class naming and FQCNs.