7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
16 * @package Zend_Paginator
17 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
18 * @license http://framework.zend.com/license/new-bsd New BSD License
19 * @version $Id: Iterator.php 16215 2009-06-21 19:36:07Z thomas $
23 * @see Zend_Paginator_Adapter_Interface
25 require_once 'Zend/Paginator/Adapter/Interface.php';
29 * @package Zend_Paginator
30 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
31 * @license http://framework.zend.com/license/new-bsd New BSD License
33 class Zend_Paginator_Adapter_Iterator
implements Zend_Paginator_Adapter_Interface
36 * Iterator which implements Countable
40 protected $_iterator = null;
47 protected $_count = null;
52 * @param Iterator $iterator Iterator to paginate
53 * @throws Zend_Paginator_Exception
55 public function __construct(Iterator
$iterator)
57 if (!$iterator instanceof Countable
) {
59 * @see Zend_Paginator_Exception
61 require_once 'Zend/Paginator/Exception.php';
63 throw new Zend_Paginator_Exception('Iterator must implement Countable');
66 $this->_iterator
= $iterator;
67 $this->_count
= count($iterator);
71 * Returns an iterator of items for a page, or an empty array.
73 * @param integer $offset Page offset
74 * @param integer $itemCountPerPage Number of items per page
75 * @return LimitIterator|array
77 public function getItems($offset, $itemCountPerPage)
79 if ($this->_count
== 0) {
83 return new LimitIterator($this->_iterator
, $offset, $itemCountPerPage);
87 * Returns the total number of rows in the collection.
91 public function count()