mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-06 10:02:49 +08:00
清理技术债务
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -1,238 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\tools\phpparser;
|
||||
|
||||
use PhpParser\Comment;
|
||||
use PhpParser\Comment\Doc;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\ClassConstFetch;
|
||||
use PhpParser\Node\Expr\Instanceof_;
|
||||
use PhpParser\Node\Expr\New_;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Expr\StaticPropertyFetch;
|
||||
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;
|
||||
use PhpParser\Node\Stmt\Catch_;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Declare_;
|
||||
use PhpParser\Node\Stmt\DeclareDeclare;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\Node\Stmt\TraitUse;
|
||||
use PhpParser\Node\Stmt\TraitUseAdaptation\Alias;
|
||||
use PhpParser\Node\Stmt\Use_;
|
||||
use PhpParser\NodeTraverser;
|
||||
use PhpParser\NodeVisitorAbstract;
|
||||
use think\helper\Str;
|
||||
|
||||
class NodeVisitorTools extends NodeVisitorAbstract
|
||||
{
|
||||
protected $cmd;
|
||||
protected $name;
|
||||
|
||||
|
||||
public $usedClass = [];
|
||||
|
||||
public $callClass = [];
|
||||
protected $skipClass = [
|
||||
// 'Doctrine\Common\Annotations\Annotation\Attributes',
|
||||
// 'app\admin\service\annotation\ControllerAnnotation',
|
||||
// 'app\admin\service\annotation\NodeAnotation',
|
||||
];
|
||||
|
||||
public function __construct($cmd, $name)
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
<?php
|
||||
namespace app\commmon\tools\phpparser;
|
||||
|
||||
use PhpParser\NodeVisitorAbstract;
|
||||
|
||||
class PackUseNodeVisitorTools extends NodeVisitorAbstract
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user