mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-23 16:45:35 +08:00
simplify duplicated composer executable getter
This commit is contained in:
@@ -6,6 +6,7 @@ namespace ZM\Utils\CodeGenerator;
|
||||
|
||||
use ZM\Exception\FileSystemException;
|
||||
use ZM\Store\FileSystem;
|
||||
use ZM\Utils\ZMUtil;
|
||||
|
||||
/**
|
||||
* Class PluginGenerator
|
||||
@@ -81,10 +82,7 @@ class PluginGenerator
|
||||
file_put_contents(zm_dir($plugin_base_dir . '/composer.json'), json_encode($composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
|
||||
// TODO: 寻找 PHP 运行环境和 Composer 是否在当前目录的情况
|
||||
chdir($plugin_base_dir);
|
||||
$env = getenv('COMPOSER_EXECUTABLE');
|
||||
if ($env === false) {
|
||||
$env = 'composer';
|
||||
}
|
||||
$env = ZMUtil::getComposerExecutable();
|
||||
passthru(PHP_BINARY . ' ' . escapeshellcmd($env) . ' dump-autoload');
|
||||
chdir(WORKING_DIR);
|
||||
return $plugin_base_dir;
|
||||
|
||||
@@ -27,4 +27,16 @@ class ZMUtil
|
||||
{
|
||||
return file_put_contents(($path ?? SOURCE_ROOT_DIR) . '/composer.json', json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前 Composer 二进制执行命令的初始位置
|
||||
*/
|
||||
public static function getComposerExecutable(): string
|
||||
{
|
||||
$env = getenv('COMPOSER_EXECUTABLE');
|
||||
if ($env === false) {
|
||||
$env = 'composer';
|
||||
}
|
||||
return $env;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user