File indexing completed on 2024-12-22 05:36:53
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Paginator 0017 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0018 * @license http://framework.zend.com/license/new-bsd New BSD License 0019 * @version $Id$ 0020 */ 0021 0022 /** 0023 * @category Zend 0024 * @package Zend_Paginator 0025 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0026 * @license http://framework.zend.com/license/new-bsd New BSD License 0027 */ 0028 class Zend_Paginator_SerializableLimitIterator extends LimitIterator implements Serializable, ArrayAccess 0029 { 0030 0031 /** 0032 * Offset to first element 0033 * 0034 * @var int 0035 */ 0036 private $_offset; 0037 0038 /** 0039 * Maximum number of elements to show or -1 for all 0040 * 0041 * @var int 0042 */ 0043 private $_count; 0044 0045 /** 0046 * Construct a Zend_Paginator_SerializableLimitIterator 0047 * 0048 * @param Iterator $it Iterator to limit (must be serializable by un-/serialize) 0049 * @param int $offset Offset to first element 0050 * @param int $count Maximum number of elements to show or -1 for all 0051 * @see LimitIterator::__construct 0052 */ 0053 public function __construct (Iterator $it, $offset=0, $count=-1) 0054 { 0055 parent::__construct($it, $offset, $count); 0056 $this->_offset = $offset; 0057 $this->_count = $count; 0058 } 0059 0060 /** 0061 * @return string representation of the instance 0062 */ 0063 public function serialize() 0064 { 0065 return serialize(array( 0066 'it' => $this->getInnerIterator(), 0067 'offset' => $this->_offset, 0068 'count' => $this->_count, 0069 'pos' => $this->getPosition(), 0070 )); 0071 } 0072 0073 /** 0074 * @param string $data representation of the instance 0075 */ 0076 public function unserialize($data) 0077 { 0078 $dataArr = unserialize($data); 0079 $this->__construct($dataArr['it'], $dataArr['offset'], $dataArr['count']); 0080 $this->seek($dataArr['pos']+$dataArr['offset']); 0081 } 0082 0083 /** 0084 * Returns value of the Iterator 0085 * 0086 * @param int $offset 0087 * @return mixed 0088 */ 0089 public function offsetGet($offset) 0090 { 0091 $currentOffset = $this->key(); 0092 $this->seek($offset); 0093 $current = $this->current(); 0094 $this->seek($currentOffset); 0095 return $current; 0096 } 0097 0098 /** 0099 * Does nothing 0100 * Required by the ArrayAccess implementation 0101 * 0102 * @param int $offset 0103 * @param mixed $value 0104 */ 0105 public function offsetSet($offset, $value) 0106 { 0107 } 0108 0109 /** 0110 * Determine if a value of Iterator is set and is not NULL 0111 * 0112 * @param int $offset 0113 */ 0114 public function offsetExists($offset) 0115 { 0116 if ($offset > 0 && $offset < $this->_count) { 0117 try { 0118 $currentOffset = $this->key(); 0119 $this->seek($offset); 0120 $current = $this->current(); 0121 $this->seek($currentOffset); 0122 return null !== $current; 0123 } catch (OutOfBoundsException $e) { 0124 // reset position in case of exception is assigned null 0125 $this->rewind(); 0126 $this->seek($currentOffset); 0127 return false; 0128 } 0129 } 0130 return false; 0131 } 0132 0133 /** 0134 * Does nothing 0135 * Required by the ArrayAccess implementation 0136 * 0137 * @param int $offset 0138 */ 0139 public function offsetUnset($offset) 0140 { 0141 } 0142 }