Spot\Mapper::transaction PHP Method

transaction() public method

Transaction with closure
public transaction ( Closure $work, $entityName = null )
$work Closure
    public function transaction(\Closure $work, $entityName = null)
    {
        $connection = $this->connection($entityName);
        try {
            $connection->beginTransaction();
            // Execute closure for work inside transaction
            $result = $work($this);
            // Rollback on boolean 'false' return
            if ($result === false) {
                $connection->rollback();
            } else {
                $connection->commit();
            }
        } catch (\Exception $e) {
            // Rollback on uncaught exception
            $connection->rollback();
            // Re-throw exception so we don't bury it
            throw $e;
        }
        return $result;
    }