change phar writable checker to FileSystem

This commit is contained in:
Jerry
2023-02-01 16:59:54 +08:00
parent 60382a98f6
commit 2d2660c8f3
5 changed files with 28 additions and 16 deletions

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace ZM\Store;
use ZM\Exception\FileSystemException;
use ZM\Utils\ZMUtil;
class FileSystem
@@ -83,12 +84,24 @@ class FileSystem
/**
* 创建目录(如果不存在)
*
* @param string $path 目录路径
* @param string $path 目录路径
* @throws FileSystemException
*/
public static function createDir(string $path): void
{
if (!is_dir($path) && !mkdir($path, 0755, true) && !is_dir($path)) {
throw new \RuntimeException(sprintf('无法建立目录:%s', $path));
throw new FileSystemException(sprintf('无法建立目录:%s', $path));
}
}
/**
* 调用该方法将确认传入的文件是否可写,如果不可写将抛出 FileSystemException 异常。
* @throws FileSystemException
*/
public static function ensureFileWritable(string $phar_path): void
{
if (file_exists($phar_path) && !is_writable($phar_path)) {
throw new FileSystemException('目标文件不可写:' . $phar_path);
}
}

View File

@@ -37,16 +37,4 @@ class PharHelper
}
}
}
/**
* 调用该方法将确认传入的 Phar 文件是否可写,如果不可写将抛出 \PharException 异常。
*
* @throws \PharException
*/
public static function ensurePharFileWritable(string $phar_path): void
{
if (file_exists($phar_path) && !is_writable($phar_path)) {
throw new \PharException('目标文件不可写:' . $phar_path);
}
}
}