From 417fbb5119bb3d1a96ed7a6d02035463d1423ab6 Mon Sep 17 00:00:00 2001 From: augushong Date: Wed, 16 Nov 2022 17:56:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=89=93=E5=8C=85=E5=B0=81?= =?UTF-8?q?=E8=A3=85=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/command/build/Dist.php | 39 +++++++++++++-------- app/common/command/build/tpl/index.php.temp | 21 ----------- app/common/command/build/tpl/think.temp | 17 --------- lib/index.php | 1 + public/index.php | 2 ++ think | 5 ++- 6 files changed, 32 insertions(+), 53 deletions(-) delete mode 100644 app/common/command/build/tpl/index.php.temp delete mode 100644 app/common/command/build/tpl/think.temp create mode 100644 lib/index.php diff --git a/app/common/command/build/Dist.php b/app/common/command/build/Dist.php index 5d47f5c..93b2820 100644 --- a/app/common/command/build/Dist.php +++ b/app/common/command/build/Dist.php @@ -10,11 +10,15 @@ use app\common\tools\phpparser\NodeVisitorTools; use League\Flysystem\Adapter\Local; use League\Flysystem\Filesystem; use PhpParser\Node; +use PhpParser\Node\Expr\BinaryOp\Concat; +use PhpParser\Node\Expr\Include_; use PhpParser\Node\Name; use PhpParser\Node\Scalar\MagicConst\Dir; +use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassLike; +use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\Namespace_; use PhpParser\Node\Stmt\Use_; use PhpParser\Node\Stmt\UseUse; @@ -114,8 +118,8 @@ class Dist extends Command - $lib_php_file = 'lib/index.' . uniqid() . '.php'; - $lib_php_path = $this->distPath . '/' . $lib_php_file; + $lib_php_file = '/lib.' . uniqid() . '.php'; + $lib_php_path = $this->distPath . '/lib' . $lib_php_file; PathTools::intiDir($lib_php_path); @@ -138,21 +142,28 @@ class Dist extends Command file_put_contents($lib_php_path, $newCode); - $index_code = file_get_contents(__DIR__ . '/tpl/index.php.temp'); - - $index_code = str_replace('{$lib_php_file}', $lib_php_file, $index_code); - - $dist_filesystem->put('public/index.php', $index_code); - - $think_code = file_get_contents(__DIR__ . '/tpl/think.temp'); - - $think_code = str_replace('{$lib_php_file}', $lib_php_file, $think_code); - - $dist_filesystem->put('think', $think_code); + $this->buildIncludeIndexFile([ + $lib_php_file + ]); $output->info('打包完成'); } + public function buildIncludeIndexFile($files) + { + $file_stmts = []; + + foreach ($files as $file_name) { + $file_stmts[] = new Expression(new Include_(new Concat(new Dir, new String_($file_name)), Include_::TYPE_REQUIRE_ONCE)); + } + $prettyPrinter = new Standard(); + + + $newCode = $prettyPrinter->prettyPrintFile($file_stmts); + + file_put_contents($this->distPath . '/lib/index.php', $newCode); + } + public function parsePackList() { @@ -194,7 +205,6 @@ class Dist extends Command if (isset($this->packList[$try_namse_extend_name])) { $this->insertToNewPackList($try_namse_extend_name, $this->packList[$try_namse_extend_name]); } - } } @@ -370,6 +380,7 @@ class Dist extends Command $ignore_path = [ '/^vendor/', '/^config/', + '/^lib\//', '/^database\/*/', '/event\.php/', '/middleware\.php/', diff --git a/app/common/command/build/tpl/index.php.temp b/app/common/command/build/tpl/index.php.temp deleted file mode 100644 index 6895f8a..0000000 --- a/app/common/command/build/tpl/index.php.temp +++ /dev/null @@ -1,21 +0,0 @@ -http; - -$response = $http->run(); - -$response->send(); - -$http->end($response); diff --git a/app/common/command/build/tpl/think.temp b/app/common/command/build/tpl/think.temp deleted file mode 100644 index 179e544..0000000 --- a/app/common/command/build/tpl/think.temp +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env php -console->run(); \ No newline at end of file diff --git a/lib/index.php b/lib/index.php new file mode 100644 index 0000000..b3d9bbc --- /dev/null +++ b/lib/index.php @@ -0,0 +1 @@ +console->run(); \ No newline at end of file +(new App())->console->run();