diff options
Diffstat (limited to 'includes/vendor/aura/sql/src/Iterator')
6 files changed, 368 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; + } +} diff --git a/includes/vendor/aura/sql/src/Iterator/AllIterator.php b/includes/vendor/aura/sql/src/Iterator/AllIterator.php new file mode 100644 index 0000000..9d56a24 --- /dev/null +++ b/includes/vendor/aura/sql/src/Iterator/AllIterator.php @@ -0,0 +1,46 @@ +<?php +/** + * + * This file is part of Aura for PHP. + * + * @license http://opensource.org/licenses/bsd-license.php BSD + * + */ +namespace Aura\Sql\Iterator; + +use PDO; +use PDOStatement; + +/** + * + * The iterator equivalent of `fetchAll()`. + * + * @package Aura.Sql + * + */ +class AllIterator extends AbstractIterator +{ + /** + * + * Constructor. + * + * @param PDOStatement $statement PDO statement. + * + */ + public function __construct(PDOStatement $statement) + { + $this->statement = $statement; + $this->statement->setFetchMode(PDO::FETCH_ASSOC); + } + + /** + * + * Fetches next row from statement. + * + */ + public function next() + { + $this->row = $this->statement->fetch(); + $this->key ++; + } +} diff --git a/includes/vendor/aura/sql/src/Iterator/AssocIterator.php b/includes/vendor/aura/sql/src/Iterator/AssocIterator.php new file mode 100644 index 0000000..ea77a7a --- /dev/null +++ b/includes/vendor/aura/sql/src/Iterator/AssocIterator.php @@ -0,0 +1,49 @@ +<?php +/** + * + * This file is part of Aura for PHP. + * + * @license http://opensource.org/licenses/bsd-license.php BSD + * + */ +namespace Aura\Sql\Iterator; + +use PDO; +use PDOStatement; + +/** + * + * The iterator equivalent of `fetchAssoc()`. + * + * @package Aura.Sql + * + */ +class AssocIterator extends AbstractIterator +{ + /** + * + * Constructor. + * + * @param PDOStatement $statement PDO statement. + * + */ + public function __construct(PDOStatement $statement) + { + $this->statement = $statement; + $this->statement->setFetchMode(PDO::FETCH_ASSOC); + } + + /** + * + * Fetches next row from statement. + * + */ + public function next() + { + $this->row = $this->statement->fetch(); + $this->key = false; + if ($this->row !== false) { + $this->key = current($this->row); + } + } +} diff --git a/includes/vendor/aura/sql/src/Iterator/ColIterator.php b/includes/vendor/aura/sql/src/Iterator/ColIterator.php new file mode 100644 index 0000000..7be66e8 --- /dev/null +++ b/includes/vendor/aura/sql/src/Iterator/ColIterator.php @@ -0,0 +1,49 @@ +<?php +/** + * + * This file is part of Aura for PHP. + * + * @license http://opensource.org/licenses/bsd-license.php BSD + * + */ +namespace Aura\Sql\Iterator; + +use PDO; +use PDOStatement; + +/** + * + * The iterator equivalent of `fetchCol()`. + * + * @package Aura.Sql + * + */ +class ColIterator extends AbstractIterator +{ + /** + * + * Constructor. + * + * @param PDOStatement $statement PDO statement. + * + */ + public function __construct(PDOStatement $statement) + { + $this->statement = $statement; + $this->statement->setFetchMode(PDO::FETCH_NUM); + } + + /** + * + * Fetches next row from statement. + * + */ + public function next() + { + $this->row = $this->statement->fetch(); + if ($this->row !== false) { + $this->row = $this->row[0]; + } + $this->key ++; + } +} diff --git a/includes/vendor/aura/sql/src/Iterator/ObjectsIterator.php b/includes/vendor/aura/sql/src/Iterator/ObjectsIterator.php new file mode 100644 index 0000000..bbd08fc --- /dev/null +++ b/includes/vendor/aura/sql/src/Iterator/ObjectsIterator.php @@ -0,0 +1,60 @@ +<?php +/** + * + * This file is part of Aura for PHP. + * + * @license http://opensource.org/licenses/bsd-license.php BSD + * + */ +namespace Aura\Sql\Iterator; + +use PDO; +use PDOStatement; + +/** + * + * The iterator equivalent of `fetchObjects()`. + * + * @package Aura.Sql + * + */ +class ObjectsIterator extends AbstractIterator +{ + /** + * + * Constructor. + * + * @param PDOStatement $statement PDO statement. + * + * @param string $class_name The name of the class to create. + * + * @param array $ctor_args Arguments to pass to the object constructor. + * + */ + public function __construct( + PDOStatement $statement, + $class_name = 'StdClass', + array $ctor_args = array() + ) { + $this->statement = $statement; + $this->statement->setFetchMode(PDO::FETCH_CLASS, $class_name); + if ($ctor_args) { + $this->statement->setFetchMode( + PDO::FETCH_CLASS, + $class_name, + $ctor_args + ); + } + } + + /** + * + * Fetches next row from statement. + * + */ + public function next() + { + $this->row = $this->statement->fetch(); + $this->key ++; + } +} diff --git a/includes/vendor/aura/sql/src/Iterator/PairsIterator.php b/includes/vendor/aura/sql/src/Iterator/PairsIterator.php new file mode 100644 index 0000000..20c1a13 --- /dev/null +++ b/includes/vendor/aura/sql/src/Iterator/PairsIterator.php @@ -0,0 +1,50 @@ +<?php +/** + * + * This file is part of Aura for PHP. + * + * @license http://opensource.org/licenses/bsd-license.php BSD + * + */ +namespace Aura\Sql\Iterator; + +use PDO; +use PDOStatement; + +/** + * + * The iterator equivalent of `fetchPairs()`. + * + * @package Aura.Sql + * + */ +class PairsIterator extends AbstractIterator +{ + /** + * + * Constructor. + * + * @param PDOStatement $statement PDO statement. + * + */ + public function __construct(PDOStatement $statement) + { + $this->statement = $statement; + $this->statement->setFetchMode(PDO::FETCH_NUM); + } + + /** + * + * Fetches next row from statement. + * + */ + public function next() + { + $this->key = false; + $this->row = $this->statement->fetch(); + if ($this->row !== false) { + $this->key = $this->row[0]; + $this->row = $this->row[1]; + } + } +} |