mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-09 03:22:51 +08:00
完成ENV配置编译打包
This commit is contained in:
@@ -167,13 +167,13 @@ class Dist extends Command
|
|||||||
$this->log('删除注释并生成版权声明');
|
$this->log('删除注释并生成版权声明');
|
||||||
$this->clearCommentAndGenerateCopyright();
|
$this->clearCommentAndGenerateCopyright();
|
||||||
|
|
||||||
|
|
||||||
$this->log('编译env配置信息');
|
$this->log('编译env配置信息');
|
||||||
// 根据配置pack_env扫描编译
|
$this->packEnv();
|
||||||
// $this->packEnv();
|
|
||||||
|
|
||||||
$this->log('编译所有代码以全命名空间路径调用');
|
$this->log('编译所有代码以全命名空间路径调用');
|
||||||
$this->packClassUseName();
|
$this->packClassUseName();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
@@ -416,9 +416,6 @@ class Dist extends Command
|
|||||||
|
|
||||||
public function packClassUseName()
|
public function packClassUseName()
|
||||||
{
|
{
|
||||||
// 删除无效的use
|
|
||||||
// 将所有的use类名混淆
|
|
||||||
|
|
||||||
$list_file = $this->tempFilesystem->listContents('', true);
|
$list_file = $this->tempFilesystem->listContents('', true);
|
||||||
|
|
||||||
|
|
||||||
@@ -580,16 +577,48 @@ class Dist extends Command
|
|||||||
|
|
||||||
public function packEnv()
|
public function packEnv()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
$env_pack_mode = Config::get('dist.pack_env.pack_env_mode');
|
||||||
|
|
||||||
|
if ($env_pack_mode == 3) {
|
||||||
|
$this->debug('跳过ENV配置打包');
|
||||||
|
return;
|
||||||
|
}
|
||||||
$list_files = $this->tempFilesystem->listContents('', true);
|
$list_files = $this->tempFilesystem->listContents('', true);
|
||||||
|
|
||||||
$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
|
$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
|
||||||
|
|
||||||
$prettyPrinter = new PrettyPrinterTools();
|
$pretty_printer = new PrettyPrinterTools();
|
||||||
|
|
||||||
foreach ($list_files as $item_file) {
|
foreach ($list_files as $item_file) {
|
||||||
$path = $item_file['path'];
|
$path = $item_file['path'];
|
||||||
|
|
||||||
|
|
||||||
|
$target_include = $this->getAllInclude();
|
||||||
|
|
||||||
|
$target_exclude = $this->getAllExclude();
|
||||||
|
|
||||||
|
if (!$this->checkPregMatchPhp($target_include, $item_file) || $this->checkPregMatch($target_exclude, $path, false)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->debug('编译: ' . $path);
|
||||||
|
|
||||||
|
$file_content = $this->tempFilesystem->read($path);
|
||||||
|
$file_stmts = $parser->parse($file_content);
|
||||||
|
|
||||||
|
$env_traverser = new NodeTraverser;
|
||||||
|
$env_traverser->addVisitor(
|
||||||
|
new NameResolver()
|
||||||
|
);
|
||||||
|
$env_traverser->addVisitor(
|
||||||
|
new ReadEnvVisitorNodeTools($path)
|
||||||
|
);
|
||||||
|
|
||||||
|
$file_stmts = $env_traverser->traverse($file_stmts);
|
||||||
|
|
||||||
|
// 生成代码
|
||||||
|
$result_content = $pretty_printer->prettyPrintFile($file_stmts);
|
||||||
|
|
||||||
$this->tempFilesystem->put($path, $result_content);
|
$this->tempFilesystem->put($path, $result_content);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,6 @@ class ReadEnvVisitorNodeTools extends NodeVisitorAbstract
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ($node instanceof StaticCall) {
|
} else if ($node instanceof StaticCall) {
|
||||||
|
|
||||||
if ($node->class instanceof FullyQualified) {
|
if ($node->class instanceof FullyQualified) {
|
||||||
$class_name = $node->class->toString();
|
$class_name = $node->class->toString();
|
||||||
if ($class_name == 'think\\facade\\Env') {
|
if ($class_name == 'think\\facade\\Env') {
|
||||||
@@ -101,7 +100,7 @@ class ReadEnvVisitorNodeTools extends NodeVisitorAbstract
|
|||||||
} else if (is_string($value)) {
|
} else if (is_string($value)) {
|
||||||
|
|
||||||
|
|
||||||
$env_pack_mode = Config::get('dist.pack_env_mode');
|
$env_pack_mode = Config::get('dist.pack_env.pack_env_mode');
|
||||||
|
|
||||||
if ($env_pack_mode == 0) {
|
if ($env_pack_mode == 0) {
|
||||||
return new FuncCall(new Name('base64_decode'), [
|
return new FuncCall(new Name('base64_decode'), [
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ return [
|
|||||||
],
|
],
|
||||||
'pack_env' => [
|
'pack_env' => [
|
||||||
// 0:base64方式处理,1:明文打包,3:不要编译env配置
|
// 0:base64方式处理,1:明文打包,3:不要编译env配置
|
||||||
'pack_env_mode' => 1,
|
'pack_env_mode' => 0,
|
||||||
// 实际上任何代码都可以,但是尽量只编译业务代码
|
// 实际上任何代码都可以,但是尽量只编译业务代码
|
||||||
'include_path' => [
|
'include_path' => [
|
||||||
"/^app/",
|
"/^app/",
|
||||||
|
|||||||
Reference in New Issue
Block a user