From b9ef6604ea1d62a1e23bed37c5a3e96b8733da97 Mon Sep 17 00:00:00 2001 From: Silvio Date: Thu, 1 Jul 2010 12:08:09 -0300 Subject: Adding IsisMethodIterator --- classes/IsisMethodIterator.php | 62 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 classes/IsisMethodIterator.php (limited to 'classes/IsisMethodIterator.php') diff --git a/classes/IsisMethodIterator.php b/classes/IsisMethodIterator.php new file mode 100644 index 0000000..0cb7dd4 --- /dev/null +++ b/classes/IsisMethodIterator.php @@ -0,0 +1,62 @@ +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. + */ + 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