DatabaseTransactionRecord.php
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP_SCOPED\Illuminate\Database; |
| 4 | |
| 5 | class DatabaseTransactionRecord |
| 6 | { |
| 7 | /** |
| 8 | * The name of the database connection. |
| 9 | * |
| 10 | * @var string |
| 11 | */ |
| 12 | public $connection; |
| 13 | /** |
| 14 | * The transaction level. |
| 15 | * |
| 16 | * @var int |
| 17 | */ |
| 18 | public $level; |
| 19 | /** |
| 20 | * The callbacks that should be executed after committing. |
| 21 | * |
| 22 | * @var array |
| 23 | */ |
| 24 | protected $callbacks = []; |
| 25 | /** |
| 26 | * Create a new database transaction record instance. |
| 27 | * |
| 28 | * @param string $connection |
| 29 | * @param int $level |
| 30 | * @return void |
| 31 | */ |
| 32 | public function __construct($connection, $level) |
| 33 | { |
| 34 | $this->connection = $connection; |
| 35 | $this->level = $level; |
| 36 | } |
| 37 | /** |
| 38 | * Register a callback to be executed after committing. |
| 39 | * |
| 40 | * @param callable $callback |
| 41 | * @return void |
| 42 | */ |
| 43 | public function addCallback($callback) |
| 44 | { |
| 45 | $this->callbacks[] = $callback; |
| 46 | } |
| 47 | /** |
| 48 | * Execute all of the callbacks. |
| 49 | * |
| 50 | * @return void |
| 51 | */ |
| 52 | public function executeCallbacks() |
| 53 | { |
| 54 | foreach ($this->callbacks as $callback) { |
| 55 | \call_user_func($callback); |
| 56 | } |
| 57 | } |
| 58 | /** |
| 59 | * Get all of the callbacks. |
| 60 | * |
| 61 | * @return array |
| 62 | */ |
| 63 | public function getCallbacks() |
| 64 | { |
| 65 | return $this->callbacks; |
| 66 | } |
| 67 | } |
| 68 |