From 24ea4d9806861cbbae2348c2b34b27343c5cbf71 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Wed, 25 Feb 2026 11:50:28 +0800 Subject: [PATCH] =?UTF-8?q?refactor(php):=20=E4=BC=98=E5=8C=96=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E5=90=8D=E7=A7=B0=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将直接访问 targetName 属性改为使用 getModuleName 方法 - 移除数字开头目标名的预处理逻辑 - 新增 getModuleName 方法处理数字开头的模块名 - 统一模块入口函数中的名称引用方式 --- src/Php/CompilerBase.php | 2 +- src/Php/Translator.php | 11 ++++++++--- src/template/extension.cc.php | 22 +++++++++++----------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index f0eb01d8..f41427ef 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -3659,7 +3659,7 @@ class CompilerBase extends \PhpAot\Core\Translator if (!$this->hasNativeClass($class)) { return false; } - $classDef = $this->classes[$class]; + $classDef = $this->getClassDef($class); if (!$classDef->hasMethod($method)) { return false; } diff --git a/src/Php/Translator.php b/src/Php/Translator.php index 193a78f8..7fb32ac1 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -137,9 +137,6 @@ class Translator extends Preprocessor $this->climate->red('The target name [' . $name . '] must not be a reserved keyword'); exit(1); } - if (is_numeric($name)) { - $name = 'app_' . $name; - } $this->targetName = $name; } @@ -239,6 +236,14 @@ class Translator extends Preprocessor $this->localHeaders = []; } + public function getModuleName(): string + { + if (ctype_digit($this->targetName[0])) { + return 'app_' . $this->targetName; + } + return $this->targetName; + } + public function hasObjectFileCache(string $cppFile): bool { if (!$this->enableCache or $this->climate->arguments->defined('force')) { diff --git a/src/template/extension.cc.php b/src/template/extension.cc.php index a1065048..76d6e897 100644 --- a/src/template/extension.cc.php +++ b/src/template/extension.cc.php @@ -95,7 +95,7 @@ foreach ($this->functions as $functionDef): }; // clang-format on -PHP_MINIT_FUNCTION(targetName?>) { +PHP_MINIT_FUNCTION(getModuleName()?>) { // class/interface class entries classCeList as $ce): @@ -159,7 +159,7 @@ foreach ($this->nativeConstants as $name => $const): } -PHP_RINIT_FUNCTION(targetName?>) { +PHP_RINIT_FUNCTION(getModuleName()?>) { php::request_init(); php_app_init(); @@ -174,29 +174,29 @@ PHP_RINIT_FUNCTION(targetName?>) { return SUCCESS; } -PHP_RSHUTDOWN_FUNCTION(targetName?>) { +PHP_RSHUTDOWN_FUNCTION(getModuleName()?>) { php_app_clean(); php::request_shutdown(); return SUCCESS; } -zend_module_entry targetName?>_module_entry = { +zend_module_entry getModuleName()?>_module_entry = { STANDARD_MODULE_HEADER, - "targetName?>", + "getModuleName()?>", ext_functions, - PHP_MINIT(targetName?>), + PHP_MINIT(getModuleName()?>), nullptr, - PHP_RINIT(targetName?>), - PHP_RSHUTDOWN(targetName?>), + PHP_RINIT(getModuleName()?>), + PHP_RSHUTDOWN(getModuleName()?>), nullptr, nullptr, STANDARD_MODULE_PROPERTIES, }; buildMode === 'ext'): ?> -ZEND_GET_MODULE(targetName?>); +ZEND_GET_MODULE(getModuleName()?>); -zend_module_entry *get_module() { - return &targetName ?>_module_entry; +zend_module_entry *get_module() { + return &getModuleName() ?>_module_entry; } \ No newline at end of file