From 1c8d0a053e4cf8af56930d7272be96edd8d045dd Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Tue, 4 Feb 2025 09:07:08 +0400 Subject: [PATCH] =?UTF-8?q?pr=C3=A9paration=20ajout=20Cursor::cols?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/php/coll/Cursor.php | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/php/coll/Cursor.php b/src/php/coll/Cursor.php index 884f449..f1ec9d9 100644 --- a/src/php/coll/Cursor.php +++ b/src/php/coll/Cursor.php @@ -11,9 +11,20 @@ use Traversable; * Class Cursor: parcours des lignes itérable * * @property-read array|null $value alias pour $row - * @property-read iterable|null $rows + * @property-read iterable|null $rows la source des lignes */ class Cursor implements Iterator { + const PARAMS_SCHEMA = [ + "rows" => ["?iterable"], + "rows_func" => ["?callable"], + "cols" => ["?array"], + "cols_func" => ["?callable"], + "map" => ["?array"], + "map_func" => ["?callable"], + "filter" => ["?array"], + "filter_func" => ["?callable"], + ]; + /** * mapper le tableau source $row selon les règles suivantes illustrées dans * l'exemple suivant: @@ -129,15 +140,22 @@ class Cursor implements Iterator { /** un générateur de lignes */ private ?Traversable $rowsGenerator; - /** une fonction qui retourne une instance de {@link iterable} */ + /** une fonction de signature function(Cursor):?iterable */ private ?func $rowsFunc; + /** une fonction de signature function(Cursor):?array */ + private ?func $colsFunc; + + /** une fonction de signature function(Cursor):?array */ private ?func $mapFunc; + /** une fonction de signature function(Cursor):bool */ private ?func $filterFunc; protected ?iterable $rows; + public ?array $cols; + public int $index; public int $origIndex; @@ -185,6 +203,7 @@ class Cursor implements Iterator { $map = $this->mapFunc; while ($valid = iter::valid($this->rows)) { $this->raw = iter::current($this->rows, $this->key); + $this->key ??= $this->origIndex; $this->row = cl::withn($this->raw); if ($filter === null) $filtered = $this->filter(); else $filtered = $filter->invoke([$this]);