CallbackPool.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Model;
  7. /**
  8. * Class CallbackPool
  9. */
  10. class CallbackPool
  11. {
  12. /**
  13. * Array of callbacks subscribed to commit transaction commit
  14. *
  15. * @var array
  16. */
  17. private static $commitCallbacks = [];
  18. /**
  19. * @param string $hashKey
  20. * @param array $callback
  21. * @return void
  22. */
  23. public static function attach($hashKey, $callback)
  24. {
  25. self::$commitCallbacks[$hashKey][] = $callback;
  26. }
  27. /**
  28. * @param string $hashKey
  29. * @return void
  30. */
  31. public static function clear($hashKey)
  32. {
  33. self::$commitCallbacks[$hashKey] = [];
  34. }
  35. /**
  36. * @param string $hashKey
  37. * @return array
  38. */
  39. public static function get($hashKey)
  40. {
  41. if (!isset(self::$commitCallbacks[$hashKey])) {
  42. return [];
  43. }
  44. $callbacks = self::$commitCallbacks[$hashKey];
  45. self::$commitCallbacks[$hashKey] = [];
  46. return $callbacks;
  47. }
  48. }