Sections_Iterator_Object.php 753 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. class Sections_Iterator_Object extends Mustache {
  3. public $start = "It worked the first time.";
  4. public function middle() {
  5. return new Iterator_Object;
  6. }
  7. public $final = "Then, surprisingly, it worked the final time.";
  8. }
  9. class Iterator_Object implements Iterator
  10. {
  11. protected $_position = 0;
  12. protected $_data = array(
  13. array('item' => 'And it worked the second time.'),
  14. array('item' => 'As well as the third.'),
  15. );
  16. public function rewind() {
  17. $this->_position = 0;
  18. }
  19. public function current() {
  20. return $this->_data[$this->_position];
  21. }
  22. public function key() {
  23. return $this->_position;
  24. }
  25. public function next() {
  26. ++$this->_position;
  27. }
  28. public function valid() {
  29. return isset($this->_data[$this->_position]);
  30. }
  31. }