PluginProbe
Independent Analytics – WordPress Analytics Plugin / 2.9.2
Independent Analytics – WordPress Analytics Plugin v2.9.2
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 All 120 releases
independent-analytics / vendor / illuminate / database / DatabaseTransactionsManager.php
DatabaseTransactionsManager.php
84 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IAWPSCOPED\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 = \IAWPSCOPED\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