You are browsing a version that is no longer maintained. |
Events
The Doctrine RST parser dispatches several different events internally which enable you to hook in to the core of the parser to add custom functionality.
Event Manager
You can access the Doctrine\Common\EventManager
instance with the getEventManager()
method:
1 $eventManager = $configuration->getEventManager();
If you want to set your own 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\PostParseDocumentListener
. The postParseDocument()
method will be notified every time a document is parsed:
1 namespace App\Listeners;
use Doctrine\RST\Event\PostParseDocumentEvent;
use Doctrine\RST\Event\PostParseDocumentEvent;
class PostParseDocumentListener
{
public function postParseDocument(PostParseDocumentEvent $event)
{
$documentNode = $event->getDocumentNode();
// do something with $documentNode
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
Available Events
The events you can listen for are as follows:
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.