aboutsummaryrefslogtreecommitdiff
path: root/classes/iterators/IsisEntryIterator.php
diff options
context:
space:
mode:
authorSilvio <silvio@devlet.com.br>2010-08-19 16:29:40 -0300
committerSilvio <silvio@devlet.com.br>2010-08-19 16:29:40 -0300
commit4cfb71f1f5c302061a7188081a17f0366a2da963 (patch)
tree91098ab4c9509687afba9c31b275c6381d452ceb /classes/iterators/IsisEntryIterator.php
parenta9033a0f4ce19122d4aad932344abf4fbe3b29cd (diff)
downloadcinisis-4cfb71f1f5c302061a7188081a17f0366a2da963.tar.gz
cinisis-4cfb71f1f5c302061a7188081a17f0366a2da963.tar.bz2
Adding IsisEntryIterator
Diffstat (limited to 'classes/iterators/IsisEntryIterator.php')
-rw-r--r--classes/iterators/IsisEntryIterator.php66
1 files changed, 66 insertions, 0 deletions
diff --git a/classes/iterators/IsisEntryIterator.php b/classes/iterators/IsisEntryIterator.php
new file mode 100644
index 0000000..6a1d72c
--- /dev/null
+++ b/classes/iterators/IsisEntryIterator.php
@@ -0,0 +1,66 @@
+<?php
+
+/**
+ * Isis entry iterator. Iterates over all entries in
+ * the database.
+ */
+class IsisEntryIterator implements Iterator
+{
+ private $start;
+ private $entry;
+ private $entries;
+
+ /**
+ * Constructor.
+ *
+ * @param $class
+ * Instance of IsisConnector or child class.
+ *
+ * @param $entry
+ * Start entry number to iterate from.
+ */
+ public function __construct($class, $entry = 1) {
+ // Read the first value.
+ $class->read($entry);
+
+ // Setup.
+ $this->class = $class;
+ $this->entry = $this->start = $entry;
+ $this->entries = $class->entries;
+ }
+
+ /**
+ * Rewind the Iterator to the first element.
+ */
+ function rewind() {
+ $this->entry = $this->start;
+ }
+
+ /**
+ * Return the key of the current element.
+ */
+ function key() {
+ return $this->entry;
+ }
+
+ /**
+ * Return the current element.
+ */
+ function current() {
+ return $this->class->result;
+ }
+
+ /**
+ * Move forward to next element.
+ */
+ function next() {
+ $this->class->read(++$this->entry);
+ }
+
+ /**
+ * Check if there is a current element after calls to rewind() or next().
+ */
+ function valid() {
+ return $this->entry <= $this->entries;
+ }
+}