mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-07 18:42:49 +08:00
完成所有打包的功能点
This commit is contained in:
@@ -82,15 +82,14 @@ class NodeVisitorTools extends NodeVisitorAbstract
|
||||
return;
|
||||
}
|
||||
|
||||
if(isset($this->usedClass[$used_class_str])){
|
||||
return NodeTraverser::REMOVE_NODE;
|
||||
}
|
||||
|
||||
$name .= md5($used_class_str);
|
||||
|
||||
$this->usedClass[$used_class_str] = $name;
|
||||
if (!empty($use_item->alias->name)) {
|
||||
|
||||
$name .= md5($use_item->alias->name);
|
||||
|
||||
$this->usedClass[$use_item->alias->name] = $name;
|
||||
}
|
||||
|
||||
|
||||
$use_item->alias = new Identifier($name);
|
||||
}
|
||||
|
||||
@@ -8,65 +8,106 @@ use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Expr\Cast\Bool_;
|
||||
use PhpParser\Node\Expr\ConstFetch;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Scalar\DNumber;
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\NodeTraverser;
|
||||
use PhpParser\NodeVisitorAbstract;
|
||||
class ReadEnvVisitorNodeTools extends \PhpParser\NodeVisitorAbstract
|
||||
|
||||
class ReadEnvVisitorNodeTools extends NodeVisitorAbstract
|
||||
{
|
||||
public function leaveNode(\PhpParser\Node $node)
|
||||
protected $path;
|
||||
|
||||
protected $skipFiles = [
|
||||
'app/common/tools/phpparser/ReadEnvVisitorNodeTools.php'
|
||||
];
|
||||
|
||||
public function __construct($path)
|
||||
{
|
||||
if ($node instanceof \PhpParser\Node\Expr\FuncCall) {
|
||||
if ($node->name instanceof \PhpParser\Node\Name\FullyQualified) {
|
||||
$this->path = $path;
|
||||
}
|
||||
|
||||
public function enterNode(Node $node)
|
||||
{
|
||||
if (in_array($this->path, $this->skipFiles)) {
|
||||
return NodeTraverser::DONT_TRAVERSE_CHILDREN;
|
||||
}
|
||||
}
|
||||
|
||||
public function leaveNode(Node $node)
|
||||
{
|
||||
|
||||
|
||||
if ($node instanceof FuncCall) {
|
||||
if ($node->name instanceof Name) {
|
||||
$function_name = $node->name->toString();
|
||||
|
||||
if ($function_name == 'env') {
|
||||
dump($node);
|
||||
|
||||
$env_arg_1 = $this->getArg($node, 0);
|
||||
$env_arg_2 = $this->getArg($node, 1);
|
||||
|
||||
$env_value = env($env_arg_1, $env_arg_2);
|
||||
return $this->returnEnvValue($env_value);
|
||||
|
||||
$return_node = $this->returnEnvValue($env_value);
|
||||
return $return_node;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public function getArg($node, $index)
|
||||
{
|
||||
$env = null;
|
||||
if (isset($node->args[$index])) {
|
||||
if ($node->args[$index]->value instanceof \PhpParser\Node\Scalar\String_) {
|
||||
$env = $node->args[$index]->value->value;
|
||||
} else {
|
||||
// 发现非字符串方式读取,应当提示
|
||||
}
|
||||
}
|
||||
return $env;
|
||||
}
|
||||
public function returnEnvValue($value)
|
||||
{
|
||||
if (is_array($value)) {
|
||||
return new \PhpParser\Node\Expr\Array_($value);
|
||||
} else {
|
||||
if (is_string($value)) {
|
||||
return new \PhpParser\Node\Scalar\String_($value);
|
||||
} else {
|
||||
if (is_integer($value)) {
|
||||
return new \PhpParser\Node\Scalar\LNumber($value);
|
||||
} else {
|
||||
if (is_float($value)) {
|
||||
return new \PhpParser\Node\Scalar\DNumber($value);
|
||||
} else {
|
||||
if (is_bool($value)) {
|
||||
if ($value) {
|
||||
return new \PhpParser\Node\Expr\ConstFetch(new \PhpParser\Node\Name('true'));
|
||||
} else {
|
||||
return new \PhpParser\Node\Expr\ConstFetch(new \PhpParser\Node\Name('false'));
|
||||
}
|
||||
} else if ($node instanceof StaticCall) {
|
||||
|
||||
if ($node->class instanceof FullyQualified) {
|
||||
$class_name = $node->class->toString();
|
||||
if ($class_name == 'think\\facade\\Env') {
|
||||
if ($node->name instanceof Identifier) {
|
||||
if ($node->name == 'get') {
|
||||
$env_arg_1 = $this->getArg($node, 0);
|
||||
$env_arg_2 = $this->getArg($node, 1);
|
||||
|
||||
$env_value = env($env_arg_1, $env_arg_2);
|
||||
|
||||
$return_node = $this->returnEnvValue($env_value);
|
||||
return $return_node;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getArg($node, $index)
|
||||
{
|
||||
$env = null;
|
||||
if (isset($node->args[$index])) {
|
||||
if ($node->args[$index]->value instanceof String_) {
|
||||
$env = $node->args[$index]->value->value;
|
||||
} else {
|
||||
// 发现非字符串方式读取,应当提示
|
||||
}
|
||||
}
|
||||
|
||||
return $env;
|
||||
}
|
||||
|
||||
public function returnEnvValue($value)
|
||||
{
|
||||
if (is_array($value)) {
|
||||
return new Array_($value);
|
||||
} else if (is_string($value)) {
|
||||
return new String_($value);
|
||||
} else if (is_integer($value)) {
|
||||
return new LNumber($value);
|
||||
} else if (is_float($value)) {
|
||||
return new DNumber($value);
|
||||
} else if (is_bool($value)) {
|
||||
if ($value) {
|
||||
return new ConstFetch(new Name('true'));
|
||||
} else {
|
||||
return new ConstFetch(new Name('false'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user