You are browsing a version that has not yet been released. |
Events
The Doctrine RST parser dispatches several different events internally which enable you to hook into the core of the parser to add custom functionality.
Event Manager
You can access the Doctrine\Common\EventManager
instance with the Doctrine\RST\Configuration::getEventManager()
method:
1 $eventManager = $configuration->getEventManager();
If you want to set your own event manager, you can do so with the setEventManager(EventManager $eventManager)
method:
Listeners
Add a new listener with the event manager:
Now, define your listener in App\Listeners\DocumentListener
. The postParseDocument()
method will be invoked every time a document is parsed:
1 namespace App\Listeners;
use Doctrine\RST\Event\PostParseDocumentEvent;
class DocumentListener
{
public function postParseDocument(PostParseDocumentEvent $event)
{
$documentNode = $event->getDocumentNode();
// do something with $documentNode
}
// Other event handlers, if any
// ...
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Available Events
The events you can listen for and their respective handlers:
PreBuildScanEvent::PRE_BUILD_SCAN
- Dispatches a method namedpreBuildScan()
before files are scanned when using the builder.PreBuildParseEvent::PRE_BUILD_PARSE
- Dispatches a method namedpreBuildParse()
before files are parsed and after they are scanned when using the builder.PreBuildRenderEvent::PRE_BUILD_RENDER
- Dispatches a method namedpreBuildRender()
before files are rendered and after they are parsed when using the builder.PostBuildRenderEvent::POST_BUILD_RENDER
- Dispatches a method namedpostBuildRender()
after files are rendered when using the builder.PostNodeCreateEvent::POST_NODE_CREATE
- Dispatches a method namedpostNodeCreate()
after a node is created.PreParseDocumentEvent::PRE_PARSE_DOCUMENT
- Dispatches a method namedpreParseDocument()
before a node is parsed.PostParseDocumentEvent::POST_PARSE_DOCUMENT
- Dispatches a method namedpostParseDocument()
after a node is parsed.PreNodeRenderEvent::PRE_NODE_RENDER
- Dispatches a method namedpreNodeRender()
before a node is rendered.PostNodeRenderEvent::POST_NODE_RENDER
- Dispatches a method namedpostNodeRender()
after a node is rendered.MissingReferenceResolverEvent::PRE_REFERENCED_RESOVED
- Dispatches a method namedresolveMissingReference()
if a reference cannot be resolved by the built-in methods. This event can be used to override theResolvedReference
returned byResolver->resolve
and thereby implement other means of references, like for example intersphinx links. The event can be listened to in implementing projects or extending packages. See Package Intersphinx, provided by the TYPO3 Documentation Team for an example implementation.PreDocumentRenderEvent
: This event is called in theDocumentNodeRenderer
before the document Node is rendered. The event can be used to influence the parameters sent to the template and or the name of the template to be used during rendering.PostDocumentRenderEvent
: This event is called in theDocumentNodeRenderer
after the content of the document got rendered and before the HTML is returned. It can be used to postprocess or exchange the HTML that will be written to the file.