SerializableLimitIterator.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  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.
  14. *
  15. * @category Zend
  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: Interface.php 17687 2009-08-20 12:55:34Z thomas $
  20. */
  21. /**
  22. * @category Zend
  23. * @package Zend_Paginator
  24. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  25. * @license http://framework.zend.com/license/new-bsd New BSD License
  26. */
  27. class Zend_Paginator_SerializableLimitIterator extends LimitIterator implements Serializable
  28. {
  29. /**
  30. * Offset to first element
  31. *
  32. * @var int
  33. */
  34. private $_offset;
  35. /**
  36. * Maximum number of elements to show or -1 for all
  37. *
  38. * @var int
  39. */
  40. private $_count;
  41. /**
  42. * Construct a Zend_Paginator_SerializableLimitIterator
  43. *
  44. * @param Iterator $it Iterator to limit (must be serializable by un-/serialize)
  45. * @param int $offset Offset to first element
  46. * @param int $count Maximum number of elements to show or -1 for all
  47. * @see LimitIterator::__construct
  48. */
  49. public function __construct (Iterator $it, $offset=0, $count=-1)
  50. {
  51. parent::__construct($it, $offset, $count);
  52. $this->_offset = $offset;
  53. $this->_count = $count;
  54. }
  55. /**
  56. * @return string representation of the instance
  57. */
  58. public function serialize()
  59. {
  60. return serialize(array(
  61. 'it' => $this->getInnerIterator(),
  62. 'offset' => $this->_offset,
  63. 'count' => $this->_count,
  64. 'pos' => $this->getPosition(),
  65. ));
  66. }
  67. /**
  68. * @paran string $data representation of the instance
  69. */
  70. public function unserialize($data)
  71. {
  72. $dataArr = unserialize($data);
  73. $this->__construct($dataArr['it'], $dataArr['offset'], $dataArr['count']);
  74. $this->seek($dataArr['pos']+$dataArr['offset']);
  75. }
  76. }