delphi / parser-scoperesolver
PHPParser 访问者用于解决和设置作用域
dev-main
2021-08-17 16:52 UTC
Requires
- delphi/parser-fileresolver: dev-main
- delphi/parserutils: dev-main
- nikic/php-parser: ^4
Requires (Dev)
- phpunit/phpunit: ^9
This package is auto-updated.
Last update: 2024-09-17 23:17:30 UTC
README
跟踪当前活动的作用域以维护变量注册表
用法
$scopeResolver = new ScopeResolver(); $t = new \PhpParser\NodeTraverser(); $t->addVisitor($scopeResolver); /** @var \delphi\Parser\Scope\Helper\Scope $scope */ $scope = $node->getAttribute(ScopeResolver::ATTRIBUTE_KEY); if ($scope->hasVariable('foo')) { /** @var \PhpParser\Node\Expr $value The expression that defined the variable itself */ $value = $scope->getVariable('foo'); } /** @var \PhpParser\Node $definingNode The node that defined this scope (class, function, etc) */ $definingNode = $scope->getDefiningNode(); /** * Scope that contains the given scope, or null if already the global scope * @var \delphi\Parser\Scope\Helper\Scope | null $parentScope */ $parentScope = $scope->getParentScope();