feat(config): add ext-deps alias for extension-dependencies configuration

- Added support for `ext-deps` as equivalent shorthand name for `extension-dependencies`
- Implemented validation to prevent using both config names simultaneously
- Updated documentation to reflect the new alias and usage restrictions
- Added test cases to verify ext-deps alias parsing works correctly
- Added test cases to ensure configuration error occurs when both names are used
- Refactored Translator.php to handle both configuration key variants
- Maintained backward compatibility with existing extension-dependencies usage
master
韩天峰 19 hours ago
parent 1118c1e8ec
commit 178636a577
  1. 2
      docs/COMPILER_CLI.md
  2. 36
      phpunit/src/CompilerBaseApiTest.php
  3. 14
      src/Translator.php

@ -127,6 +127,8 @@ extension-dependencies:
- curl
```
`ext-deps` 是等价的简写名称。一个项目中只能使用其中一个配置名;同时出现 `extension-dependencies``ext-deps` 会产生配置错误。
编译器会为每一项生成 `ZEND_MOD_REQUIRED`。Zend 在加载 TypePHP 模块时检查这些扩展是否已加载。该配置不表示原生链接库;C/C++ 链接依赖仍使用 `link-libs`
## 查看权威帮助

@ -471,6 +471,40 @@ YAML);
$this->invokeMethod('parseProjectYaml', $projectFile);
}
public function testParseProjectYamlSupportsExtDepsAlias(): void
{
$projectFile = $this->createProjectFile(<<<'YAML'
sources:
- main.php
ext-deps:
- pdo_mysql
- curl
- curl
YAML);
$this->invokeMethod('parseProjectYaml', $projectFile);
$this->assertSame(['pdo_mysql', 'curl'], $this->compiler->getExtensionDependencies());
}
public function testParseProjectYamlRejectsBothExtensionDependencyNames(): void
{
$projectFile = $this->createProjectFile(<<<'YAML'
sources:
- main.php
extension-dependencies:
- pdo_mysql
ext-deps:
- curl
YAML);
$this->expectException(TestError::class);
$this->expectExceptionMessage(
'`extension-dependencies` and `ext-deps` cannot be used together',
);
$this->invokeMethod('parseProjectYaml', $projectFile);
}
public function testExtensionDependenciesAreWrittenToZendModuleEntry(): void
{
global $translator;
@ -479,7 +513,7 @@ YAML);
$projectFile = $this->createProjectFile(<<<'YAML'
sources:
- main.php
extension-dependencies:
ext-deps:
- pdo_mysql
- curl
YAML);

@ -2580,14 +2580,20 @@ CODE;
// Required PHP modules. These are emitted as zend_module_dep entries;
// they are unrelated to native libraries configured through link-libs.
if (array_key_exists('extension-dependencies', $cfg)) {
$dependencies = $cfg['extension-dependencies'];
$hasExtensionDependencies = array_key_exists('extension-dependencies', $cfg);
$hasExtensionDependenciesAlias = array_key_exists('ext-deps', $cfg);
if ($hasExtensionDependencies && $hasExtensionDependenciesAlias) {
$this->error('`extension-dependencies` and `ext-deps` cannot be used together');
}
if ($hasExtensionDependencies || $hasExtensionDependenciesAlias) {
$configKey = $hasExtensionDependencies ? 'extension-dependencies' : 'ext-deps';
$dependencies = $cfg[$configKey];
if (!is_array($dependencies)) {
$this->error('`extension-dependencies` must be array');
$this->error("`{$configKey}` must be array");
}
foreach ($dependencies as $dependency) {
if (!is_string($dependency) || trim($dependency) === '') {
$this->error('Each `extension-dependencies` entry must be a non-empty string');
$this->error("Each `{$configKey}` entry must be a non-empty string");
}
$dependency = trim($dependency);
if (str_contains($dependency, "\0")) {

Loading…
Cancel
Save