fix(php): 修复目标名称验证逻辑

- 在无效标识符错误消息中显示实际的目标名称
- 在保留关键字错误消息中显示实际的目标名称
- 添加目录名称冲突检查以防止覆盖现有目录
- 统一错误消息格式使用反引号包围目标名称
pull/1/head
韩天峰 6 months ago
parent 6a9b75d91f
commit 7b4eeefb19
  1. 9
      src/Php/Translator.php

@ -132,11 +132,16 @@ class Translator extends Preprocessor
}
$name = str_replace(['-', '*'], '_', $name);
if (!preg_match('/^[a-zA-Z0-9_]+$/', $name)) {
$this->climate->red('The target name must be a valid identifier');
$this->climate->red('The target name `' . $name . '` must be a valid identifier');
exit(1);
}
if (in_array($name, Constants::CPP_RESERVED_NAMES)) {
$this->climate->red('The target name [' . $name . '] must not be a reserved keyword');
$this->climate->red('The target name `' . $name . '` must not be a reserved keyword');
exit(1);
}
$realTargetPath = $this->rootPath . '/' . $name;
if (is_dir($realTargetPath)) {
$this->climate->red('The target name `' . $name . '` must not be a directory');
exit(1);
}
$this->targetName = $name;

Loading…
Cancel
Save