From 37c16f3e3f0326dff91bcdc7b8085fdfa505d952 Mon Sep 17 00:00:00 2001 From: augushong Date: Tue, 15 Nov 2022 11:21:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E7=B1=BB=E5=90=8D=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/class/phpparser/NodeVisitor.php | 70 ++++++++++++++++------ 1 file changed, 53 insertions(+), 17 deletions(-) diff --git a/app/common/class/phpparser/NodeVisitor.php b/app/common/class/phpparser/NodeVisitor.php index 7675f76..05e1bcc 100644 --- a/app/common/class/phpparser/NodeVisitor.php +++ b/app/common/class/phpparser/NodeVisitor.php @@ -6,8 +6,11 @@ use PhpParser\Comment; use PhpParser\Node; use PhpParser\Node\Expr\New_; use PhpParser\Node\Expr\StaticCall; +use PhpParser\Node\Expr\Variable; use PhpParser\Node\Identifier; use PhpParser\Node\Name; +use PhpParser\Node\Name\FullyQualified; +use PhpParser\Node\Param; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\TraitUseAdaptation\Alias; @@ -71,26 +74,59 @@ class NodeVisitor extends NodeVisitorAbstract } } } - } else if ($node instanceof Expression) { - if ( - $node->expr instanceof StaticCall || - $node->expr instanceof New_ - ) { - $used_class_str = implode('\\', $node->expr->class->parts); - if ($used_class_str != 'static' && $used_class_str != 'self' && $used_class_str != 'parent') { - $is_replaced = false; - foreach ($this->usedClass as $class_name => $class_name_md5) { - if (Str::endsWith($class_name, $used_class_str)) { - $is_replaced = true; - $node->expr->class = new Name($class_name_md5); - } - } - if(!$is_replaced){ - dump($node); + } else if ($node instanceof StaticCall || $node instanceof New_) { + + + if($node->class instanceof Variable){ + return; + } + + if($node->class instanceof Class_){ + return; + } + // exit; + + $used_class_str = implode('\\', $node->class->parts); + + + + + if ($used_class_str != 'static' && $used_class_str != 'self' && $used_class_str != 'parent') { + $is_replaced = false; + foreach ($this->usedClass as $class_name => $class_name_md5) { + if (Str::endsWith($class_name, $used_class_str)) { + $is_replaced = true; + $node->class = new Name($class_name_md5); } } - + if (!$is_replaced) { + // dump($this->name); + // dump($used_class_str); + // dump($this->usedClass); + // dump($node); + } } + }else if($node instanceof Param){ + + + if(is_null($node->type)){ + return; + } + + if($node->type instanceof Identifier){ + return; + } + + + $used_class_str = implode('\\', $node->type->parts); + + foreach ($this->usedClass as $class_name => $class_name_md5) { + if (Str::endsWith($class_name, $used_class_str)) { + $is_replaced = true; + $node->type = new Name($class_name_md5); + } + } + } return null;