refactor(php): 优化模块名称处理逻辑

- 将直接访问 targetName 属性改为使用 getModuleName 方法
- 移除数字开头目标名的预处理逻辑
- 新增 getModuleName 方法处理数字开头的模块名
- 统一模块入口函数中的名称引用方式
pull/1/head
韩天峰 6 months ago
parent 0b5fb6fdd1
commit 24ea4d9806
  1. 2
      src/Php/CompilerBase.php
  2. 11
      src/Php/Translator.php
  3. 22
      src/template/extension.cc.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;
}

@ -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')) {

@ -95,7 +95,7 @@ foreach ($this->functions as $functionDef):
};
// clang-format on
PHP_MINIT_FUNCTION(<?=$this->targetName?>) {
PHP_MINIT_FUNCTION(<?=$this->getModuleName()?>) {
// class/interface class entries
<?php
foreach ($this->classCeList as $ce):
@ -159,7 +159,7 @@ foreach ($this->nativeConstants as $name => $const):
<?php endforeach; ?>
}
PHP_RINIT_FUNCTION(<?=$this->targetName?>) {
PHP_RINIT_FUNCTION(<?=$this->getModuleName()?>) {
php::request_init();
php_app_init();
@ -174,29 +174,29 @@ PHP_RINIT_FUNCTION(<?=$this->targetName?>) {
return SUCCESS;
}
PHP_RSHUTDOWN_FUNCTION(<?=$this->targetName?>) {
PHP_RSHUTDOWN_FUNCTION(<?=$this->getModuleName()?>) {
php_app_clean();
php::request_shutdown();
return SUCCESS;
}
zend_module_entry <?=$this->targetName?>_module_entry = {
zend_module_entry <?=$this->getModuleName()?>_module_entry = {
STANDARD_MODULE_HEADER,
"<?=$this->targetName?>",
"<?=$this->getModuleName()?>",
ext_functions,
PHP_MINIT(<?=$this->targetName?>),
PHP_MINIT(<?=$this->getModuleName()?>),
nullptr,
PHP_RINIT(<?=$this->targetName?>),
PHP_RSHUTDOWN(<?=$this->targetName?>),
PHP_RINIT(<?=$this->getModuleName()?>),
PHP_RSHUTDOWN(<?=$this->getModuleName()?>),
nullptr,
nullptr,
STANDARD_MODULE_PROPERTIES,
};
<?php if ($this->buildMode === 'ext'): ?>
ZEND_GET_MODULE(<?=$this->targetName?>);
ZEND_GET_MODULE(<?=$this->getModuleName()?>);
<?php else: ?>
zend_module_entry *<?= self::PREFIX . 'embed_' ?>get_module() {
return &<?= $this->targetName ?>_module_entry;
zend_module_entry *<?= Translator::PREFIX . 'embed_' ?>get_module() {
return &<?= $this->getModuleName() ?>_module_entry;
}
<?php endif; ?>
Loading…
Cancel
Save