Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bartko-s/stefano-nested-transaction
PHP library which manage nested database transactions
https://github.com/bartko-s/stefano-nested-transaction
Last synced: 3 months ago
JSON representation
PHP library which manage nested database transactions
- Host: GitHub
- URL: https://github.com/bartko-s/stefano-nested-transaction
- Owner: bartko-s
- Created: 2014-01-21T12:49:08.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2022-09-30T19:56:39.000Z (over 2 years ago)
- Last Synced: 2024-07-13T09:51:04.837Z (7 months ago)
- Language: PHP
- Homepage:
- Size: 11.7 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Stefano Nested Transaction
===================[![Build Status](https://app.travis-ci.com/bartko-s/stefano-nested-transaction.svg?branch=master)](https://app.travis-ci.com/bartko-s/stefano-nested-transaction)
[![Coverage Status](https://coveralls.io/repos/bartko-s/stefano-nested-transaction/badge.png?branch=master)](https://coveralls.io/r/bartko-s/stefano-nested-transaction?branch=master)Instalation using Composer
--------------------------
1. Run command ``` composer require stefano/stefano-nested-transaction```Features
------------- manages nested transaction
Usage
------- Configuration
```
//$transactionAdapter implements \StefanoNestedTransaction\Adapter\TransactionInterface
$transactionAdapter = new YourTransactionAdapter();$transactionManager = new \StefanoNestedTransaction\TransactionManager($transactionAdapter);
```- Example: normal flow
```
$transactionManager->begin(); //REAL start transaction
try {
// ...//nested transaction block, that might be in some other code
$transactionManager->begin(); //increase internal transaction counter
try {
// ...$transactionManager->commit(); //decrease internal transaction counter
} catch(\Exception $e) {
$transactionManager->rollback(); //skipped
throw $e->getPrevious();
}// ...
$transactionManager->commit(); //REAL commit transaction;
} catch(\Exception $e) {
$transactionManager->rollback(); //skipped
throw $e->getPrevious();
}
```- Example: throw exception
```
$transactionManager->begin(); //REAL start transaction
try {
// ...//nested transaction block, that might be in some other code
$transactionManager->begin(); //increase internal transaction counter
try {
// ...throw new \Exception();
$transactionManager->commit(); //skipped
} catch(\Exception $e) {
$transactionManager->rollback(); //marked as rollback only
throw $e->getPrevious();
}// ...
$transactionManager->commit(); //skipped
} catch(\Exception $e) {
$transactionManager->rollback(); //REAL rollback
throw $e->getPrevious();
}
```- Example: throw exception
```
$transactionManager->begin(); //REAL start transaction
try {
// ...//nested transaction block, that might be in some other code
$transactionManager->begin(); //increase internal transaction counter
try {
// ...throw new \Exception();
$transactionManager->commit(); //do nothing
} catch(\Exception $e) {
$transactionManager->rollback(); //marked as rollback only
}// ...
$transactionManager->commit(); //this throw exception because transaction is marked as rollback only
} catch(\Exception $e) {
$transactionManager->rollback(); //REAL rollback
throw $e->getPrevious();
}
```