From 441b1e0f8dfe0eb0a61ec303725add23210a0550 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Wed, 16 Oct 2024 22:25:03 +0200 Subject: [PATCH] [FEAT] Allow post parse mutations We should allow post parse events to change the document. --- packages/guides/src/Event/PostParseDocument.php | 17 +++++++++++++++-- .../guides/src/Handlers/ParseFileHandler.php | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/guides/src/Event/PostParseDocument.php b/packages/guides/src/Event/PostParseDocument.php index f252473e4..017b8511b 100644 --- a/packages/guides/src/Event/PostParseDocument.php +++ b/packages/guides/src/Event/PostParseDocument.php @@ -22,8 +22,11 @@ */ 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 @@ -31,8 +34,18 @@ 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; + } } diff --git a/packages/guides/src/Handlers/ParseFileHandler.php b/packages/guides/src/Handlers/ParseFileHandler.php index 548f119b9..f68262caf 100644 --- a/packages/guides/src/Handlers/ParseFileHandler.php +++ b/packages/guides/src/Handlers/ParseFileHandler.php @@ -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();