From b593840316a5f9f2681e91c568f8632889938a5c Mon Sep 17 00:00:00 2001 From: augushong Date: Wed, 14 Dec 2022 17:12:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=85=E7=90=86=E6=8A=80=E6=9C=AF=E5=80=BA?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/command/build/Dist.php | 263 ------------------------------ 1 file changed, 263 deletions(-) diff --git a/app/common/command/build/Dist.php b/app/common/command/build/Dist.php index 489fbd1..8cea8df 100644 --- a/app/common/command/build/Dist.php +++ b/app/common/command/build/Dist.php @@ -702,40 +702,6 @@ class Dist extends Command } } - /** - * 统一声明目录魔术常量 - * - * @param string $lib_dir_const_path - * @return void - */ - public function buildDirConstFile() - { - $dir_const_stmts = []; - - foreach ($this->constDirList as $const_key => $const_value) { - - $dir_const_stmts[] = new Expression(new FuncCall( - new Name('define'), - [ - new Arg(new String_($const_key)), - new Arg(new Concat( - new Dir(), - new String_('/../' . $const_value) - )), - ] - )); - } - - $prettyPrinter = new MinifyPrinterTools(); - - $dir_const_code = $prettyPrinter->prettyPrintFile($dir_const_stmts); - - $dir_const_path = 'lib/' . uniqid() . '.php'; - - $this->includeLibPath['dir_const_file'] = $dir_const_path; - $this->tempFilesystem->put($dir_const_path, $dir_const_code); - } - public function buildMagicVarMapFile() { $dir_const_stmts = []; @@ -765,139 +731,6 @@ class Dist extends Command } - - /** - * 打包路由文件 - * - * @return void - */ - public function buildRouteFile() - { - $route_dir = 'route'; - - $list_files = $this->tempFilesystem->listContents($route_dir, true); - - $parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7); - - $prettyPrinter = new MinifyPrinterTools(); - - foreach ($list_files as $item_file) { - if ($item_file['type'] == 'dir') { - continue; - } - - $file_content = $this->tempFilesystem->read($item_file['path']); - - $file_stmts = $parser->parse($file_content); - - $traverser = new NodeTraverser(); - $traverser->addVisitor(new class($item_file['path'], $this) extends NodeVisitorAbstract - { - protected $name; - protected $mainClass; - public function __construct($name, $main_class) - { - $this->name = $name; - $this->mainClass = $main_class; - } - - public function leaveNode(Node $node) - { - $name = $this->name; - if ($node instanceof Dir) { - // Clean out the function body - $const_key = 'dirconst' . uniqid(); - - $this->mainClass->constDirList[$const_key] = dirname($name); - return new ConstFetch(new Name($const_key)); - } - - if ($node->hasAttribute('comments')) { - $node->setAttribute('comments', []); - } - } - }); - - - $traverser_var_faker = new NodeTraverser(); - $traverser_var_faker->addVisitor(new NodeFakeVarVisitorTools); - - $file_stmts = $traverser_var_faker->traverse($file_stmts); - - - $function_code = $prettyPrinter->prettyPrintFile($file_stmts); - - $this->distFilesystem->put($item_file['path'], $function_code); - } - } - - /** - * 处理数据库迁移代码 - * - * @return void - */ - public function buildMigrateFile() - { - $database_dir = 'database'; - - $list_files = $this->tempFilesystem->listContents($database_dir, true); - - $parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7); - - - $prettyPrinter = new MinifyPrinterTools(); - - foreach ($list_files as $item_file) { - if ($item_file['type'] == 'dir') { - continue; - } - - $file_content = $this->tempFilesystem->read($item_file['path']); - - $file_stmts = $parser->parse($file_content); - - $traverser = new NodeTraverser(); - $traverser->addVisitor(new class($item_file['path'], $this) extends NodeVisitorAbstract - { - protected $name; - protected $mainClass; - public function __construct($name, $main_class) - { - $this->name = $name; - $this->mainClass = $main_class; - } - - public function leaveNode(Node $node) - { - $name = $this->name; - if ($node instanceof Dir) { - // Clean out the function body - $const_key = 'dirconst' . uniqid(); - - $this->mainClass->constDirList[$const_key] = dirname($name); - return new ConstFetch(new Name($const_key)); - } - - if ($node->hasAttribute('comments')) { - $node->setAttribute('comments', []); - } - } - }); - - $file_stmts = $traverser->traverse($file_stmts); - - $traverser_var_faker = new NodeTraverser(); - $traverser_var_faker->addVisitor(new NodeFakeVarVisitorTools); - - $file_stmts = $traverser_var_faker->traverse($file_stmts); - - - $function_code = $prettyPrinter->prettyPrintFile($file_stmts); - - $this->distFilesystem->put($item_file['path'], $function_code); - } - } - public function packMainClassFile() { @@ -1169,9 +1002,6 @@ class Dist extends Command return $content; } - - // $stmts = $this->parseStmts($stmts, $name); - $class_name = null; $extend_name = null; $namespace_name = null; @@ -1221,98 +1051,5 @@ class Dist extends Command } - /** - * 遍历扫描代码 - * - * @param Node\Stmt[]|null $stmts - * @param string $name - * @return Node\Stmt[] - */ - public function parseStmts($stmts, $name) - { - $traverser = new NodeTraverser(); - - $node_visitor = new NodeVisitorTools($this, $name); - - $traverser->addVisitor($node_visitor); - - $stmts = $traverser->traverse($stmts); - - return $stmts; - } - - /** - * 扫描魔术变量 - * - * @param Node\Stmt[]|null $stmts - * @param string $name - * @return void - */ - public function scanForMagicConstDir($stmts, $name) - { - - $traverser = new NodeTraverser(); - $traverser->addVisitor(new class($name, $this) extends NodeVisitorAbstract - { - protected $name; - protected $mainClass; - public function __construct($name, $main_class) - { - $this->name = $name; - $this->mainClass = $main_class; - } - - public function leaveNode(Node $node) - { - $name = $this->name; - if ($node instanceof Dir) { - // Clean out the function body - $const_key = 'dirconst' . uniqid(); - - $this->mainClass->constDirList[$const_key] = dirname($name); - return new ConstFetch(new Name($const_key)); - } - } - }); - - $stmts = $traverser->traverse($stmts); - } - - public function isSkip($path) - { - - $system_skip_path = [ - '/app\/common.php/', - '/^database\/*/', - '/^route\/*/', - ]; - - $skip_path = Config::get('dist.skip_path', []); - - $skip_path = array_merge($system_skip_path, $skip_path); - - foreach ($skip_path as $rule) { - if (preg_match($rule, $path)) { - return true; - } - } - - return false; - } - - public function isIgnored($path) - { - - $ignore_path = Config::get('dist.ignore_path', []); - - foreach ($ignore_path as $rule) { - - if (preg_match($rule, $path)) { - return true; - } - } - - return false; - } }