modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2024-06-12 20:42:15 +04:00
parent 4285804be4
commit 6cb66688ec
3 changed files with 25 additions and 5 deletions

View File

@ -4,6 +4,7 @@ namespace nur\sery\file\csv;
use DateTimeInterface; use DateTimeInterface;
use nur\sery\cl; use nur\sery\cl;
use nur\sery\file\TempStream; use nur\sery\file\TempStream;
use nur\sery\os\path;
use nur\sery\php\func; use nur\sery\php\func;
use nur\sery\php\time\DateTime; use nur\sery\php\time\DateTime;
use nur\sery\web\http; use nur\sery\web\http;
@ -118,7 +119,9 @@ abstract class AbstractBuilder extends TempStream {
if ($this->sentHeaders) return; if ($this->sentHeaders) return;
$this->_sendContentType(); $this->_sendContentType();
$output = $this->output; $output = $this->output;
if ($output !== null) http::download_as($output); if ($output !== null) {
http::download_as(path::filename($output));
}
$this->sentHeaders = true; $this->sentHeaders = true;
} }

View File

@ -1,13 +1,30 @@
<?php <?php
namespace nur\sery\file\csv; namespace nur\sery\file\csv;
use nur\sery\file\web\Upload;
use nur\sery\os\path;
use nur\sery\ValueException; use nur\sery\ValueException;
trait TAbstractBuilder { trait TAbstractBuilder {
/** @param Upload|string|array $builder */
static function with($builder): self { static function with($builder): self {
if ($builder instanceof self) return $builder; if ($builder instanceof self) return $builder;
elseif (is_string($builder)) return new static($builder); $class = null;
elseif (is_array($builder)) return new static(null, $builder); if ($builder instanceof Upload) {
else throw ValueException::invalid_type($builder, self::class); # faire un builder dans le même format que le fichier uploadé
if ($builder->isExt(".csv")) $class = CsvBuilder::class;
else $class = static::class;
return $class($builder->name);
}
if (is_string($builder)) $builder = ["output" => $builder];
if (!is_array($builder)) {
throw ValueException::invalid_type($builder, self::class);
}
$input = $builder["output"] ?? null;
if (is_string($input) && path::ext($input) === ".csv") {
$class = CsvBuilder::class;
}
if ($class === null) $class = static::class;
return $class($builder);
} }
} }

View File

@ -6,7 +6,7 @@ use nur\sery\os\path;
use nur\sery\ValueException; use nur\sery\ValueException;
trait TAbstractReader { trait TAbstractReader {
/** @param Upload|string|array */ /** @param Upload|string|array $reader */
static function with($reader): self { static function with($reader): self {
if ($reader instanceof self) return $reader; if ($reader instanceof self) return $reader;
$class = null; $class = null;