PHP code example of jeroen / batching-iterator
1. Go to this page and download the library: Download jeroen/batching-iterator library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jeroen / batching-iterator example snippets
class TweetImporter {
public function importTweets( Iterator $tweets ) {
foreach ( $tweets as $tweet ) {
$this->tweetStore->saveTweet( $tweet );
}
}
}
class BatchingTweetFetcher implements BatchingFetcher {
public function fetchNext( $maxFetchCount ) {
// Make a call to some external service to fetch $tweets
return $tweets;
}
public function rewind() {
// Go back to the first tweet
}
}
class TweetImportCli {
public function importTweets() {
$tweetIterator = new BatchingIterator( new BatchingTweetFetcher() );
$tweetIterator->setMaxBatchSize( 42 );
$this->tweetImporter->importTweets( $tweetIterator );
}
}