fix(php): 修复文件编码检查和方法调用问题

- 添加了UTF-8编码检查以确保文件正确读取
- 更新了composer.json中的swoole/phpx依赖版本
- 修复了Translator中类名获取的方法调用
- 移除了UniversalMethodCall中不需要的返回类型参数
pull/1/head
韩天峰 3 months ago
parent 64e9d76770
commit f30a29a048
  1. 2
      composer.json
  2. 3
      src/Php/CompilerBase.php
  3. 2
      src/Php/Translator.php
  4. 4
      src/Php/UniversalMethodCall.php

@ -7,7 +7,7 @@
"marcj/topsort": "^2.0",
"symfony/var-dumper": "^8.0",
"symfony/yaml": "^8.0",
"swoole/phpx": "~2.1.6"
"swoole/phpx": "~2.3.0"
},
"require-dev": {
"phpunit/phpunit": "^10.4",

@ -5876,6 +5876,9 @@ class CompilerBase extends \PhpAot\Core\Translator
if (!$phpCode) {
throw new \Exception('Can not read file: ' . $file);
}
if (!mb_check_encoding($phpCode, 'UTF-8')) {
throw new \Exception('File encoding must be UTF-8, got: ' . mb_detect_encoding($phpCode, ['UTF-8', 'ISO-8859-1', 'GBK', 'Shift_JIS'], true) . ' in ' . $file);
}
$this->file = realpath($file);
$this->dir = dirname($this->file);
$this->stubFile = $this->isStubFile($file);

@ -1744,7 +1744,7 @@ CODE;
$traitMethods = [];
$traitConstants = [];
$traitProperties = [];
$classDef = $this->getClass($className);
$classDef = $this->getClass($className->toString());
foreach ($stmt->stmts as $classStmt) {
if ($classStmt instanceof Node\Stmt\ClassMethod) {

@ -592,7 +592,7 @@ trait UniversalMethodCall
'calc_dec' => '(' . $receiver . ' - 1)',
'direct_method' => $this->genUniversalDirectMethod($receiver, $def['method'], $expr->args, $def['int_cast_args'] ?? []),
'direct_method_mutate' => $this->genUniversalMutatingMethod($receiver, $def['method'], $expr->args),
'convert_fn' => $this->genUniversalConvertFn($receiver, $def['fn'], $def['return_type']),
'convert_fn' => $this->genUniversalConvertFn($receiver, $def['fn']),
'php_fn' => $this->genUniversalPhpFn($receiver, $def['fn'], $expr->args, $def['receiver_pos'] ?? 0, $def['const_args'] ?? []),
'php_fn_ref' => $this->genUniversalPhpFnRef($receiver, $def['fn'], $expr->args, $def['return_type']),
'cpp_fn' => $this->genUniversalCppFn($receiver, $def['fn'], $expr->args, $def['receiver_pos'] ?? 0),
@ -688,7 +688,7 @@ trait UniversalMethodCall
return '(' . $call . ', ' . $object . ')';
}
protected function genUniversalConvertFn(string $receiver, string $fn, string $type): string
protected function genUniversalConvertFn(string $receiver, string $fn): string
{
return 'php::' . $fn . '(' . $receiver . ')';
}

Loading…
Cancel
Save