Exemple #1
0
 /**
  * Commit transaction
  *
  * @triggers commit.pre  On every commit call. If a listener stops propagation, the ES performs a rollback
  * @triggers commit.post Once after all started transactions are committed. Event includes all "recordedEvents".
  *                       Perfect to attach a domain event dispatcher
  */
 public function commit()
 {
     if ($this->transactionLevel === 0) {
         throw new RuntimeException('Cannot commit transaction. EventStore has no active transaction');
     }
     $event = $this->getActionEventEmitter()->getNewActionEvent(__FUNCTION__ . '.pre', $this);
     $event->setParam('isNestedTransaction', $this->transactionLevel > 1);
     $event->setParam('transactionLevel', $this->transactionLevel);
     $this->getActionEventEmitter()->dispatch($event);
     if ($event->propagationIsStopped()) {
         $this->rollback();
         return;
     }
     $this->transactionLevel--;
     //Nested transaction commit only decreases transaction level
     if ($this->transactionLevel > 0) {
         return;
     }
     if ($this->adapter instanceof CanHandleTransaction) {
         $this->adapter->commit();
     }
     $event = $this->getActionEventEmitter()->getNewActionEvent(__FUNCTION__ . '.post', $this, ['recordedEvents' => $this->recordedEvents]);
     $this->recordedEvents = [];
     $this->getActionEventEmitter()->dispatch($event);
 }
Exemple #2
0
 /**
  * Commit transaction
  *
  * @triggers commit.pre  On every commit call. If a listener stops propagation, the ES performs a rollback
  * @triggers commit.post Once after all started transactions are committed. Event includes all "recordedEvents".
  *                       Perfect to attach a domain event dispatcher
  */
 public function commit()
 {
     if (!$this->inTransaction) {
         throw new RuntimeException('Cannot commit transaction. EventStore has no active transaction');
     }
     $event = $this->getActionEventEmitter()->getNewActionEvent(__FUNCTION__ . '.pre', $this);
     $event->setParam('inTransaction', true);
     $this->getActionEventEmitter()->dispatch($event);
     if ($event->propagationIsStopped()) {
         $this->rollback();
         return;
     }
     $this->inTransaction = false;
     if ($this->adapter instanceof CanHandleTransaction) {
         $this->adapter->commit();
     }
     $event = $this->getActionEventEmitter()->getNewActionEvent(__FUNCTION__ . '.post', $this, ['recordedEvents' => $this->recordedEvents]);
     $this->recordedEvents = new ArrayIterator();
     $this->getActionEventEmitter()->dispatch($event);
 }