From badcffdd3ffb241bf5c86695a257130eb95d423a Mon Sep 17 00:00:00 2001 From: augushong Date: Wed, 14 Dec 2022 17:15:50 +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 | 6 +- .../phpparser/FindClassNodeVisitorTools.php | 39 --- .../tools/phpparser/NodeVisitorTools.php | 238 ------------------ .../phpparser/PackUseNodeVisitorTools.php | 9 - 4 files changed, 1 insertion(+), 291 deletions(-) delete mode 100644 app/common/tools/phpparser/NodeVisitorTools.php delete mode 100644 app/common/tools/phpparser/PackUseNodeVisitorTools.php diff --git a/app/common/command/build/Dist.php b/app/common/command/build/Dist.php index 8cea8df..232c3bc 100644 --- a/app/common/command/build/Dist.php +++ b/app/common/command/build/Dist.php @@ -4,12 +4,10 @@ declare(strict_types=1); namespace app\common\command\build; -use app\commmon\tools\phpparser\PackUseNodeVisitorTools; use app\common\tools\PathTools; use app\common\tools\phpparser\FindClassNodeVisitorTools; use app\common\tools\phpparser\MinifyPrinterTools; use app\common\tools\phpparser\NodeFakeVarVisitorTools; -use app\common\tools\phpparser\NodeVisitorTools; use League\Flysystem\Adapter\Local; use League\Flysystem\Filesystem; use PhpParser\Node; @@ -32,7 +30,6 @@ use PhpParser\Node\Stmt\UseUse; use PhpParser\NodeTraverser; use PhpParser\NodeVisitorAbstract; use PhpParser\ParserFactory; -use app\common\tools\phpparser\PrettyPrinterTools as Standard; use app\common\tools\phpparser\PrettyPrinterTools; use app\common\tools\phpparser\ReadEnvVisitorNodeTools; use PhpParser\Comment; @@ -758,8 +755,7 @@ class Dist extends Command public function buildMainClassFile() { - - $prettyPrinter = new Standard(); + $prettyPrinter = new PrettyPrinterTools(); // 根据调用次数排序 $this->parsePackList(); diff --git a/app/common/tools/phpparser/FindClassNodeVisitorTools.php b/app/common/tools/phpparser/FindClassNodeVisitorTools.php index 60b82cb..99786e9 100644 --- a/app/common/tools/phpparser/FindClassNodeVisitorTools.php +++ b/app/common/tools/phpparser/FindClassNodeVisitorTools.php @@ -2,48 +2,10 @@ namespace app\common\tools\phpparser; -use PhpParser\NodeTraverser; -use app\commmon\tools\phpparser\PackUseNodeVisitorTools; -use app\common\tools\PathTools; -use app\common\tools\phpparser\MinifyPrinterTools; -use app\common\tools\phpparser\NodeFakeVarVisitorTools; -use app\common\tools\phpparser\NodeVisitorTools; -use League\Flysystem\Adapter\Local; -use League\Flysystem\Filesystem; use PhpParser\Node; -use PhpParser\Node\Arg; -use PhpParser\Node\Const_; -use PhpParser\Node\Expr\BinaryOp\Concat; -use PhpParser\Node\Expr\ConstFetch; -use PhpParser\Node\Expr\FuncCall; -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; use PhpParser\NodeVisitorAbstract; -use PhpParser\ParserFactory; -use app\common\tools\phpparser\PrettyPrinterTools as Standard; -use app\common\tools\phpparser\PrettyPrinterTools; -use app\common\tools\phpparser\ReadEnvVisitorNodeTools; -use PhpParser\Comment; -use PhpParser\NodeVisitor\NameResolver; -use think\Collection; -use think\console\Command; -use think\console\Input; -use think\console\input\Argument; -use think\console\input\Option; -use think\console\Output; -use think\facade\App; -use think\facade\Config; -use think\facade\View; -use think\helper\Str; use PhpParser\Node\Expr\New_; use PhpParser\Node\Expr\PropertyFetch; use PhpParser\Node\Expr\StaticCall; @@ -56,7 +18,6 @@ use PhpParser\Node\Param; use PhpParser\Node\Stmt\TraitUse; use PhpParser\Node\Stmt\Catch_; use PhpParser\Node\Stmt\ClassMethod; -use PhpParser\Node\Stmt\Declare_; class FindClassNodeVisitorTools extends NodeVisitorAbstract { diff --git a/app/common/tools/phpparser/NodeVisitorTools.php b/app/common/tools/phpparser/NodeVisitorTools.php deleted file mode 100644 index 87c561f..0000000 --- a/app/common/tools/phpparser/NodeVisitorTools.php +++ /dev/null @@ -1,238 +0,0 @@ -cmd = $cmd; - $this->name = $name; - } - - public function leaveNode(Node $node) - { - - $comments = $node->getComments(); - if (!empty($comments)) { - $new_comments = []; - foreach ($comments as $comment_item) { - if ($comment_item instanceof Doc) { - $new_comments[] = $comment_item; - } - } - - $node->setAttribute('comments', $new_comments); - } - - - if ($node instanceof Use_) { - - foreach ($node->uses as &$use_item) { - - $name = 'class'; - - $name .= md5($this->name); - - $used_class_str = implode('\\', $use_item->name->parts); - - - if (in_array($used_class_str, $this->skipClass)) { - return; - } - - if(isset($this->usedClass[$used_class_str])){ - return NodeTraverser::REMOVE_NODE; - } - - $name .= md5($used_class_str); - - $this->usedClass[$used_class_str] = $name; - - - $use_item->alias = new Identifier($name); - } - } else if ($node instanceof Class_) { - - if (!empty($node->extends)) { - $used_class_str = $node->extends->toString(); - $result_name = $this->findClassName($used_class_str); - if (!empty($result_name)) { - $node->extends = new Name($result_name); - } - } - - if (!empty($node->implements)) { - foreach ($node->implements as &$node_implements) { - $used_class_str = $node_implements->toString(); - $result_name = $this->findClassName($used_class_str); - if (!empty($result_name)) { - $node_implements = new Name($result_name); - } - } - } - } else if ( - $node instanceof StaticCall || - $node instanceof New_ || - $node instanceof ClassConstFetch || - $node instanceof Instanceof_ || - $node instanceof StaticPropertyFetch - ) { - - if ($node->class instanceof Variable) { - return; - } - - if ($node->class instanceof Class_) { - return; - } - - if ($node->class instanceof PropertyFetch) { - - if ($node->class->var->name == 'this') { - return; - } - } - - $used_class_str = $node->class->toString(); - - if ($used_class_str != 'static' && $used_class_str != 'self' && $used_class_str != 'parent') { - $result_name = $this->findClassName($used_class_str); - - if (!empty($result_name)) { - $node->class = new Name($result_name); - } - } - } else if ($node instanceof Param) { - - - if (is_null($node->type)) { - return; - } - - if ($node->type instanceof Identifier) { - return; - } - - $used_class_str = $node->type->toString(); - - $result_name = $this->findClassName($used_class_str); - - if (!empty($result_name)) { - - - $node->type = new Name($result_name); - } - } else if ($node instanceof Declare_) { - return NodeTraverser::REMOVE_NODE; - } else if ($node instanceof TraitUse) { - foreach ($node->traits as &$node_name) { - $used_class_str = $node_name->toString(); - - $result_name = $this->findClassName($used_class_str); - if (!empty($result_name)) { - $node_name = new Name($result_name); - } - } - } else if ($node instanceof Catch_) { - foreach ($node->types as &$node_name) { - $used_class_str = $node_name->toString(); - - $result_name = $this->findClassName($used_class_str); - - if (!empty($result_name)) { - $node_name = new Name($result_name); - } - } - } else if ($node instanceof ClassMethod) { - - if (empty($node->returnType)) { - return; - } - - if ($node->returnType instanceof Identifier) { - return; - } - - $used_class_str = $node->returnType->toString(); - $result_name = $this->findClassName($used_class_str); - - if (!empty($result_name)) { - - $node->returnType = new Name($result_name); - } - } - - return null; - } - - public function findClassName($class_name_str) - { - $name = null; - foreach ($this->usedClass as $class_name => $class_name_md5) { - - $class_name_arr = explode('\\', $class_name); - - $class_name_str_arr = explode('\\', $class_name_str); - - $class_name_str_arr = array_reverse($class_name_str_arr); - - $last_index = 0; - foreach ($class_name_str_arr as $class_item) { - $last_class_item = array_pop($class_name_arr); - if ($last_class_item != $class_item) { - break; - } - - $last_index++; - } - - if ($last_index == count($class_name_str_arr)) { - $name = $class_name_md5; - break; - } - } - return $name; - } -} diff --git a/app/common/tools/phpparser/PackUseNodeVisitorTools.php b/app/common/tools/phpparser/PackUseNodeVisitorTools.php deleted file mode 100644 index 9f62068..0000000 --- a/app/common/tools/phpparser/PackUseNodeVisitorTools.php +++ /dev/null @@ -1,9 +0,0 @@ -