mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-23 08:35:35 +08:00
change phar writable checker to FileSystem
This commit is contained in:
@@ -6,6 +6,7 @@ namespace ZM\Command;
|
|||||||
|
|
||||||
use Symfony\Component\Console\Attribute\AsCommand;
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
use ZM\Exception\FileSystemException;
|
||||||
use ZM\Store\FileSystem;
|
use ZM\Store\FileSystem;
|
||||||
use ZM\Store\PharHelper;
|
use ZM\Store\PharHelper;
|
||||||
|
|
||||||
@@ -27,6 +28,7 @@ class BuildCommand extends Command
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws \PharException
|
* @throws \PharException
|
||||||
|
* @throws FileSystemException
|
||||||
*/
|
*/
|
||||||
protected function handle(): int
|
protected function handle(): int
|
||||||
{
|
{
|
||||||
@@ -40,7 +42,7 @@ class BuildCommand extends Command
|
|||||||
}
|
}
|
||||||
$target = $build_dir . '/' . $target;
|
$target = $build_dir . '/' . $target;
|
||||||
// 确认 Phar 文件可以写入
|
// 确认 Phar 文件可以写入
|
||||||
PharHelper::ensurePharFileWritable($target);
|
FileSystem::ensureFileWritable($target);
|
||||||
|
|
||||||
$this->comment("目标文件:{$target}");
|
$this->comment("目标文件:{$target}");
|
||||||
|
|
||||||
|
|||||||
9
src/ZM/Exception/FileSystemException.php
Normal file
9
src/ZM/Exception/FileSystemException.php
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace ZM\Exception;
|
||||||
|
|
||||||
|
class FileSystemException extends ZMException
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -290,7 +290,7 @@ class PluginManager
|
|||||||
$phar_name = $plugin->getName() . '_' . $plugin->getVersion() . '.phar';
|
$phar_name = $plugin->getName() . '_' . $plugin->getVersion() . '.phar';
|
||||||
$phar_name = zm_dir($build_dir . '/' . $phar_name);
|
$phar_name = zm_dir($build_dir . '/' . $phar_name);
|
||||||
// 判断文件如果存在的话是否是可写的
|
// 判断文件如果存在的话是否是可写的
|
||||||
PharHelper::ensurePharFileWritable($phar_name);
|
FileSystem::ensureFileWritable($phar_name);
|
||||||
// 文件存在先删除
|
// 文件存在先删除
|
||||||
if (file_exists($phar_name)) {
|
if (file_exists($phar_name)) {
|
||||||
$command_context?->info('Phar 文件 ' . $phar_name . ' 已存在,删除中...');
|
$command_context?->info('Phar 文件 ' . $phar_name . ' 已存在,删除中...');
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace ZM\Store;
|
namespace ZM\Store;
|
||||||
|
|
||||||
|
use ZM\Exception\FileSystemException;
|
||||||
use ZM\Utils\ZMUtil;
|
use ZM\Utils\ZMUtil;
|
||||||
|
|
||||||
class FileSystem
|
class FileSystem
|
||||||
@@ -83,12 +84,24 @@ class FileSystem
|
|||||||
/**
|
/**
|
||||||
* 创建目录(如果不存在)
|
* 创建目录(如果不存在)
|
||||||
*
|
*
|
||||||
* @param string $path 目录路径
|
* @param string $path 目录路径
|
||||||
|
* @throws FileSystemException
|
||||||
*/
|
*/
|
||||||
public static function createDir(string $path): void
|
public static function createDir(string $path): void
|
||||||
{
|
{
|
||||||
if (!is_dir($path) && !mkdir($path, 0755, true) && !is_dir($path)) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user