From e55da7297df29ed58768e1f245c51b81a1be77ad Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Thu, 18 Jun 2026 11:50:19 +0800 Subject: [PATCH] =?UTF-8?q?feat(compiler):=20=E6=B7=BB=E5=8A=A0=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E7=9B=AE=E5=BD=95=E5=8F=82=E6=95=B0=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 CompilerBase 中添加 outputDir 属性用于存储 -o 参数指定的输出目录 - 实现将目标文件路径与输出目录进行拼接的功能 - 在 Translator 中解析输出参数中的路径分隔符并分离目录和文件名 - 支持通过 -o 参数直接指定完整的输出路径包括目录结构 --- src/Php/CompilerBase.php | 5 +++++ src/Php/Translator.php | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 6ce94775..e0ea530c 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -334,6 +334,7 @@ class CompilerBase extends \PhpAot\Core\Translator protected bool $bigintTypes = false; protected string $rootPath; protected string $buildDir; + protected string $outputDir = ''; // -o 参数指定的输出目录 protected int $debugLine = 0; protected CLImate $climate; protected bool $stubFile = false; @@ -2391,6 +2392,10 @@ class CompilerBase extends \PhpAot\Core\Translator $targetFile .= $extension; } + if ($this->outputDir !== '') { + $targetFile = rtrim($this->outputDir, '/\\') . '/' . $targetFile; + } + return $targetFile; } diff --git a/src/Php/Translator.php b/src/Php/Translator.php index 196eeebd..b776fea0 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -412,6 +412,11 @@ class Translator extends Preprocessor if ($this->climate->arguments->defined('output')) { $name = $this->climate->arguments->get('output'); } + // 如果指定了路径(包含目录分隔符),提取目录和文件名 + if (str_contains($name, '/') || str_contains($name, '\\')) { + $this->outputDir = dirname($name); + $name = basename($name); + } $name = str_replace(['-', '*'], '_', $name); if (!preg_match('/^[a-zA-Z0-9_]+$/', $name)) { $this->climate->red('The target name `' . $name . '` must be a valid identifier');