From 62c0c46f12cbeba2dc05388ca7067a5f62f43430 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Mon, 25 Nov 2024 14:06:49 +0400 Subject: [PATCH] modifs.mineures sans commentaires --- php/src/ValueException.php | 5 +++++ php/src/file.php | 2 +- php/src/file/csv/TAbstractReader.php | 2 +- php/src/file/web/Upload.php | 11 ++++++++--- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/php/src/ValueException.php b/php/src/ValueException.php index 11e3689..12813d2 100644 --- a/php/src/ValueException.php +++ b/php/src/ValueException.php @@ -44,6 +44,11 @@ class ValueException extends UserException { return new static(self::message(null, $message, $kind, $prefix, " should not be null")); } + static final function check_null($value, ?string $kind=null, ?string $prefix=null, ?string $message=null) { + if ($value === null) throw static::null($kind, $prefix, $message); + return $value; + } + static final function invalid_kind($value=null, ?string $kind=null, ?string $prefix=null, ?string $message=null): self { return new static(self::message($value, $message, $kind, $prefix, " is invalid")); } diff --git a/php/src/file.php b/php/src/file.php index bae8159..feaa12c 100644 --- a/php/src/file.php +++ b/php/src/file.php @@ -29,7 +29,7 @@ class file { return $file; } - static function writer($output, ?string $mode=null, ?callable $func=null): FileWriter { + static function writer($output, ?string $mode="w+b", ?callable $func=null): FileWriter { $file = new FileWriter(self::fix_dash($output), $mode); if ($func !== null) { try { diff --git a/php/src/file/csv/TAbstractReader.php b/php/src/file/csv/TAbstractReader.php index 3b17014..ed59776 100644 --- a/php/src/file/csv/TAbstractReader.php +++ b/php/src/file/csv/TAbstractReader.php @@ -22,7 +22,7 @@ trait TAbstractReader { $params["ss_type"] = "xlsx"; } } - return new $class($reader->tmpName, $params); + return new $class($reader->getFile(), $params); } if (is_string($reader)) { diff --git a/php/src/file/web/Upload.php b/php/src/file/web/Upload.php index 5e49584..ce4d19b 100644 --- a/php/src/file/web/Upload.php +++ b/php/src/file/web/Upload.php @@ -4,6 +4,7 @@ namespace nulib\file\web; use nulib\cl; use nulib\file\FileReader; use nulib\os\path; +use nulib\os\sh; use nulib\php\coll\BaseArray; use nulib\ValueException; @@ -103,6 +104,7 @@ class Upload extends BaseArray { function moveTo(string $dest): bool { if ($this->file === null) { + sh::mkdirof($dest); $moved = move_uploaded_file($this->tmpName, $dest); if ($moved) $this->file = $dest; } else { @@ -111,8 +113,11 @@ class Upload extends BaseArray { return $moved; } - function getFile(): FileReader { - $file = $this->file ?? $this->tmpName; - return new FileReader($file, "r+b"); + function getFile(): string { + return $this->file ?? $this->tmpName; + } + + function getReader(): FileReader { + return new FileReader($this->getFile(), "r+b"); } }