modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2024-06-17 22:41:34 +04:00
parent d744775ccc
commit 378f5fa107
2 changed files with 34 additions and 0 deletions

View File

@ -36,6 +36,38 @@ class A {
return false;
}
/**
* s'assurer que $array est un tableau de $size éléments, en complétant avec
* des occurrences de $default si nécessaire
*
* @return bool true si le tableau a été modifié, false sinon
*/
static final function ensure_size(?array &$array, int $size, $default=null): bool {
$modified = false;
if ($array === null) {
$array = [];
$modified = true;
}
if ($size < 0) return $modified;
$count = count($array);
if ($count == $size) return $modified;
if ($count < $size) {
# agrandir le tableau
while ($count++ < $size) {
$array[] = $default;
}
return true;
}
# rétrécir le tableau
$tmparray = [];
foreach ($array as $key => $value) {
if ($size-- == 0) break;
$tmparray[$key] = $value;
}
$array = $tmparray;
return true;
}
static function merge(&$dest, ...$merges): void {
self::ensure_narray($dest);
$dest = cl::merge($dest, ...$merges);

View File

@ -1,6 +1,7 @@
<?php
namespace nur\sery\file\csv;
use nur\sery\A;
use nur\sery\php\time\Date;
use nur\sery\php\time\DateTime;
@ -71,6 +72,7 @@ abstract class AbstractReader implements IReader {
}
return false;
}
A::ensure_size($row, count($this->headers));
$row = array_combine($this->headers, $row);
return true;
}