Skip to content

Commit

Permalink
NikicPhpParser: support custom NodeVisitors
Browse files Browse the repository at this point in the history
  • Loading branch information
janedbal committed Mar 19, 2024
1 parent 104f17a commit 8e7f14f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
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

0 comments on commit 8e7f14f

Please sign in to comment.