public transactional ( Closur\Closure $func ) | ||
$func | Closur\Closure | The function to execute transactionally. |
public function transactional(Closure $func)
{
$this->conn->beginTransaction();
try {
$func($this);
$this->flush();
$this->conn->commit();
} catch (Exception $e) {
$this->close();
$this->conn->rollback();
throw $e;
}
}
/** * @param float $discount */ public function apply($discount) { $this->entityManager->transactional(function () use($discount) { foreach ($this->items->findAll() as $item) { $item->applyDiscount($discount); } }); $this->entityManager->clear(); }