_offset = $offset; $this->_count = $count; } /** * @return string representation of the instance */ public function serialize() { return serialize(array( 'it' => $this->getInnerIterator(), 'offset' => $this->_offset, 'count' => $this->_count, 'pos' => $this->getPosition(), )); } /** * @param string $data representation of the instance */ public function unserialize($data) { $dataArr = unserialize($data); $this->__construct($dataArr['it'], $dataArr['offset'], $dataArr['count']); $this->seek($dataArr['pos']+$dataArr['offset']); } /** * Returns value of the Iterator * * @param int $offset * @return mixed */ public function offsetGet($offset) { $currentOffset = $this->key(); $this->seek($offset); $current = $this->current(); $this->seek($currentOffset); return $current; } /** * Does nothing * Required by the ArrayAccess implementation * * @param int $offset * @param mixed $value */ public function offsetSet($offset, $value) { } /** * Determine if a value of Iterator is set and is not NULL * * @param int $offset */ public function offsetExists($offset) { if ($offset > 0 && $offset < $this->_count) { try { $currentOffset = $this->key(); $this->seek($offset); $current = $this->current(); $this->seek($currentOffset); return null !== $current; } catch (OutOfBoundsException $e) { // reset position in case of exception is assigned null $this->rewind(); $this->seek($currentOffset); return false; } } return false; } /** * Does nothing * Required by the ArrayAccess implementation * * @param int $offset */ public function offsetUnset($offset) { } }