3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Paginator
;
17 class SerializableLimitIterator
extends LimitIterator
implements Serializable
, ArrayAccess
21 * Offset to first element
28 * Maximum number of elements to show or -1 for all
35 * Construct a Zend\Paginator\SerializableLimitIterator
37 * @param Iterator $it Iterator to limit (must be serializable by un-/serialize)
38 * @param int $offset Offset to first element
39 * @param int $count Maximum number of elements to show or -1 for all
40 * @see LimitIterator::__construct
42 public function __construct(Iterator
$it, $offset=0, $count=-1)
44 parent
::__construct($it, $offset, $count);
45 $this->offset
= $offset;
46 $this->count
= $count;
50 * @return string representation of the instance
52 public function serialize()
54 return serialize(array(
55 'it' => $this->getInnerIterator(),
56 'offset' => $this->offset
,
57 'count' => $this->count
,
58 'pos' => $this->getPosition(),
63 * @param string $data representation of the instance
66 public function unserialize($data)
68 $dataArr = unserialize($data);
69 $this->__construct($dataArr['it'], $dataArr['offset'], $dataArr['count']);
70 $this->seek($dataArr['pos']+
$dataArr['offset']);
74 * Returns value of the Iterator
79 public function offsetGet($offset)
81 $currentOffset = $this->key();
83 $current = $this->current();
84 $this->seek($currentOffset);
90 * Required by the ArrayAccess implementation
95 public function offsetSet($offset, $value)
100 * Determine if a value of Iterator is set and is not NULL
105 public function offsetExists($offset)
107 if ($offset > 0 && $offset < $this->count
) {
109 $currentOffset = $this->key();
110 $this->seek($offset);
111 $current = $this->current();
112 $this->seek($currentOffset);
113 return null !== $current;
114 } catch (\OutOfBoundsException
$e) {
115 // reset position in case of exception is assigned null
116 $this->seek($currentOffset);
125 * Required by the ArrayAccess implementation
129 public function offsetUnset($offset)