aboutsummaryrefslogtreecommitdiff
path: root/includes/vendor/aura/sql/src/Iterator/AbstractIterator.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/vendor/aura/sql/src/Iterator/AbstractIterator.php')
-rw-r--r--includes/vendor/aura/sql/src/Iterator/AbstractIterator.php114
1 files changed, 114 insertions, 0 deletions
diff --git a/includes/vendor/aura/sql/src/Iterator/AbstractIterator.php b/includes/vendor/aura/sql/src/Iterator/AbstractIterator.php
new file mode 100644
index 0000000..895fd4e
--- /dev/null
+++ b/includes/vendor/aura/sql/src/Iterator/AbstractIterator.php
@@ -0,0 +1,114 @@
+<?php
+/**
+ *
+ * This file is part of Aura for PHP.
+ *
+ * @license http://opensource.org/licenses/bsd-license.php BSD
+ *
+ */
+namespace Aura\Sql\Iterator;
+
+use Iterator;
+use PDOStatement;
+
+/**
+ *
+ * A base class for iterators.
+ *
+ * @package Aura.Sql
+ *
+ */
+abstract class AbstractIterator implements Iterator
+{
+ /**
+ *
+ * PDO statement.
+ *
+ * @var PDOStatement
+ *
+ */
+ protected $statement;
+
+ /**
+ *
+ * Current row value.
+ *
+ * @var mixed
+ *
+ */
+ protected $row;
+
+ /**
+ *
+ * Current key.
+ *
+ * @var mixed
+ *
+ */
+ protected $key = -1;
+
+ /**
+ *
+ * Frees memory when object is destroyed.
+ *
+ */
+ public function __destruct()
+ {
+ $this->statement->closeCursor();
+ unset($this->statement);
+ }
+
+ /**
+ *
+ * Moves row set pointer to first element.
+ *
+ */
+ public function rewind()
+ {
+ $this->key = -1;
+ $this->next();
+ }
+
+ /**
+ *
+ * Returns value at current position.
+ *
+ * @return mixed
+ *
+ */
+ public function current()
+ {
+ return $this->row;
+ }
+
+ /**
+ *
+ * Returns key at current position.
+ *
+ * @return mixed
+ *
+ */
+ public function key()
+ {
+ return $this->key;
+ }
+
+ /**
+ *
+ * Fetches next row from statement.
+ *
+ */
+ abstract public function next();
+
+ /**
+ *
+ * Detects if iterator state is valid.
+ *
+ * @return bool
+ *
+ */
+ public function valid()
+ {
+ return $this->row !== false;
+ }
+}