From d9f864a13f9216b7ee78a85c53d3184220eb01c3 Mon Sep 17 00:00:00 2001 From: Silvio Date: Thu, 15 Jul 2010 18:15:21 -0300 Subject: Moving iterators to their own folder --- classes/iterators/IsisMethodIterator.php | 63 ++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 classes/iterators/IsisMethodIterator.php (limited to 'classes/iterators/IsisMethodIterator.php') diff --git a/classes/iterators/IsisMethodIterator.php b/classes/iterators/IsisMethodIterator.php new file mode 100644 index 0000000..4e5871c --- /dev/null +++ b/classes/iterators/IsisMethodIterator.php @@ -0,0 +1,63 @@ +class = $class; + $this->total = count($class->fields); + $this->keys = array_keys($class->fields); + } + + /** + * Rewind the Iterator to the first element. + */ + function rewind() { + $this->position = 0; + } + + /** + * Return the key of the current element. + */ + function key() { + $type = $this->class->getMapType($this->current()); + return $this->class->methodName($type); + } + + /** + * Return the current element. + */ + function current() { + return $this->class->fields[$this->keys[$this->position]]; + } + + /** + * Move forward to next element. The method should be callable, otherwise + * we move to the next position. + */ + function next() { + do { + ++$this->position; + } + while (!is_callable(array($this->class, $this->key())) && $this->valid()); + } + + /** + * Check if there is a current element after calls to rewind() or next(). + */ + function valid() { + return $this->position <= $this->total; + } +} -- cgit v1.2.3