Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Paginator / SerializableLimitIterator.php
blob5b0bb3cad3768673d43ebe34cdd0399fd5610075
1 <?php
2 /**
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
8 */
10 namespace Zend\Paginator;
12 use ArrayAccess;
13 use Iterator;
14 use LimitIterator;
15 use Serializable;
17 class SerializableLimitIterator extends LimitIterator implements Serializable, ArrayAccess
20 /**
21 * Offset to first element
23 * @var int
25 private $offset;
27 /**
28 * Maximum number of elements to show or -1 for all
30 * @var int
32 private $count;
34 /**
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;
49 /**
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(),
59 ));
62 /**
63 * @param string $data representation of the instance
64 * @return void
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']);
73 /**
74 * Returns value of the Iterator
76 * @param int $offset
77 * @return mixed
79 public function offsetGet($offset)
81 $currentOffset = $this->key();
82 $this->seek($offset);
83 $current = $this->current();
84 $this->seek($currentOffset);
85 return $current;
88 /**
89 * Does nothing
90 * Required by the ArrayAccess implementation
92 * @param int $offset
93 * @param mixed $value
95 public function offsetSet($offset, $value)
99 /**
100 * Determine if a value of Iterator is set and is not NULL
102 * @param int $offset
103 * @return bool
105 public function offsetExists($offset)
107 if ($offset > 0 && $offset < $this->count) {
108 try {
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);
117 return false;
120 return false;
124 * Does nothing
125 * Required by the ArrayAccess implementation
127 * @param int $offset
129 public function offsetUnset($offset)