From fd54686f1d544dbf47fce195eb98467ceade8987 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Mon, 22 Apr 2024 14:12:32 +0400 Subject: [PATCH] modifs.mineures sans commentaires --- nur_src/path.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/nur_src/path.php b/nur_src/path.php index acb5a75..50490e2 100644 --- a/nur_src/path.php +++ b/nur_src/path.php @@ -269,10 +269,23 @@ class path { return strpos($file, ".", $pos) !== false; } - static final function ensure_ext(string $path, string $new_ext, ?string $replace_ext=null): string { + /** + * @param string $path + * @param string $new_ext + * @param string|array|null $replace_ext + * @return string + */ + static final function ensure_ext(string $path, string $new_ext, $replace_ext=null): string { [$dir, $filename] = self::split($path); - if (self::ext($filename) === $replace_ext) { - $filename = self::basename($filename); + $ext = self::ext($filename); + if ($ext !== null && $replace_ext !== null) { + if (is_string($replace_ext)) $replace_ext = [$replace_ext]; + foreach ($replace_ext as $old_ext) { + if ($ext === $old_ext) { + $filename = self::basename($filename); + break; + } + } } $filename .= $new_ext; return self::join($dir, $filename);