From e40a57cba19a3fe744e216ce96c8a646fc041dea Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Sun, 15 Aug 2010 06:27:54 -0400 Subject: [PATCH] Refactor section_iterator_objects example. Defining an IteratorObject class is unnecessary: the ArrayIterator will do just fine. --- .../SectionIteratorObjects.php | 30 ++----------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/examples/section_iterator_objects/SectionIteratorObjects.php b/examples/section_iterator_objects/SectionIteratorObjects.php index fa5213c..7b65597 100644 --- a/examples/section_iterator_objects/SectionIteratorObjects.php +++ b/examples/section_iterator_objects/SectionIteratorObjects.php @@ -3,38 +3,14 @@ class SectionIteratorObjects extends Mustache { public $start = "It worked the first time."; - public function middle() { - return new IteratorObject(); - } - - public $final = "Then, surprisingly, it worked the final time."; -} - -class IteratorObject implements Iterator { - protected $_position = 0; - protected $_data = array( array('item' => 'And it worked the second time.'), array('item' => 'As well as the third.'), ); - public function rewind() { - $this->_position = 0; + public function middle() { + return new ArrayIterator($this->_data); } - public function current() { - return $this->_data[$this->_position]; - } - - public function key() { - return $this->_position; - } - - public function next() { - ++$this->_position; - } - - public function valid() { - return isset($this->_data[$this->_position]); - } + public $final = "Then, surprisingly, it worked the final time."; } \ No newline at end of file