From 4c138708edef5b4ed958a252e9d6038ad0a78ccc Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Fri, 29 Nov 2024 15:46:34 +0400 Subject: [PATCH] suivi index du row --- php/src/file/tab/AbstractBuilder.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/php/src/file/tab/AbstractBuilder.php b/php/src/file/tab/AbstractBuilder.php index 457505d..93b818b 100644 --- a/php/src/file/tab/AbstractBuilder.php +++ b/php/src/file/tab/AbstractBuilder.php @@ -33,6 +33,7 @@ abstract class AbstractBuilder extends TempStream implements IBuilder { $rows = $params["rows"] ?? null; if (is_callable($rows)) $rows = $rows(); $this->rows = $rows; + $this->index = 0; $cookFunc = $params["cook_func"] ?? null; $cookCtx = $cookArgs = null; if ($cookFunc !== null) { @@ -55,6 +56,8 @@ abstract class AbstractBuilder extends TempStream implements IBuilder { protected ?iterable $rows; + protected int $index; + protected ?string $output; protected ?array $cookCtx; @@ -89,14 +92,14 @@ abstract class AbstractBuilder extends TempStream implements IBuilder { $row = nur_func::_call($this->cookCtx, $args); } if ($row !== null) { - foreach ($row as &$value) { + foreach ($row as &$col) { # formatter les dates - if ($value instanceof DateTime) { - $value = $value->format(); - } elseif ($value instanceof DateTimeInterface) { - $value = DateTime::with($value)->format(); + if ($col instanceof DateTime) { + $col = $col->format(); + } elseif ($col instanceof DateTimeInterface) { + $col = DateTime::with($col)->format(); } - }; unset($value); + }; unset($col); } return $row; } @@ -106,6 +109,7 @@ abstract class AbstractBuilder extends TempStream implements IBuilder { if ($row === null) return; $this->writeHeaders(array_keys($row)); $this->_write($row, $colsStyle, $rowStyle); + $this->index++; } function writeAll(?iterable $rows=null, ?array $rowStyle=null): void {