Skip to content

Commit

Permalink
[FEAT] Allow post parse mutations
Browse files Browse the repository at this point in the history
We should allow post parse events to change the document.

(cherry picked from commit 441b1e0)
  • Loading branch information
jaapio committed Oct 16, 2024
1 parent 8409e2e commit eec78f6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions packages/guides/src/Event/PostParseDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,30 @@
*/
final class PostParseDocument
{
public function __construct(private readonly string $fileName, private readonly DocumentNode|null $documentNode)
{
public function __construct(
private readonly string $fileName,
private DocumentNode|null $documentNode,
private readonly string $originalFile,
) {
}

public function getDocumentNode(): DocumentNode|null
{
return $this->documentNode;
}

public function setDocumentNode(DocumentNode|null $documentNode): void
{
$this->documentNode = $documentNode;
}

public function getFileName(): string
{
return $this->fileName;
}

public function getOriginalFileName(): string
{
return $this->originalFile;
}
}
2 changes: 1 addition & 1 deletion packages/guides/src/Handlers/ParseFileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private function createDocument(
);
}

$event = $this->eventDispatcher->dispatch(new PostParseDocument($fileName, $document));
$event = $this->eventDispatcher->dispatch(new PostParseDocument($fileName, $document, $path));
assert($event instanceof PostParseDocument);

return $event->getDocumentNode();
Expand Down

0 comments on commit eec78f6

Please sign in to comment.