2021-11-23 14:08:50 +01:00

56 lines
985 B
PHP

<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Pagination;
use Iterator;
/**
* PageGenerator associated with a Paginator.
*/
class PageGenerator implements Iterator
{
protected int $current = 1;
protected Paginator $paginator;
public function __construct(Paginator $paginator)
{
$this->paginator = $paginator;
}
public function current()
{
return $this->paginator->getPage($current);
}
public function key()
{
return $this->current;
}
public function next()
{
++$this->current;
}
public function rewind()
{
$this->current = 1;
}
public function valid()
{
return 0 < $this->current
&& $this->paginator->countPages() >= $this->current;
}
}