ProcessStepHandler.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Traits;
  3. /**
  4. *
  5. * Created by PhpStorm.
  6. * User: ThurData
  7. * Date: 08.10.19
  8. * Time: 11:22
  9. * Class ProcesStepHandler
  10. */
  11. trait ProcessStepHandler
  12. {
  13. /**
  14. * array with process in progress
  15. * @var array
  16. */
  17. protected $inProgressProcess = [];
  18. /**
  19. * array with completed process
  20. * @var array
  21. */
  22. protected $completedProcess = [];
  23. /**
  24. * array with process finished with error status
  25. * @var array
  26. */
  27. protected $errorProcess = [];
  28. /**
  29. * @var array
  30. */
  31. protected $allProcess = [];
  32. /**
  33. * @return array
  34. */
  35. public function getInProgress()
  36. {
  37. return $this->inProgressProcess;
  38. }
  39. /**
  40. * @return array
  41. */
  42. public function getCompleted()
  43. {
  44. return $this->completedProcess;
  45. }
  46. /**
  47. * @return array
  48. */
  49. public function getErrorProcess()
  50. {
  51. return $this->errorProcess;
  52. }
  53. /**
  54. * @return array
  55. */
  56. public function getAllProcess()
  57. {
  58. return $this->allProcess;
  59. }
  60. /**
  61. * @param $code
  62. * @return $this
  63. */
  64. public function startProcess($code)
  65. {
  66. $this->inProgressProcess[$code] = $code;
  67. $this->allProcess[] = $code;
  68. return $this;
  69. }
  70. /**
  71. * @param $code
  72. * @return $this
  73. */
  74. public function stopProcess($code)
  75. {
  76. unset($this->inProgressProcess[$code]);
  77. $this->completedProcess[$code] = $code;
  78. return $this;
  79. }
  80. /**
  81. * @param $code
  82. * @param $error
  83. * @return $this
  84. */
  85. public function stopProcessWithError($code, $error)
  86. {
  87. unset($this->inProgressProcess[$code]);
  88. $this->error[$code] = ['code' => $code, 'error' => $error];
  89. return $this;
  90. }
  91. /**
  92. * @return array
  93. */
  94. public function info()
  95. {
  96. return [
  97. 'process' => $this->getAllProcess(),
  98. 'inProgress' => $this->getInProgress(),
  99. 'finished' => $this->getCompleted(),
  100. 'error' => $this->getErrorProcess(),
  101. ];
  102. }
  103. }