modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2024-04-22 14:12:32 +04:00
parent 32a9239209
commit fd54686f1d
1 changed files with 16 additions and 3 deletions

View File

@ -269,10 +269,23 @@ class path {
return strpos($file, ".", $pos) !== false; 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); [$dir, $filename] = self::split($path);
if (self::ext($filename) === $replace_ext) { $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); $filename = self::basename($filename);
break;
}
}
} }
$filename .= $new_ext; $filename .= $new_ext;
return self::join($dir, $filename); return self::join($dir, $filename);