modifs.mineures sans commentaires
This commit is contained in:
parent
4285804be4
commit
6cb66688ec
|
@ -4,6 +4,7 @@ namespace nur\sery\file\csv;
|
|||
use DateTimeInterface;
|
||||
use nur\sery\cl;
|
||||
use nur\sery\file\TempStream;
|
||||
use nur\sery\os\path;
|
||||
use nur\sery\php\func;
|
||||
use nur\sery\php\time\DateTime;
|
||||
use nur\sery\web\http;
|
||||
|
@ -118,7 +119,9 @@ abstract class AbstractBuilder extends TempStream {
|
|||
if ($this->sentHeaders) return;
|
||||
$this->_sendContentType();
|
||||
$output = $this->output;
|
||||
if ($output !== null) http::download_as($output);
|
||||
if ($output !== null) {
|
||||
http::download_as(path::filename($output));
|
||||
}
|
||||
$this->sentHeaders = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,30 @@
|
|||
<?php
|
||||
namespace nur\sery\file\csv;
|
||||
|
||||
use nur\sery\file\web\Upload;
|
||||
use nur\sery\os\path;
|
||||
use nur\sery\ValueException;
|
||||
|
||||
trait TAbstractBuilder {
|
||||
/** @param Upload|string|array $builder */
|
||||
static function with($builder): self {
|
||||
if ($builder instanceof self) return $builder;
|
||||
elseif (is_string($builder)) return new static($builder);
|
||||
elseif (is_array($builder)) return new static(null, $builder);
|
||||
else throw ValueException::invalid_type($builder, self::class);
|
||||
$class = null;
|
||||
if ($builder instanceof Upload) {
|
||||
# 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use nur\sery\os\path;
|
|||
use nur\sery\ValueException;
|
||||
|
||||
trait TAbstractReader {
|
||||
/** @param Upload|string|array */
|
||||
/** @param Upload|string|array $reader */
|
||||
static function with($reader): self {
|
||||
if ($reader instanceof self) return $reader;
|
||||
$class = null;
|
||||
|
|
Loading…
Reference in New Issue