protected function inTransaction($fn) {
$connection = ...
$transaction = $connection->beginTransaction();
$result = false;
try {
$result = call_user_func($fn);
$transaction->commit();
} catch (Exception $e) {
$transaction->rollBack();
}
return $result;
}
$result = $this->inTransaction(function() use ($data) {
...
});
$result = $this->inTransaction(array('ClassName', 'methodName'));