<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">&lt;?php
class PagingJsonIterator implements Iterator
{
    protected $http;
    protected $url;
    protected $pageSize;
    protected $totalCount;

    public $jsonVarTotal = 'total';
    public $jsonVarStartAt = 'startAt';
    public $jsonVarPageSize = 'maxResults';
    public $jsonVarData = 'issues';

    public function __construct(HTTP_Request2 $http, $url, $pageSize = 50)
    {
        $this-&gt;http = $http;
        $this-&gt;url = $url;
        $this-&gt;pageSize = $pageSize;
    }

    public function rewind()
    {
        $this-&gt;position = 0;
        $this-&gt;loadData();
    }

    public function current()
    {
        return $this-&gt;data[$this-&gt;position - $this-&gt;dataPos];
    }

    public function key()
    {
        return $this-&gt;position;
    }

    public function next()
    {
        ++$this-&gt;position;
    }

    public function valid()
    {
        if (isset($this-&gt;data[$this-&gt;position - $this-&gt;dataPos])) {
            return true;
        }
        if ($this-&gt;position &gt;= $this-&gt;totalCount) {
            //no more data
            return false;
        }
        $this-&gt;loadData();
        return isset($this-&gt;data[$this-&gt;position - $this-&gt;dataPos]);
    }

    protected function loadData()
    {
        $hreq = clone $this-&gt;http;
        $hreq-&gt;setUrl(
            str_replace(
                array('{startAt}', '{pageSize}'),
                array($this-&gt;position, $this-&gt;pageSize),
                $this-&gt;url
            )
        );
        $res = $hreq-&gt;send();
        $obj = json_decode($res-&gt;getBody());
        $this-&gt;totalCount = $obj-&gt;{$this-&gt;jsonVarTotal};
        $this-&gt;data = $obj-&gt;{$this-&gt;jsonVarData};
        $this-&gt;dataPos = $this-&gt;position;
    }
}
?&gt;
</pre></body></html>