Download the PHP package trkisf2/remote-collection-stream without Composer
On this page you can find all versions of the php package trkisf2/remote-collection-stream. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download trkisf2/remote-collection-stream
More information about trkisf2/remote-collection-stream
Files in trkisf2/remote-collection-stream
Package remote-collection-stream
Short Description Continuously streams remote collection in user defined chunks and yields them using Generators.
License
Informations about the package remote-collection-stream
Description
Continuously streams remote collection in user defined chunks and yields them using Generators.
Usage
Use case, implementation example
Let's say we want to fully stream a bigger MySQL table (few million rows) into a messanging queue in chunks without crushing due to memory limits.
ChunksProvider looks like:
And $this->campaigns is a simple Repository fetching data from MySQL using $offset, $limit. Chunk object is just a custom DTO.
Or it could be a dummy in memory collection
Few last words about the implementation
The Stream objects fetches new collections using callable which is a bit loose as I can't enforce the callable arguments with an interface and even though it makes me feel as a JS developer, it gives the implementation side a nice advantage + there is a validation in place verifying the number of arguments passed.
The ability to combine the call with own parameters:
If Stream object would require some kind of "CollectionRepository" in the constructor then you would have to use setters, nullable attributes and other evil things in the repository in order to use additional arguments like filters in the query etc.
Tests included.