mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-07 18:42:49 +08:00
开始打包env
This commit is contained in:
@@ -60,7 +60,7 @@ class NodeVisitorTools extends NodeVisitorAbstract
|
||||
foreach ($comments as $comment_item) {
|
||||
if ($comment_item instanceof Doc) {
|
||||
$new_comments[] = $comment_item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$node->setAttribute('comments', $new_comments);
|
||||
@@ -86,9 +86,12 @@ class NodeVisitorTools extends NodeVisitorAbstract
|
||||
|
||||
$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);
|
||||
}
|
||||
} else if ($node instanceof Class_) {
|
||||
|
||||
@@ -2,9 +2,71 @@
|
||||
|
||||
namespace app\common\tools\phpparser;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\Logical\Boolean;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Expr\Cast\Bool_;
|
||||
use PhpParser\Node\Expr\ConstFetch;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
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\NodeVisitorAbstract;
|
||||
|
||||
class ReadEnvVisitorNodeTools extends NodeVisitorAbstract
|
||||
class ReadEnvVisitorNodeTools extends \PhpParser\NodeVisitorAbstract
|
||||
{
|
||||
|
||||
}
|
||||
public function leaveNode(\PhpParser\Node $node)
|
||||
{
|
||||
if ($node instanceof \PhpParser\Node\Expr\FuncCall) {
|
||||
if ($node->name instanceof \PhpParser\Node\Name\FullyQualified) {
|
||||
$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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user