mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-08 19:12:48 +08:00
完善打包封装代码结构
This commit is contained in:
@@ -10,11 +10,15 @@ use app\common\tools\phpparser\NodeVisitorTools;
|
|||||||
use League\Flysystem\Adapter\Local;
|
use League\Flysystem\Adapter\Local;
|
||||||
use League\Flysystem\Filesystem;
|
use League\Flysystem\Filesystem;
|
||||||
use PhpParser\Node;
|
use PhpParser\Node;
|
||||||
|
use PhpParser\Node\Expr\BinaryOp\Concat;
|
||||||
|
use PhpParser\Node\Expr\Include_;
|
||||||
use PhpParser\Node\Name;
|
use PhpParser\Node\Name;
|
||||||
use PhpParser\Node\Scalar\MagicConst\Dir;
|
use PhpParser\Node\Scalar\MagicConst\Dir;
|
||||||
|
use PhpParser\Node\Scalar\String_;
|
||||||
use PhpParser\Node\Stmt;
|
use PhpParser\Node\Stmt;
|
||||||
use PhpParser\Node\Stmt\Class_;
|
use PhpParser\Node\Stmt\Class_;
|
||||||
use PhpParser\Node\Stmt\ClassLike;
|
use PhpParser\Node\Stmt\ClassLike;
|
||||||
|
use PhpParser\Node\Stmt\Expression;
|
||||||
use PhpParser\Node\Stmt\Namespace_;
|
use PhpParser\Node\Stmt\Namespace_;
|
||||||
use PhpParser\Node\Stmt\Use_;
|
use PhpParser\Node\Stmt\Use_;
|
||||||
use PhpParser\Node\Stmt\UseUse;
|
use PhpParser\Node\Stmt\UseUse;
|
||||||
@@ -114,8 +118,8 @@ class Dist extends Command
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
$lib_php_file = 'lib/index.' . uniqid() . '.php';
|
$lib_php_file = '/lib.' . uniqid() . '.php';
|
||||||
$lib_php_path = $this->distPath . '/' . $lib_php_file;
|
$lib_php_path = $this->distPath . '/lib' . $lib_php_file;
|
||||||
|
|
||||||
|
|
||||||
PathTools::intiDir($lib_php_path);
|
PathTools::intiDir($lib_php_path);
|
||||||
@@ -138,21 +142,28 @@ class Dist extends Command
|
|||||||
|
|
||||||
file_put_contents($lib_php_path, $newCode);
|
file_put_contents($lib_php_path, $newCode);
|
||||||
|
|
||||||
$index_code = file_get_contents(__DIR__ . '/tpl/index.php.temp');
|
$this->buildIncludeIndexFile([
|
||||||
|
$lib_php_file
|
||||||
$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);
|
|
||||||
|
|
||||||
$output->info('打包完成');
|
$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()
|
public function parsePackList()
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -194,7 +205,6 @@ class Dist extends Command
|
|||||||
if (isset($this->packList[$try_namse_extend_name])) {
|
if (isset($this->packList[$try_namse_extend_name])) {
|
||||||
$this->insertToNewPackList($try_namse_extend_name, $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 = [
|
$ignore_path = [
|
||||||
'/^vendor/',
|
'/^vendor/',
|
||||||
'/^config/',
|
'/^config/',
|
||||||
|
'/^lib\//',
|
||||||
'/^database\/*/',
|
'/^database\/*/',
|
||||||
'/event\.php/',
|
'/event\.php/',
|
||||||
'/middleware\.php/',
|
'/middleware\.php/',
|
||||||
|
|||||||
@@ -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);
|
|
||||||
@@ -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();
|
|
||||||
1
lib/index.php
Normal file
1
lib/index.php
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<?php
|
||||||
@@ -4,6 +4,8 @@
|
|||||||
namespace think;
|
namespace think;
|
||||||
|
|
||||||
require __DIR__ . '/../vendor/autoload.php';
|
require __DIR__ . '/../vendor/autoload.php';
|
||||||
|
require __DIR__ . '/../lib/index.php';
|
||||||
|
|
||||||
|
|
||||||
// 声明全局变量
|
// 声明全局变量
|
||||||
define('DS', DIRECTORY_SEPARATOR);
|
define('DS', DIRECTORY_SEPARATOR);
|
||||||
|
|||||||
5
think
5
think
@@ -1,12 +1,15 @@
|
|||||||
#!/usr/bin/env php
|
#!/usr/bin/env php
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace think;
|
namespace think;
|
||||||
|
|
||||||
// 命令行入口文件
|
// 命令行入口文件
|
||||||
// 加载基础文件
|
// 加载基础文件
|
||||||
require __DIR__ . '/vendor/autoload.php';
|
require __DIR__ . '/vendor/autoload.php';
|
||||||
|
|
||||||
|
require __DIR__ . '/lib/index.php';
|
||||||
|
|
||||||
define('REUQEST_UID', uniqid());
|
define('REUQEST_UID', uniqid());
|
||||||
|
|
||||||
// 应用初始化
|
// 应用初始化
|
||||||
(new App())->console->run();
|
(new App())->console->run();
|
||||||
|
|||||||
Reference in New Issue
Block a user