DatabaseTransactionRecord.php 1.6 KB

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