aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--classes/IsisSubfieldIterator.php51
1 files changed, 51 insertions, 0 deletions
diff --git a/classes/IsisSubfieldIterator.php b/classes/IsisSubfieldIterator.php
new file mode 100644
index 0000000..ad1851d
--- /dev/null
+++ b/classes/IsisSubfieldIterator.php
@@ -0,0 +1,51 @@
+<?php
+
+// TODO: not working
+class IsisSubfieldIterator implements Iterator
+{
+ private $position = 0;
+ private $class;
+ private $field;
+ private $subfields;
+ private $keys;
+
+ public function __construct($class, $field)
+ {
+ $this->class = $class;
+ $this->field = $field;
+ $this->subfields = $class->getSubfields($field);
+ $this->keys = array_values($this->subfields);
+ print_r($field);
+ }
+
+ function subfield()
+ {
+ return $this->subfields[$this->key()];
+ }
+
+ function rewind()
+ {
+ $this->position = 0;
+ }
+
+ function current()
+ {
+ $value = $this->class->getSubfield($this->field, $this->subfield());
+ return $this->class->explodeValue($value);
+ }
+
+ function key()
+ {
+ return $this->keys[$this->position];
+ }
+
+ function next()
+ {
+ ++$this->position;
+ }
+
+ function valid()
+ {
+ return isset($this->keys[$this->position]) && ($this->current() != null);
+ }
+}