示例#1
0
 /**
  * Dispatches the TransactionEvents in two passes
  * @param    TransactionEvents
  */
 public function dispatch(TransactionEvents $transaction)
 {
     try {
         $this->em->getConnection()->beginTransaction();
         foreach ($transaction->getFirstPass() as $eventName => $event) {
             $this->dispatcher->dispatch($eventName, $event);
         }
         foreach ($transaction->getFirstPass() as $eventName => $event) {
             $this->applyEventChangeSet($event);
         }
         $this->em->flush();
         foreach ($transaction->getSecondPass() as $eventName => $event) {
             $this->dispatcher->dispatch($eventName, $event);
         }
         foreach ($transaction->getSecondPass() as $eventName => $event) {
             $this->applyEventChangeSet($event);
         }
         $this->em->flush();
         $this->em->getConnection()->commit();
     } catch (\Exception $e) {
         $this->em->getConnection()->rollBack();
         throw $e;
     }
 }
示例#2
0
 public function testEmptyTransactionYieldsEmptyArray()
 {
     $transaction = new TransactionEvents();
     $this->assertSame(array(), $transaction->getFirstPass());
     $this->assertSame(array(), $transaction->getSecondPass());
 }