ErrorCode.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace ModulesGarden\Servers\ProxmoxVps\Core\HandlerError\ErrorCodes;
  3. class ErrorCode
  4. {
  5. use \ModulesGarden\Servers\ProxmoxVps\Core\Traits\Lang;
  6. protected $code = null;
  7. protected $message = null;
  8. protected $token = null;
  9. protected $logable = false;
  10. public function __construct($code = null, $codeDetails = null, $token = null)
  11. {
  12. $this->setToken($token);
  13. $this->setCode($code);
  14. $this->setDetails($codeDetails);
  15. }
  16. /**
  17. * @param null $code
  18. */
  19. public function setCode($code = null)
  20. {
  21. if (is_string($code))
  22. {
  23. $this->code = $code;
  24. }
  25. }
  26. /**
  27. * @param null $message
  28. */
  29. public function setMessage($message = null)
  30. {
  31. if (is_string($message) && $message !== '')
  32. {
  33. $this->message = $message;
  34. }
  35. }
  36. /**
  37. * @param null $token
  38. */
  39. public function setToken($token = null)
  40. {
  41. if (is_string($token))
  42. {
  43. $this->token = $token;
  44. }
  45. }
  46. /**
  47. * @return string
  48. */
  49. public function getCode()
  50. {
  51. return $this->code === null ? '' : $this->code;
  52. }
  53. /**
  54. * @return string
  55. */
  56. public function getToken()
  57. {
  58. return $this->token === null ? '' : $this->token;
  59. }
  60. /**
  61. * @return string
  62. */
  63. public function getMessage()
  64. {
  65. return $this->message === null ? '' : $this->message;
  66. }
  67. public function getRawErrorMessage()
  68. {
  69. return 'Error Code: ' . ($this->getCode() ? : 'none') . ' Error Token: ' . ($this->getToken() ? : 'none') . 'Error Message: ' . $this->getMessage() ? : 'none.';
  70. }
  71. public function setLogable($logable)
  72. {
  73. if (is_bool($logable))
  74. {
  75. $this->logable = $logable;
  76. }
  77. }
  78. public function isLogable()
  79. {
  80. return $this->logable;
  81. }
  82. public function setDetails($codeDetails)
  83. {
  84. if (is_string($codeDetails))
  85. {
  86. $this->setMessage($codeDetails);
  87. return;
  88. }
  89. $this->setMessage($codeDetails[ErrorCodes::MESSAGE]);
  90. $this->setLogable($codeDetails[ErrorCodes::LOG]);
  91. }
  92. }