diff options
author | Silvio <silvio@devlet.com.br> | 2010-07-01 12:08:09 -0300 |
---|---|---|
committer | Silvio <silvio@devlet.com.br> | 2010-07-01 12:08:09 -0300 |
commit | b9ef6604ea1d62a1e23bed37c5a3e96b8733da97 (patch) | |
tree | e1fd2fe691215c488181a99fa145df8d49c5fc91 | |
parent | 833f13ca5c2bc5a96f82388b22cf1ca5a445c07b (diff) | |
download | cinisis-b9ef6604ea1d62a1e23bed37c5a3e96b8733da97.tar.gz cinisis-b9ef6604ea1d62a1e23bed37c5a3e96b8733da97.tar.bz2 |
Adding IsisMethodIterator
-rw-r--r-- | classes/IsisMethodIterator.php | 62 | ||||
-rw-r--r-- | classes/IsisSubfieldIterator.php | 1 |
2 files changed, 63 insertions, 0 deletions
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 @@ +<?php + +/** + * Iterates over all callable methods for database mapping. + */ +class IsisMethodIterator implements Iterator +{ + private $total = 0; + private $class; + private $keys; + + /** + * Constructor. + * + * @param $class + * Instance of IsisConnector or child class. + */ + public function __construct($class) { + $this->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; + } +} diff --git a/classes/IsisSubfieldIterator.php b/classes/IsisSubfieldIterator.php index ad1851d..70ff07f 100644 --- a/classes/IsisSubfieldIterator.php +++ b/classes/IsisSubfieldIterator.php @@ -15,6 +15,7 @@ class IsisSubfieldIterator implements Iterator $this->field = $field; $this->subfields = $class->getSubfields($field); $this->keys = array_values($this->subfields); + $this->total = count($this->class->result[$field['name']); print_r($field); } |