DatabaseTransactionRecord.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 callbacks that should be executed after committing.
  19. *
  20. * @var array
  21. */
  22. protected $callbacks = [];
  23. /**
  24. * Create a new database transaction record instance.
  25. *
  26. * @param string $connection
  27. * @param int $level
  28. * @return void
  29. */
  30. public function __construct($connection, $level)
  31. {
  32. $this->connection = $connection;
  33. $this->level = $level;
  34. }
  35. /**
  36. * Register a callback to be executed after committing.
  37. *
  38. * @param callable $callback
  39. * @return void
  40. */
  41. public function addCallback($callback)
  42. {
  43. $this->callbacks[] = $callback;
  44. }
  45. /**
  46. * Execute all of the callbacks.
  47. *
  48. * @return void
  49. */
  50. public function executeCallbacks()
  51. {
  52. foreach ($this->callbacks as $callback) {
  53. call_user_func($callback);
  54. }
  55. }
  56. /**
  57. * Get all of the callbacks.
  58. *
  59. * @return array
  60. */
  61. public function getCallbacks()
  62. {
  63. return $this->callbacks;
  64. }
  65. }