Skip to content

Commit

Permalink
Remove dependency to collection
Browse files Browse the repository at this point in the history
  • Loading branch information
tbreuss committed Mar 25, 2016
1 parent 050d9c4 commit 7168a5b
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions system/Pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,32 @@

namespace Herbie;

use Herbie\Menu\Page\Collection;

class Pagination implements \IteratorAggregate, \Countable
{

/** @var array */
protected $items;

/** @var int */
protected $limit;

/** @var string */
protected $name;

/**
* @param Collection|array $items
* @param \IteratorAggregate|array $items
* @param int $limit
* @param string $name
* @throws \Exception
*/
public function __construct($items, $limit = 10, $name = 'page')
{
$this->items = [];
if (is_array($items)) {
$this->items = $items;
}
if ($items instanceof Collection) {
$this->items = $items->flatten();
} elseif ($items instanceof \IteratorAggregate) {
$this->items = (array)$items->getIterator();
} else {
throw new \Exception("The param \$items must be an array or an object implementing IteratorAggregate.", 500);
}
$this->setLimit($limit);
$this->name = $name;
Expand Down

0 comments on commit 7168a5b

Please sign in to comment.