PPPStripeUtilAutoPagingIterator

The Gravity Forms + Stripe PPP Stripe Util AutoPagingIterator class.

Defined (1)

The class is defined in the following location(s).

/includes/api/stripe-php/lib/Util/AutoPagingIterator.php  
  1. class AutoPagingIterator implements \Iterator 
  2. private $lastId = null; 
  3. private $page = null; 
  4. private $pageOffset = 0; 
  5. private $params = array(); 
  6.  
  7. public function __construct($collection, $params) 
  8. $this->page = $collection; 
  9. $this->params = $params; 
  10.  
  11. public function rewind() 
  12. // Actually rewinding would require making a copy of the original page. 
  13.  
  14. public function current() 
  15. $item = current($this->page->data); 
  16. $this->lastId = $item !== false ? $item['id'] : null; 
  17.  
  18. return $item; 
  19.  
  20. public function key() 
  21. return key($this->page->data) + $this->pageOffset; 
  22.  
  23. public function next() 
  24. $item = next($this->page->data); 
  25. if ($item === false) { 
  26. // If we've run out of data on the current page, try to fetch another one 
  27. // and increase the offset the new page would start at 
  28. $this->pageOffset += count($this->page->data); 
  29. if ($this->page['has_more']) { 
  30. $this->params = array_merge( 
  31. $this->params ? $this->params : array(),  
  32. array('starting_after' => $this->lastId) 
  33. ); 
  34. $this->page = $this->page->all($this->params); 
  35. } else { 
  36. return false; 
  37.  
  38. public function valid() 
  39. $key = key($this->page->data); 
  40. $valid = ($key !== null && $key !== false); 
  41. return $valid;