aboutsummaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
Diffstat (limited to 'classes')
-rw-r--r--classes/IsisConnector.php4
-rw-r--r--classes/IsisMethodIterator.php2
-rw-r--r--classes/IsisRowIterator.php58
3 files changed, 61 insertions, 3 deletions
diff --git a/classes/IsisConnector.php b/classes/IsisConnector.php
index 3978d0b..1111672 100644
--- a/classes/IsisConnector.php
+++ b/classes/IsisConnector.php
@@ -96,7 +96,7 @@ class IsisConnector {
* Field data.
*/
public function getFields($field) {
- for ($row = 0; $row <= $this->getRows($field); $row++) {
+ foreach (new IsisRowIterator($this, $field) as $row) {
$values[$row] = $this->getField($field, $row);
}
@@ -137,7 +137,7 @@ class IsisConnector {
* Subfield data.
*/
public function getSubfields($field, $subfield) {
- for ($row = 0; $row <= $this->getRows($field); $row++) {
+ foreach (new IsisRowIterator($this, $field) as $row) {
$values[$row] = $this->getSubfield($field, $subfield, $row);
}
diff --git a/classes/IsisMethodIterator.php b/classes/IsisMethodIterator.php
index 51820ed..4e5871c 100644
--- a/classes/IsisMethodIterator.php
+++ b/classes/IsisMethodIterator.php
@@ -44,7 +44,7 @@ class IsisMethodIterator implements Iterator
}
/**
- * Move forward to next element. The method should be callabe, otherwise
+ * Move forward to next element. The method should be callable, otherwise
* we move to the next position.
*/
function next() {
diff --git a/classes/IsisRowIterator.php b/classes/IsisRowIterator.php
new file mode 100644
index 0000000..a81373e
--- /dev/null
+++ b/classes/IsisRowIterator.php
@@ -0,0 +1,58 @@
+<?php
+
+/**
+ * Iterates over all rows from a field result.
+ */
+class IsisRowIterator implements Iterator
+{
+ private $position = 0;
+ private $total = 0;
+
+ /**
+ * Constructor.
+ *
+ * @param $class
+ * Instance of IsisConnector or child class.
+ *
+ * @param $field
+ * Field to iterate over.
+ */
+ public function __construct($class, $field) {
+ $this->total = $class->getRows($field);
+ }
+
+ /**
+ * Rewind the Iterator to the first element.
+ */
+ function rewind() {
+ $this->position = 0;
+ }
+
+ /**
+ * Return the key of the current element.
+ */
+ function key() {
+ return $this->position;
+ }
+
+ /**
+ * Return the current element.
+ */
+ function current() {
+ return $this->position;
+ }
+
+ /**
+ * Move forward to next element.
+ */
+ function next() {
+ ++$this->position;
+ }
+
+ /**
+ * Check if there is a current element after calls to rewind() or next().
+ */
+ function valid() {
+ return $this->position <= $this->total;
+ }
+}