TransactionManager.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Model\ResourceModel\Db;
  7. use Magento\Framework\DB\Adapter\AdapterInterface as Connection;
  8. class TransactionManager implements TransactionManagerInterface
  9. {
  10. /**
  11. * @var Connection[]
  12. */
  13. protected $participants;
  14. /**
  15. * {@inheritdoc}
  16. */
  17. public function start(Connection $connection)
  18. {
  19. $this->participants[] = $connection;
  20. $connection->beginTransaction();
  21. return $connection;
  22. }
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public function commit()
  27. {
  28. /** @var \Magento\Framework\DB\Adapter\AdapterInterface $connection */
  29. while ($connection = array_pop($this->participants)) {
  30. $connection->commit();
  31. }
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function rollBack()
  37. {
  38. /** @var \Magento\Framework\DB\Adapter\AdapterInterface $connection */
  39. while ($connection = array_pop($this->participants)) {
  40. $connection->rollBack();
  41. }
  42. }
  43. /**
  44. * Get object key
  45. *
  46. * @param Connection $connection
  47. * @return string
  48. */
  49. protected function getConnectionKey(Connection $connection)
  50. {
  51. return spl_object_hash($connection);
  52. }
  53. }