完善打包封装代码结构

This commit is contained in:
2022-11-16 17:56:28 +08:00
parent 227aca6912
commit 417fbb5119
6 changed files with 32 additions and 53 deletions

View File

@@ -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/',

View File

@@ -1,21 +0,0 @@
<?php
// [ 应用入口文件 ]
namespace think;
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../{$lib_php_file}';
// 声明全局变量
define('DS', DIRECTORY_SEPARATOR);
define('ROOT_PATH', __DIR__ . DS . '..' . DS);
define('REUQEST_UID', uniqid());
// 执行HTTP应用并响应
$http = (new App())->http;
$response = $http->run();
$response->send();
$http->end($response);

View File

@@ -1,17 +0,0 @@
#!/usr/bin/env php
<?php
namespace think;
// 命令行入口文件
// 加载基础文件
require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/{$lib_php_file}';
define('REUQEST_UID', uniqid());
// 应用初始化
$app = (new App());
$app->console->run();