Capsule
2 years ago
Concerns
2 years ago
Connectors
2 years ago
Console
2 years ago
DBAL
2 years ago
Eloquent
2 years ago
Events
2 years ago
Migrations
2 years ago
PDO
2 years ago
Query
2 years ago
Schema
2 years ago
ClassMorphViolationException.php
2 years ago
ConfigurationUrlParser.php
2 years ago
Connection.php
2 years ago
ConnectionInterface.php
2 years ago
ConnectionResolver.php
2 years ago
ConnectionResolverInterface.php
2 years ago
DatabaseManager.php
2 years ago
DatabaseServiceProvider.php
2 years ago
DatabaseTransactionRecord.php
2 years ago
DatabaseTransactionsManager.php
2 years ago
DetectsConcurrencyErrors.php
2 years ago
DetectsLostConnections.php
2 years ago
Grammar.php
2 years ago
LazyLoadingViolationException.php
2 years ago
MigrationServiceProvider.php
2 years ago
MultipleRecordsFoundException.php
2 years ago
MySqlConnection.php
2 years ago
PostgresConnection.php
2 years ago
QueryException.php
2 years ago
RecordsNotFoundException.php
2 years ago
SQLiteConnection.php
2 years ago
Seeder.php
2 years ago
SqlServerConnection.php
2 years ago
DatabaseTransactionsManager.php
84 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP_SCOPED\Illuminate\Database; |
| 4 | |
| 5 | /** @internal */ |
| 6 | class DatabaseTransactionsManager |
| 7 | { |
| 8 | /** |
| 9 | * All of the recorded transactions. |
| 10 | * |
| 11 | * @var \Illuminate\Support\Collection |
| 12 | */ |
| 13 | protected $transactions; |
| 14 | /** |
| 15 | * Create a new database transactions manager instance. |
| 16 | * |
| 17 | * @return void |
| 18 | */ |
| 19 | public function __construct() |
| 20 | { |
| 21 | $this->transactions = \IAWP_SCOPED\collect(); |
| 22 | } |
| 23 | /** |
| 24 | * Start a new database transaction. |
| 25 | * |
| 26 | * @param string $connection |
| 27 | * @param int $level |
| 28 | * @return void |
| 29 | */ |
| 30 | public function begin($connection, $level) |
| 31 | { |
| 32 | $this->transactions->push(new DatabaseTransactionRecord($connection, $level)); |
| 33 | } |
| 34 | /** |
| 35 | * Rollback the active database transaction. |
| 36 | * |
| 37 | * @param string $connection |
| 38 | * @param int $level |
| 39 | * @return void |
| 40 | */ |
| 41 | public function rollback($connection, $level) |
| 42 | { |
| 43 | $this->transactions = $this->transactions->reject(function ($transaction) use($connection, $level) { |
| 44 | return $transaction->connection == $connection && $transaction->level > $level; |
| 45 | })->values(); |
| 46 | } |
| 47 | /** |
| 48 | * Commit the active database transaction. |
| 49 | * |
| 50 | * @param string $connection |
| 51 | * @return void |
| 52 | */ |
| 53 | public function commit($connection) |
| 54 | { |
| 55 | [$forThisConnection, $forOtherConnections] = $this->transactions->partition(function ($transaction) use($connection) { |
| 56 | return $transaction->connection == $connection; |
| 57 | }); |
| 58 | $this->transactions = $forOtherConnections->values(); |
| 59 | $forThisConnection->map->executeCallbacks(); |
| 60 | } |
| 61 | /** |
| 62 | * Register a transaction callback. |
| 63 | * |
| 64 | * @param callable $callback |
| 65 | * @return void |
| 66 | */ |
| 67 | public function addCallback($callback) |
| 68 | { |
| 69 | if ($current = $this->transactions->last()) { |
| 70 | return $current->addCallback($callback); |
| 71 | } |
| 72 | \call_user_func($callback); |
| 73 | } |
| 74 | /** |
| 75 | * Get all the transactions. |
| 76 | * |
| 77 | * @return \Illuminate\Support\Collection |
| 78 | */ |
| 79 | public function getTransactions() |
| 80 | { |
| 81 | return $this->transactions; |
| 82 | } |
| 83 | } |
| 84 |