Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/HuasoFoundries/phpPgAdmin6.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/Core/ArrayRecordset.php')
-rw-r--r--src/Core/ArrayRecordset.php98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/Core/ArrayRecordset.php b/src/Core/ArrayRecordset.php
new file mode 100644
index 00000000..2f555571
--- /dev/null
+++ b/src/Core/ArrayRecordset.php
@@ -0,0 +1,98 @@
+<?php
+
+/**
+ * PHPPgAdmin6
+ */
+
+namespace PHPPgAdmin\Core;
+
+use ADOFieldObject;
+use Countable;
+use PHPPgAdmin\Interfaces\RecordSet;
+
+/**
+ * @file
+ * Really simple RecordSet to allow printTable of arrays.
+ *
+ * Id: ArrayRecordSet.php,v 1.3 2007/01/10 01:46:28 soranzo Exp $
+ */
+
+/**
+ * Really simple RecordSet to allow printTable arrays.
+ * Mimics the behavior of an ADORecordset.
+ *
+ * Id: ArrayRecordSet.php,v 1.3 2007/01/10 01:46:28 soranzo Exp $
+ */
+class ArrayRecordset implements Countable, RecordSet
+{
+ public $EOF = false;
+
+ public $fields;
+
+ private $_array;
+
+ /**
+ * Constructor.
+ *
+ * @param array<array-key, mixed> $data The input array
+ */
+ public function __construct($data)
+ {
+ $this->_array = $data;
+ $this->fields = \reset($this->_array);
+
+ if (false === $this->fields) {
+ $this->EOF = true;
+ }
+ }
+
+ public function getIterator()
+ {
+ return $this->_array;
+ }
+
+ /**
+ * Returns the recordCount.
+ */
+ public function count(): int
+ {
+ return \count($this->_array);
+ }
+
+ public function FetchField($off = 0): ADOFieldObject
+ {
+ // offsets begin at 0
+
+ $o = new ADOFieldObject();
+
+ $o->name = \array_keys($this->fields)[$off] ?? null;
+ $value = $this->fields[$o->name ?? \random_bytes(64)] ?? null;
+ $o->type = get_debug_type($value);
+ $o->max_length = 1024;
+
+ return $o;
+ }
+
+ /**
+ * Counts the records in the instance array.
+ *
+ * @return int number of records in the instance array
+ */
+ public function RecordCount(): int
+ {
+ return $this->count();
+ }
+
+ /**
+ * Advance the internal pointer of the instance array
+ * if no more fields are left, marks the instance variable $EOF as true.
+ */
+ public function MoveNext(): void
+ {
+ $this->fields = \next($this->_array);
+
+ if (false === $this->fields) {
+ $this->EOF = true;
+ }
+ }
+}