/**
* {@inheritdoc}
*/
public function register(EventDispatcher $dispatcher)
{
$dispatcher->addListener(RouteMatchedEvent::class, function (RouteMatchedEvent $event) {
$annotation = $this->getTransactionalAnnotation($event->getRouteMatch());
if ($annotation) {
$this->connection->setTransactionIsolation($annotation->getIsolationLevel());
$this->connection->beginTransaction();
}
});
$dispatcher->addListener(ControllerInvocatedEvent::class, function (ControllerInvocatedEvent $event) {
$annotation = $this->getTransactionalAnnotation($event->getRouteMatch());
if ($annotation) {
if ($this->connection->isTransactionActive()) {
$this->connection->rollback();
}
}
});
}