Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NikicPhpParser: support custom NodeVisitors #21

Open
wants to merge 1 commit into
base: 2.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
->set(NikicPhpParser::class)
->args([
'$extractors' => tagged_iterator('reference_extractors'),
'$visitors' => tagged_iterator('node_visitors'),
]);
$services->alias(ParserInterface::class, NikicPhpParser::class);
$services->set(TypeResolver::class);
Expand Down
8 changes: 7 additions & 1 deletion src/Core/Ast/Parser/NikicPhpParser/NikicPhpParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor;
use PhpParser\NodeVisitor\FindingVisitor;
use PhpParser\NodeVisitor\NameResolver;
use PhpParser\Parser;
Expand All @@ -35,15 +36,20 @@ class NikicPhpParser implements ParserInterface

/**
* @param ReferenceExtractorInterface[] $extractors
* @param NodeVisitor[] $visitors
*/
public function __construct(
private readonly Parser $parser,
private readonly AstFileReferenceCacheInterface $cache,
private readonly TypeResolver $typeResolver,
private readonly iterable $extractors
private readonly iterable $extractors,
private readonly iterable $visitors
) {
$this->traverser = new NodeTraverser();
$this->traverser->addVisitor(new NameResolver());
foreach ($this->visitors as $visitor) {
$this->traverser->addVisitor($visitor);
}
}

public function parseFile(string $file): FileReference
Expand Down
Loading