refactor(php): 简化属性类型解析逻辑

- 移除手动类型映射逻辑,统一使用 parseTypeDecl 方法处理
- 添加 propClass 变量存储属性类信息
- 将解析后的类型直接赋值给属性定义对象
- 确保所有属性类型都通过标准方法进行解析和转换
pull/1/head
韩天峰 3 months ago
parent 96b4fefb58
commit 83a81e8df8
  1. 10
      src/Php/Preprocessor.php

@ -269,14 +269,10 @@ class Preprocessor extends CompilerBase
if ($this->classDef->hasProperty($name)) {
$this->fatalError($param, "Duplicate property `{$name}`");
}
// 将类型标准化为内部类型格式(如 array -> php::Array)
if ($type instanceof NodeAbstract) {
$dummyClass = '';
$propType = $this->parseTypeDecl($type, self::DECL_TYPE_OF_PROPERTY, $dummyClass);
} else {
$propType = $this->zendTypeMap[strtolower($type)] ?? self::TYPE_VAR;
}
$propClass = '';
$propType = $this->parseTypeDecl($type, self::DECL_TYPE_OF_PROPERTY, $propClass);
$propertyDef = new PropertyDef($name, $param->flags, $propType, $default, $nullable);
$propertyDef->class = $propClass;
$this->classDef->properties[$name] = $propertyDef;
}
if ($param->variadic) {

Loading…
Cancel
Save