ErrorTrait.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace crmeb\traits;
  12. /**
  13. *
  14. * Class BaseError
  15. * @package crmeb\basic
  16. */
  17. trait ErrorTrait
  18. {
  19. /**
  20. * 错误信息
  21. * @var string
  22. */
  23. protected $error;
  24. /**
  25. * 设置错误信息
  26. * @param string|null $error
  27. * @return bool
  28. */
  29. protected function setError(?string $error = null)
  30. {
  31. $this->error = $error ?: '未知错误';
  32. return false;
  33. }
  34. /**
  35. * 获取错误信息
  36. * @return string
  37. */
  38. public function getError()
  39. {
  40. $error = $this->error;
  41. $this->error = null;
  42. return $error;
  43. }
  44. }