EventManager.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace refill;
  3. use Log;
  4. use refill\event\card_crash;
  5. class EventManager
  6. {
  7. private static $stInstance = null;
  8. public static function instance()
  9. {
  10. if (self::$stInstance == null) {
  11. self::$stInstance = new EventManager();
  12. }
  13. return self::$stInstance;
  14. }
  15. private $mStubs = [];
  16. public function load()
  17. {
  18. $cfgs = [
  19. 'open_crash' => true,
  20. 'cfgs_crash' => [
  21. 'channels' => [],
  22. 'succ_interval' => 900
  23. ]
  24. ];
  25. $open_crash = $cfgs['open_crash'] ?? false;
  26. if($open_crash) {
  27. $crash = new card_crash();
  28. $crash->load($cfgs['cfgs_crash'] ?? []);
  29. $this->mStubs[] = $crash;
  30. }
  31. }
  32. public function onBeforeSubmit(order $order)
  33. {
  34. foreach ($this->mStubs as $stub)
  35. {
  36. if($stub->onBeforeSubmit($order) === false) {
  37. return false;
  38. }
  39. }
  40. return true;
  41. }
  42. public function onSubmit(order $order)
  43. {
  44. foreach ($this->mStubs as $stub) {
  45. $stub->onSubmit($order);
  46. }
  47. }
  48. public function onBeforeCommit(order $order, $ch_name): bool
  49. {
  50. foreach ($this->mStubs as $stub)
  51. {
  52. if ($stub->onBeforeCommit($order, $ch_name) === false) {
  53. return false;
  54. }
  55. }
  56. return true;
  57. }
  58. public function onCommit(order $order, $ch_name)
  59. {
  60. foreach ($this->mStubs as $stub) {
  61. $stub->onCommit($order, $ch_name);
  62. }
  63. }
  64. public function onNeterror(order $order, $ch_name)
  65. {
  66. foreach ($this->mStubs as $stub) {
  67. $stub->onNeterror($order, $ch_name);
  68. }
  69. }
  70. public function onNotify($refill_info, $order_info, $success)
  71. {
  72. foreach ($this->mStubs as $stub) {
  73. $stub->onNotify($$refill_info, $order_info, $success);
  74. }
  75. }
  76. public function onComplete($refill_info, $order_info, $success)
  77. {
  78. foreach ($this->mStubs as $stub) {
  79. $stub->onComplete($$refill_info, $order_info, $success);
  80. }
  81. }
  82. }