add wrong usage exception

This commit is contained in:
crazywhalecc
2023-03-29 21:39:36 +08:00
parent d31e1b00e8
commit b0ac50941f
13 changed files with 67 additions and 18 deletions

View File

@@ -385,4 +385,13 @@ class FileSystem
throw new FileSystemException(sprintf('无法建立目录:%s', $path));
}
}
public static function writeFile(string $path, $content, ...$args): bool|string|int
{
$dir = pathinfo($path, PATHINFO_DIRNAME);
if (!is_dir($dir) && !mkdir($dir, 0755, true)) {
throw new FileSystemException('Write file failed, cannot create parent directory: ' . $dir);
}
return file_put_contents($path, $content, ...$args);
}
}