SectionIteratorObject.php 750 B

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