From 7168a5ba4bca2d437e179ded714986b4bfcd932d Mon Sep 17 00:00:00 2001 From: Thomas Breuss Date: Fri, 25 Mar 2016 13:52:25 +0100 Subject: [PATCH] Remove dependency to collection --- system/Pagination.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/system/Pagination.php b/system/Pagination.php index bf7c3b9f..99f2fe45 100644 --- a/system/Pagination.php +++ b/system/Pagination.php @@ -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;